[Diao Ye learns programming] Arduino hands-on (132)---KY-027 magic halo module

The mention of 7 types of sensors and actuators has been widely circulated on the Internet. In fact, there must be more than 37 types of sensor modules compatible with Arduino. In view of the fact that I have accumulated some sensor and actuator modules on hand, according to the concept of practicing true knowledge (must be done), for the purpose of learning and communication, I am going to try a series of experiments one by one, regardless of success (the program goes through) or not, They will be recorded - small progress or unsolvable problems, hoping to inspire others.

[Arduino] 168 kinds of sensor module series experiments (data code + simulation programming + graphics programming)
Experiment 132: KY-027 magic light cup for UNO magic halo module

insert image description here
Knowledge point: Mercury switch

It is to use the characteristics of good conductivity and fluidity of mercury to control the opening and closing of electrical circuits. It is composed of glass tube, mercury, fixed electrode, lead wire and so on. The air is extracted from the tube and then filled with various gases to seal it. It is suitable for places with dust, oil, water vapor and corrosive gases, and can also be used as an explosion-proof switch in places with explosive gases. In view of the high surface tension and specific gravity of the mercury in the tube, and its fluidity, as long as the glass tube is slightly tilted, the position of the mercury will change immediately, and it will be in contact with the electrode in a surface contact manner, so it can be used to separate AC and DC. High Current. In addition, the characteristics of this switch are that the contact resistance is generally below 0.02 ohms, the life span can reach several million times under the rated current, small size, high sensitivity, no mechanical noise, low price, etc., so it has always been used as a switch for automatic control. .

insert image description here
I have five of these switches on hand

insert image description here
Mercury

