Controlling A Relay With Arduino
Controlling A Relay With Arduino
At some point the Arduino must control something more than LEDs. In
this opportunity we did a classic test with materials easy to find in Chile.
After the jump the complete information to control a relay from your
Arduino
materials
● Diode 1N4002
● Transistor 2N2222
● 5V Relay
● Arduino Uno R3
● USB Cable
● Resistance 1 KΩ
● Connectors
● Protoboard
● Cables
● PC with Arduino IDE
● Base ampoule with plug
For the low voltage part or trigger circuit it has two pins, among them
there is an internal coil. The pins of high voltage, depends on the
specifications of the relay, but in our case consists of three connectors, a
pin COMUN a pin NO (normally open) and another pin NC (normally
closed)
So, for the relay we use, the description of the pins is as follows; 2 pins
are for the low voltage circuit (trip circuit), 3 pins for high voltage,
1 pin is common
1 pin in NO state (normally open)
1 pin in NC state (normally closed)
This model is called relay SPDT, that is, the COMMON pin is called SP
(Single Pole) and the two contacts are called DT (Dual Throw)
The relay is seen in the following image with the indication of the pins as
they are connected in the circuit.
Bottom view of the relay. The pins are indicated in
relation to the circuit we use.
Process
As a first stage we load the sketch using the PC USB cable and the
Arduino. The program is very simple and consists of a variation of the
"Hello World"
// Internet of things / http://internetdelascosas.cl
//
// Sketch that allows to activate a relay
int relay = 2;
// The setup routine is executed when the Arduino is started or when the reset button is pressed
void setup () {
// Initialize the digital pin relay (which is worth 2) as output
pinMode (relay, OUTPUT);
}
Circuit
The circuit to use is the following
The diode is parallel to the coil with the cathode towards Vcc. The coil is
connected to Vcc and the collector of the transistor. The transistor has
the Base connected to a resistance of 1KOhm and the emitter goes to
ground.
In the high-voltage circuit, for its part, the COMUN pin is connected to
the load and the NO pin to the positive, for DC loads or to the plug, in
the case of AC
By connecting everything you can try the relay in "empty", that is to say
without load, you will hear a noise like a click, which is the change of
state in the pins of the relay.
Then you can connect a real charge like a vial. The load is connected to
the COMMAND pin and the pin does NOT connect to the plug. This is
shown in the following figure of CircuitLab
Complete circuit
Bibliography
How Relays Work
HobbyRobotics