bclose

14 – Arduino and Relays

Objectives

 

 

    • Get to know relays
    • The first circuit with a relay
    • Normally open and normally closed contacts

 

Bill of materials

Arduino Uno Arduino Uno or equivalent.
We can use any other Arduino board in this chapter.
Breadboard

Jumper wires

 

 A solderless Breadboard plus some jumper wires.
Red LED

330 Ohm Resistor

2 x and 2 x 330Ω resistors
2N222 Transistor A 2N2222 transistor

  • Check that this reference number is silverscreened on the surface, because the temperature sensor is quite similar.
Relay

Relay in a breakout board

A little Relay

Independent or on a Keyes mount

 

WHAT A RELAY IS AND WHAT IT IS FOR

 

 

Relay schematic

 

 

A relay is a switch than can be turned on by using an electric signal. In its simplest version, it is made up of an small electromagnet that moves the position of an electrical contact from connected to unconnected or vice versa, when excited.

The schematic symbol of a relay shows a coil, the rectangle on the left, and an actuator that toggles between two electrical contacts, in this case although there are relays that have multiple contacts. By means of a low current control signal that excites the coil we are able to switch high voltages or currents.

We have previously used a transistor to do the same, so why should we use relays instead?

 
  • First, the relays carry with us since the late 19th century (and no one has yet been able to make them obsolete) is a very proven technology and well established in the industry and is also useful to do things that are problematic for transistors .
  • A transistor can withstand current intensities up to some limit, but a relay can be designed to withstand whichever load, provided that the metal on the surface contacts can withstand it.
  • It completely insulates the control circuit from the power circuit, which is of importance especially in lines of medium and high-voltage.
 

Normally we use a relay when it is required to switch large voltages or current intensities such as starting AC motors of a certain power. Instead it is preferable to use the transistor as a switch, for small loads, and when the switching speed is an important issue.

 
  • The transistor switching speed is several million times faster than a relay.
 

In practice, it is easier to use a relay to turn on a fluorescent light or the electric heating when using Arduino than to find a suitable transistor.

Although there are relays that need very little power to drive the coil, Arduino generally fall short so we will have to use a transistor to solve the problem.

The example discussed below includes a transistor / relay circuit that enable us to engage any household project we propose.

 

TYPICAL CIRCUIT RELAY / TRANSISTOR

 

Chapter 14, Fritzing diagram 1

 

When we put a HIGH value on the control pin, pin 9, the transistor goes to saturation and the current between the emitter and collector energizes the coil of the relay, causing the contact change position (and also doing a very nice click).

If we put a LOW value on the control pin, the transistor enters in the cut-off region and prevents current flow so that the coil doesn’t work and the output contact returns to its rest position.

The relay output has 3 pins and not two as you might expect. The reason is that the connection between the output pins 2 and 3 is normally open (open circuit, before energizing the coil) and between pins 2 and 4 is normally closed (closed circuit, before energizing the coil).

We can build some emergency lights using a relay operating as normally open . While there is current, the coil is energized and the circuit is open, but if the power goes out, the normally open contact is closed and, if there is a battery, the emergency lights will automatically turn on using the normally closed contact instead.

Chapter 14, Fritzing diagram 2

 

 

 

In our example we can use a red and a green LED to mark the situation. We will see that only lights up one LED or the other, but never both (as befits an alarm signal).

 

THE CIRCUIT FOR THE BREADBOARD

 

For once, without a precedent, we will not include a circuit wiring diagram because the pin-out of a relay depends on the manufacturer and model and would be impractical to include multiple circuit wiring diagrams.

In addition, the basic transistor circuit from the previous chapter is exactly the same as this so it would suffice to replace the DC motor by the control contacts of the relay on the one hand, and on the other hand to find which are the normally open and normally closed pins of the relay, and connect a LED to each of them via a common resistance.

 
  • The best practice would be to search in internet the data sheet of the relay that we have and check in the manufacturer’s description the meaning of each pin.
  • If for any reason we could not get the specifications, it is usually quite easy to determine which are the control pins because they tend to be close and usually they are 3 pin together, the lonely one is the common contact. We can use LED diodes to find out which is the NO or NC contact.
  • When a relay switches you can hear a very nice click, so it’s easy to know if it has been energized. Some relays are even transparent so you can see the internal mechanism and the movement of the contact.
 

The circuit wiring diagram would only complicate things and it’s time we try to assemble the circuit from the circuit schematic diagram directly. Cheer up!

MOTOR CONTROL PROGRAM

 

To test that everything is properly connected, it is enough to run the same program we used for the DC motor:

Sketch 13.1
const int control = 9 ;
void setup()
    {
         pinMode(control,  OUTPUT) ;
    }
void loop()
    {
         digitalWrite(control, HIGH);
         delay(1000);
         digitalWrite(control, LOW);
         delay(1000);
    }

This program will cause the relay switches every second and the LEDs will light up alternately.

To convert this circuit into a hazard warning lights, it would be enough to put a battery or batteries in the common pin of the relay instead of using the Arduino 5V pin. Thereby disconnecting Arduino, the emergency light is self activated.

Summary

 

 

    • We already know the relays and why they are useful for our projects.
    • We have seen that there are two types of contacts: normally open (NO) and normally closed (NC)
    • Normally relays are very interesting to switch on and off something that has a relatively high current.

 

 

 

 

 

No Comments

Give a Reply