Mercury is a chemical element, the 80th in the periodic table of elements, commonly known as mercury. The element symbol Hg, located in the 6th period and group IIB of the chemical element periodic table, is the only metal that exists in a liquid state at normal temperature and pressure (in a strict sense, gallium (symbol Ga, element 31) and cesium ( Symbol Cs, element 55) is also liquid at room temperature (29.76°C and 28.44°C). Mercury is a silvery white shiny heavy liquid, chemically stable, insoluble in acid and alkali. Mercury can evaporate at room temperature, and mercury vapor and mercury compounds are highly toxic (chronic). Mercury has good conductivity and fluidity. Mercury has a long and diverse history of use. In medieval alchemy, together with sulfur and salt, they are called the three sacred elements of alchemy.
insert image description here
insert image description here
Mercury switch internal structure diagram

insert image description here
insert image description here
insert image description here
Mercury switch principle
The structure of the mercury switch is very simple. Outside is a sealed cylindrical insulating shell, about 30 mm long and about 10 mm in diameter. It was filled with about a fifth of mercury. Two wires drawn from the inside are fixed at one end of the housing. This is a mercury switch. Because of the gravity, the mercury droplets will flow to the lower part of the container. If they touch the two electrodes at the same time, the switch will close the circuit and turn on the switch, thus triggering the subsequent circuit to work.

insert image description here
insert image description here
Precautions for use
Mercury is poisonous to the human body and the environment, so when using the mercury switch, please be careful to avoid breaking it; when it is no longer in use, it should also be disposed of properly. Prevent the mercury switch from falling from a high place, avoid it from being in contact with hard objects, or being squeezed, which will cause the glass bubble to break.

insert image description here
Features of Mercury Switches

The mercury switch is based on the movement of the mercury encapsulated in the glass or metal shell to realize the switch on and off, so the mercury switch has many characteristics compared with the mechanical switch.

① Can be used under harsh environmental conditions. Because the mercury switch is sealed, the mercury inside is isolated from the outside world, so it can be used in the environment with oil, steam, dust and corrosive gas.

②The external force required for switching is small. Mercury is the only metal that can maintain a liquid state at room temperature. Its surface tension and specific gravity are large. As long as a slight external force is applied to tilt the mercury switch, the mercury can move to make the switch on and off.

③ Mercury has good conductivity, and the contact resistance between mercury switch electrodes is generally less than 100mΩ.

④The current allowed by the mercury switch depends on the material of the electrode. The maximum allowable current of the tungsten wire electrode is 10A, while the maximum allowable current of the general alloy wire is generally 1A.

⑤Since the on-off of the mercury switch is determined by the gravity of the mercury, it can work reliably for a long time.

⑥ The contact of the electrode is in liquid contact without any noise.

⑦Because mercury can flow, as long as the acceleration reaches the set value, the mercury switch can be turned on or off, so it can be used as a vibration sensitive element.

⑧Small size, various forms, and fully sealed device.

⑨ Simple structure and low price.

insert image description here
The difference between mercury switch and vibration switch

1. All materials of the ball switch can meet the environmental protection requirements, but the mercury switch cannot meet the requirements due to its own material problems.

2. The conduction mode of the ball switch is that the metal ball and the trigger guide pin are energized to generate a signal. Because the contact area between the ball and the trigger guide pin is small and the ball is movable, the conduction sometimes has a flickering phenomenon, while mercury The switch is made of mercury in contact with the trigger end. Because mercury is in a liquid state, the contact surface is large and stable, and generally speaking, the conduction effect is more stable.

3. The ball switch is a metal shell with good structural strength.

4. Mercury is liquid, and the contact area is large and stable. Generally speaking, the conduction effect is more stable. Its resistance is less than 0.02 ohms, and its service life can reach several million times under rated current. It can be used to switch large AC and DC currents. It has small size, high sensitivity, no mechanical noise, and low price, so it has always been used as a switch for automatic control. It is suitable for special places with dust, oil, water vapor, etc. and corrosive gases, and can also be used as an explosion-proof switch in places with explosive gases. The advantage of the glass tube-encapsulated mercury switch is that its working state can be observed from the outside, but the disadvantage is that it is easily broken.

insert image description here
Special warning:

Mercury is poisonous. Once the glass bubble breaks, please move the outflowing mercury outside quickly, and do not contact it with the skin. Because the amount of mercury in the mercury switch is very small, even less than that in ordinary mercury thermometers, there is no need to worry about safety issues when used correctly.

Wiring diagram of Arduino experiment

G: connected to gnd

+: connected to vcc

S: output pin, output the state of the mercury switch, the guess meaning is SWITCH (switch)

L: input pin, control LED light, guess meaning is LED

insert image description here
Arduino experiment open source code

/*

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

实验一百三十二:KY-027 魔术光杯 for UNO 魔术光环模块

实验接线:

G:接gnd

+:接vcc

S:水银开关接2

L:LED灯接13

*/



void setup()

{
    
    

    pinMode(2,INPUT);

    pinMode(13,OUTPUT);

}

void loop() {
    
    

  if (digitalRead(2)) {
    
    

    digitalWrite(13,HIGH);

    delay(1000);

  }

  else {
    
    

    digitalWrite(13,LOW);  

  }

}

Arduino experiment scene diagram

insert image description here
Arduino experiment open source code 2

/*

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

实验一百三十二:KY-027 魔术光杯 for UNO 魔术光环模块

实验接线:

G:接gnd

+:接vcc

S:水银开关

L:LED灯

*/



int SensorLED = 13;      //定义LED为数字引脚13

int SensorINPUT = 2;    //连接水银开关到中断0,也就是数字引脚2

volatile int state = LOW;

void setup()

{
    
    

  pinMode(SensorLED, OUTPUT);            //LED为输出模式

  pinMode(SensorINPUT, INPUT_PULLUP);  //水银开关为输入模式

  //下降沿触发,触发中断0,调用blink函数

  attachInterrupt(0, blink, FALLING);

}

void loop() {
    
    

  if (state == HIGH) {
    
                  // 如果state为HIGH

  state = LOW;

  digitalWrite(SensorLED, HIGH);  // 亮灯

  delay(100);      //延时100ms

  }

  else {
    
    

  digitalWrite(SensorLED, LOW);  // 否则,关灯

  }

}

void blink() {
    
              //中断函数blink()

  state = !state;        //一旦中断触发,state状态反转

}

Arduino experiment open source code

/*

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

实验一百三十二:KY-027 魔术光杯 for UNO 魔术光环模块

实验接线(二只模块)

G:接gnd

+:接vcc

S1:水银开关接4

L1:  LED灯接6

S2:水银开关接7

L2:  LED灯接5

*/



int LedPinA = 5;

int LedPinB = 6;

int ButtonPinA = 7;

int ButtonPinB = 4;

int buttonStateA = 0;

int buttonStateB = 0;

int brightness  = 0;

void setup()

{
    
    

  pinMode(LedPinA, OUTPUT);

  pinMode(LedPinB, OUTPUT);

  pinMode(ButtonPinA, INPUT);

  pinMode(ButtonPinB, INPUT);

}

void loop()

{
    
    

  buttonStateA = digitalRead(ButtonPinA);

  if (buttonStateA == HIGH && brightness != 255)

  {
    
    

  brightness ++;

  }

  buttonStateB = digitalRead(ButtonPinB);

  if (buttonStateB == HIGH && brightness != 0)

  {
    
    

  brightness --;

  }

  analogWrite(LedPinA, brightness);  //  A慢漸暗

  analogWrite(LedPinB, 255 - brightness);  // B慢漸亮

  delay(25);

}

Explanation: Because of the epidemic, another module arrived today

insert image description here

Guess you like

Origin blog.csdn.net/weixin_41659040/article/details/131428912
Recommended