Vous êtes sur la page 1sur 6

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.

Basic circuit for the control of 1 relay

The test we explain in this entry is to operate a relay to control a higher


power load, such as a vial.

Attention: Work with high voltage is potentially very dangerous, we


recommend reading this article completely, (including the bibliography)
before making a real implementation of a circuit

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

About the Relay


A relay is a device that allows controlling a higher voltage loads based
on low voltage signals. In this case we use a 5V Relay

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.

The top view of the relay tells us its specifications

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);
}

// The loop routine runs infinitely after the Arduino is initialized


void loop () {
digitalWrite (relay, HIGH); // Send the HIGH value (5V) to the digital pin relay
delay (2000); // Wait 2 seconds
digitalWrite (relay, LOW); // Send the LOW value (0V) to the digital pin relay
delay (10000); // Wait 10 seconds
}

Circuit
The circuit to use is the following

Connection of the relay with Arduino. Source page


of Eric Forman

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

Let's see a brief explanation about the circuit diagram.

Relays need more power than that provided by an Arduino pin, so a


transistor is required to activate it. In this case we use the known
2N2222. (It has to be of the typePNP NPN, as shown in the figure)

The 1N4002 diode prevents reverse EMF (FEM, or Electromagnetic


Force, reverse is the voltage that occurs when the current varies through
a coil)

The implementation is as seen in the figure

The trigger circuit consists of a diode in parallel with


the coil. The coil connected to Vcc and the transistor cloector with the collector of the transistor.

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

Vous aimerez peut-être aussi