Arduino Relay Controller

Caution: just because relays can work with high voltage, it doesn't mean you can.

Be extremely careful!

Controlling a relay is one of the most exciting things to do with Arduino. Arduino voltages range from 0-5 V, but relays can allow the Arduino to effectively control 0-250 V. Using a signal pin (the sketch below uses pin 12), the Arduino can close or open a relay switch as easily as it can turn on an LED. The sketch below closes the circuit for 10 seconds, and opens it for 10 seconds, repeat. The relay connections are shown in the fritzing circuit below.


Connections

Relay Signal to Arduino Pin 12

Relay Power to Arduino 5V

Relay Ground to Arduino Ground


The when the upper red wire is closed, the circuit is complete and the device/appliance will start.

In the lab, we have one extension cord that is controlled with an Arduino. The connections are sealed with heat shrink and a cardboard box covers the board and the exposed relay. The two ports that can be accessed are:

  • USB – for programming the start/stop times
  • 12V Barrel Jack – for powering the Arduino board, w/out a computer


This extension cord can turn on/off any appliance (possibly a heat pad?) for any amount of time, indefinitely. It could be fun to have effectively a square-wave control a heat pad, and measure the thermal wave through a medium with thermistors at various depths.

Arduino Code & Diagram