Arduino-Relay

Recognize components

  • Relay (Model Lok SRD-05VDC-SL-C)
    Write picture description here
    relay-Lok front SRD-05VDC-SL-C marked its type, voltage
    relays bottom surface has five pins, marked internal wiring, each foot have the following meanings:
    Write picture description here

Two input pins are connected to both ends of the coil, and the common end, normally open end, and normally closed end are three output pins. The common terminal and the normally open terminal form a normally open switch, and the common terminal and the normally closed terminal form a normally closed switch. When a 5V voltage is applied to the two input ends of the coil, the common end and the normally open end are closed, and the common end and the normally closed end are disconnected.

Be sure to figure out the pins before wiring. You can also use a multimeter to measure the resistance between each leg and verify it.

  • PNP type transistor (model 8550) The
    Write picture description here
    transistor model is 8550, and its pins are as follows:
    1 pin = E (emitter, the one with the arrow in the circuit diagram)
    2 pin = B (base, the one connected to R in the circuit diagram)
    3 Pin = C (collector, the one opposite to E)

  • diode:
    Write picture description here

The two legs of the diode have positive and negative poles, and the pin with a small ring is the negative pole.

  • 1K resistance
    Write picture description here

Schematic diagram of relay drive circuit

The relay components need to be connected to the single-chip microcomputer through a drive circuit. The schematic diagram of a typical drive circuit is as follows:
Write picture description here

In the above circuit, a PNP-type transistor is used as the control switch. In the picture, Relay is a relay. The C pole of the transistor is connected to GND, and the E pole is connected to one end of the relay coil (input terminal). The B pole of the transistor is connected to by a 1K-2K resistor. The GPIO pin of the microcontroller. The other end of the relay coil (input terminal 2) is connected to VCC. A diode is connected in reverse parallel between the two input terminals of the relay coil. The function of this diode is to filter out the reverse current generated during the charging and discharging of the coil.

The transistor in this circuit is equivalent to a switch. The operating principle is as follows:
1. When the GPIO outputs a high level, there is no voltage difference between the B pole and the E pole of the triode, the E pole and the C pole of the transistor are blocked, and the relay does not pass current.
2. When the GPIO outputs a low level, a voltage difference is formed between the three poles B pole and E pole, the transistor E pole and C pole are turned on, the current passes through the two input terminals of the relay coil, and the relay is closed.

Wiring with breadboard

Insert the transistors, relays, diodes, and resistors into the breadboard, follow the above circuit schematic diagram, and use DuPont wires to connect the wiring as shown below:
Write picture description here

int pinRelay = 3; //管脚D3连接到继电器模块的信号脚  

void setup() {  
  pinMode(pinRelay, OUTPUT); //设置pinRelay脚为输出状态  
}  

void loop() {   
   digitalWrite(pinRelay, HIGH);//输出HIGH电平,继电器模块闭合  
   delay(5000); //等待5000毫秒  

   digitalWrite(pinRelay, LOW);//输出LOW电平,继电器模块断开  
   delay(8000); //等待8000毫秒  
}  

Guess you like

Origin blog.csdn.net/sdlgq/article/details/54982107