Controlling Alternated Current – Relays

Alternated current and direct current live in very different realms, think lighting and appliances vs electronics and computers. You will never have AC flowing on your breadboard. However, with our 5V arduino circuits we can turn on and off bigger things using relays. Relays are physical switches that can be controlled by a low voltage electric signal. We are using relays in two relatively safe setups:

Power Switch Tail II

The PST is a self contained plug-and-play extension chord controlled by a digital signal (+5V). You plug the +in to the arduino digital output, the -in to ground (you can leave the gnd pin disconnected) and control the extension chord as you would control an LED, by sending a digitalWrite(pin, HIGH) to the appropriate output. In order for the Relay to click the Power Switch Tail has to be plugged in an outlet. Always disconnect the AC stuff when you are working on the circuit.


8 channel relay unit
This unit has 8 relays controlled by digital signal but it’s not prewired and pre packaged. You can also use it to control DC circuits of different voltage like 12V.
To make it equivalent to 8 Power Switch Tails we’ll have to slice some cords. Here’s a step by step guide:

Get a cheap extension cord (less than $2 at home depot).

Using a knife separate the 2 wires not too close to the end (here in the picture I’m definitely too close but it really depends on your setup).
Be extra careful to not expose the conductive part, cut right in the middle.

Cut one of the 2 wires, it doesn’t matter which one, right in the middle of the split.

Strip both ends of the cut wire. Strip no more than a quarter of inch.

To reduce the risk of short circuits it is probably a good idea to twist the threaded copper wire tightly and melt a little bit of solder on them so they stay glued together.

I recommend to tape the cord so that the two ends stay aligned and close together.

Unscrew the connectors on the relay side, insert the two stripped ends all the way down on one relay and secure tightly with the screws.
The connectors you have to use on this relay unit model are the first and the second to the left (in the diagram they look like an open switch) leaving the third one open.
Make sure that:
1) the copper wire is not exposed
2) the two stripped ends don’t touch each other and the little threads are all inside the connector. That would be a serious short circuit.
3) the wires are firm and secured
4) you don’t leave the unit where it can get wet (duh)
5) don’t leave the unit unattended when plugged in AC
6) Always disconnect the AC stuff when you are working on the circuit

To prevent the wires from slipping away I recommend securing them with zip-ties running around the loop and the unit.

Now you can connect the pins on the other side of the units with the Arduino outputs. This relay unit needs a jumper connecting COM and GND, VCC to the +5 of your circuit and the GND to your circuit ground. You can use male to female connectors and maintain the same order. In the example here outputs 0 to 7 control relays 1 to 8.
This is a test code:

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(0, OUTPUT);     
  pinMode(1, OUTPUT);     
  pinMode(2, OUTPUT);     
  pinMode(3, OUTPUT);     
  pinMode(4, OUTPUT);     
  pinMode(5, OUTPUT);     
  pinMode(6, OUTPUT);     
  pinMode(7, OUTPUT);     
  //turn all the relays off
  for (int i=0; i <8; i++){
    digitalWrite(i, LOW);
void loop() {
  //turn each relay on for half a second then off  
  for (int i=0; i <8; i++){
    digitalWrite(i, HIGH);
    digitalWrite(i, LOW);
Posted in

Post a comment