No. 15 – Relay shield

Task: Use a relay shield.

Required equipment: Relay shield / Arduino / cables

A relay is a switch, which can be activated with a low current from the Arduino board. So you can switch on and off electrical things, that need much more power than a Arduino board can provide.

RE1

The relay needs a permanent power supply trough 5V+ and – (In the picture VCC and GND). With the “IN”-pin, the switch can be activated by the Arduino board. The three terminals on the left side are meant to be connected with the electrical component that needs more power than the Arduino can provide. If the relay doesn’t get any signal from the Arduino on the “IN” contact, the contacts A and B are connected. Once the relay gets a signal from the Arduino the contacts B and C get connected.

ATTENTION: There are two types of relay shields. They differ in the way you get them to switch. Either you have to connect the “IN” pin to 5V+ on the Arduino, or you have to connect the “IN” pin to GND on the Arduino. You can easily find out which type of relay you got. Try connecting the “signal” pin with 5V+ or with GND. The version where the relay switches (you can hear a loud crack) will be the right version.

For testing purpose, you can use the “blink”-sketch. Instead of the LED, you connect the output-pin from the Arduino board with the “IN” pin from the relay. With that sketch, the relays will switch on and off in a 1 second rhythm.

 

Code:


void setup()

{

pinMode(6, OUTPUT);

}

void loop()

{

digitalWrite(6, HIGH); //At this point the relay turns on

delay(1000); //..wait one second

digitalWrite(6, LOW); //turn off the relay again

delay(1000); //…wait a second

}