Connecting an Arduino to a Relay Board | 1
Connecting an Arduino to a Relay Board
By William Gay
Overview
This manual will cover a series of steps required to hook up any household appliance to an Arduino micro controller. This will allow anybodyto be able to control household appliances programmatically to saveelectricity.It will also cover the basics of using a relay, and the necessary steps for using the Arduino microcontroller. This manual will present all the required code needed,so no programming experience is required, although it is recommended. Only minor adjustments are going to be made to the codebased on personal needs which should be simple enough for most users to follow. To complete this project it will also require basic knowledge on how to wire electronics and follow basic wiring diagrams.
Equipment Needed
- Arduino Micro Controller
- Small Philips head screw driver
- One 5v relay module at 220v
- An extension cord of any length
- Wire strippers
- Electrical tape
Getting Started
The following steps are to install the necessary Arduino software and making sure there is successful communication to the Arduino.
Installing Arduino IDE
- Type the following link into any web browser and click on the appropriate download link based on the current operating system installed on the computer
- After installing the software, locate and run the program that was installed called Arduino Studio
- On the top left of the window click on File and then click on new
- The picture on the right shows what the screen should look like after a successful installation and a new project has been created
- You are now ready to try and make a connection to the micro controller
Arduino IDE window after initial setup
Connecting to the Arduino
- Plug the USB cable into any USB port on the computer as well as in the appropriate port on the Arduino
- Check to make sure that the green light (see right hand diagram) on the Arduino is glowing which indicates that the Arduino is getting power.
If the light is not on, try disconnecting the cable and plugging it in again. If the light is still not on, try a different USB cable
- In the Arduino IDE window, click the tools icon on the top bar
- Hover the mouse over the Board submenu and then select the exact model of the connected Arduino controller
- Hover the mouse over the Serial Port submenu and then Select the USB port of which the USB cable has been plugged into
- In the Arduino IDE window, click the File menu icon
- Hover the mouse over Examples, then Basics, then click on Blink
- Click on the menu item Sketch and then click on Verify / Compile
- The green led on the Arduino that was solid should now be blinking
Making the Necessary Wire Connections
Wiring up the Arduino to the Relay Board
- Locate the pin labeled with the number 5 on the Arduino board and the pin labeled IN on the relay board
- Take a wire and connect these two pins
- Locate the pin labeled GND on the Arduino as well as on the relay board
- Connect these two pins using a wire
- Locate the pin labeled5v on the Arduino and VCC on the relay board
- Connect them together using a wire
- The relay should now be fully operational and ready to use
Hooking up the Extension Cord to the Relay Board
This will allow any household appliance to be connected to our newly made relay and be controlled by the Arduino
- Locate the extension cord and strip away the outer plastic cover somewhere in the middle of the extension cord
- Once the two wires inside are exposed, choose either one and cut it
- Take both ends of the freshly cut wire and use the wire strippers to expose about a quarter of an inch of the wire
- Take one end of the cut wire and connect it to the relay board on either of the pins labelled NO.
- Take the other end of the wire and connect it to the pin labeled COM.
- Tighten both of the screws located above the pins down using a screw driver
Make sure very little wire is exposed and cover any excess wire with electrical tape. Having exposed wire can be a fire hazard.
- Use the diagram below to make sure the finished product matches the layout presented.
Completed wiring diagram
Final Steps
Setting Up and Modifying the Code
- Within the Arduino Window and within in the new file we created earlier, copy and paste the following code
- This code will turn on and off any connected device for 5 seconds in both the on and off state
- Click on the circular button with a check mark on it to verify there are no errors
- Click on the circular button with a right pointing arrow to upload the code
Steps 3 and 4 Location of Buttons
Testing the Finished Product
- For this test it is best to hook up any standard lamp or light fixture
- Plug the lamp into the extension cord
- Plug the extension cord into any standard household outlet
- Turn the light on using the switch located on the lamp
- Verify that the lamp turns on and off
Optional Steps
These additional steps will show some basic modifications of the Arduino code that will allow for more customization on the amount of time the power is on.
Setting the Amount of Time the Power is on
- Locate in the code the first time the delay is set, look for “Delay(5000);”
- Change that line to the amount of milliseconds you wish to leave the power on.
Example: To leave the light on for 1 hour set change the line to:“Delay(3600000);”
- Locate second location where the delay is set and change it to the amount of milliseconds that you wish to leave the power off.
- Now your relay board will stay on and off for the amount of time you have set
- It is recommended to set the on time to only when you will be using the appliance to save the most amount of electricity.