Created on: 31 October 2012
In this Arduino project, you will build a small relay shield from stripboard. The shield can have one or two relays fitted to it.
Connect the Arduino and relay shield to your PC via a USB cable. Download the PC software and use it to switch anything on and off that is attached to the relays.
The shield is based on the Tiny Stripboard Shield for Arduino project.
This video shows the Arduino shield project and software.
The relay used in the circuit is a 5V relay with part number JRC-23F (JRC-23FHS1DC5V). The bottom view of the wiring diagram for this relay is shown here:
You will need an Arduino board such as the Arduino Uno, as well as a Tiny Stripboard Shield and the components listed in the table below.
Qty | Part | Designator | Notes | Type |
---|---|---|---|---|
2 | 2k2 resistor | R1, R2 | 1/4W, 5% | Resistors |
2 | 470 ohm resistor | R3, R4 | ||
2 | 3mm LED | D1, D2 | For indicating which relay is on | Semiconductors |
2 | 1N4148 | D2, D3 | Diodes | |
2 | PN2222, KSP2222 or similar | Q1, Q2 | PNP transistors | |
2 | 5V relays | RLA1, RLA2 | E.g. JRC-23F 5V miniature PCB relay or similar | Relays |
2 | 3 pole screw terminals | J1, J2 | 2.54mm pin spacing | Connectors |
If you can't get hold of the same relay or a pin compatible part, then you will need to modify the stripboard circuit layout to suit your relay. Make sure that it is a 5V relay.
The relay is a miniature relay that can switch 1A of current at 30V d.c. Don't try to switch anything that is mains powered with this relay.
This photo shows the parts used in the Arduino relay shield project:
A number of wire links will be needed to connect all of the relay contacts to the screw terminal connectors. This is the most tricky part of building the circuit. Beginners should rather stick to connecting a single relay.
To simplify the wiring further, use only the normally-open contacts and a two pole screw terminal.
These images show the top and bottom views of the completed stripboard relay shield.
After building the relay shield, plug it into the Arduino and load this sketch:
/*-------------------------------------------------------------- Program: relay_shield Description: Monitors the USB serial port. If the character '1' is received, relay 1 is switched on. If the character '3' is received, relay 1 is switched off. '2' switches relay 2 on and '4' switches it off. Hardware: Written for the Tiny Stripboard Relay Shield with relay 1 connected to Arduino pin 2 and relay 2 connected to Arduino pin 3. Date: 31 October 2012 Author: W.A. Smith, http://startingelectronics.org --------------------------------------------------------------*/ // relay pin numbers int rel1 = 2; int rel2 = 3; void setup() { Serial.begin(9600); pinMode(rel1, OUTPUT); // relay pins pinMode(rel2, OUTPUT); digitalWrite(rel1, LOW); // switch relays off digitalWrite(rel2, LOW); } void loop() { char rx_byte; if (Serial.available() > 0) { // byte received from USB? rx_byte = Serial.read(); // get byte from USB serial port if (rx_byte == '1') { digitalWrite(rel1, HIGH); // switch relay 1 on } else if (rx_byte == '2') { digitalWrite(rel2, HIGH); // switch relay 2 on } else if (rx_byte == '3') { digitalWrite(rel1, LOW); // switch relay 1 off } else if (rx_byte == '4') { digitalWrite(rel2, LOW); // switch relay 2 off } } }
Test the shield by starting the Arduino Serial Monitor and sending '1' to switch the first relay on, '2' to switch the second relay on, '3' to switch the first relay off and '4' to switch the second relay off.
Download the relay_shield_pc Processing sketch. This software runs on the PC and allows you to switch the Arduino relays on and off.
Load the relay_shield_pc sketch to the Processing IDE. Make sure that the Arduino is plugged into the PC and running the above Arduino sketch. Run the Processing sketch from the Processing IDE and see which port numbers are displayed in the bottom pane of the IDE. If necessary modify the code to select the correct port that the Arduino is attached to. Go to the bottom of temperature shield software page for more details and a video on how to do this.
When the PC application starts, click the buttons in the application to switch the relays on or off.