Introduction: Control Relays With a Custom Android App!!
This here is a final project that I made for my micro controller class at my local junior college.
Its a 4 channel relay board that is controlled via a Bluetooth device as well as an android app for a simple interface to control the individual relays.
As far as my understanding of them goes, a relay is a sort of switch allowing low powered circuitry to toggle higher powered devices such as motors and provide an isolation between the two. I am still a student so I'm learning as I go making this a learning experience for me as well as anyone else that may wish to tackle this project!
What you'll need for this project is an understanding of how to create a program within the arduino IDE and if you wish to create your own app (optional) an understanding of how to use the MIT App Inventor would be a great help as it would have saved me a good bit of time.
an arduino compatible board (I used the arduino uno)
a relay board (this depends on how many things you wish to control, I had a 4 channel from seeedstudio.com)
a Bluetooth transceiver such as the HC-05
a Bluetooth capable device such as a phone or tablet
A warning: Relays can be used to control higher powered devices that could potentially expose the user to dangerous voltages! That being said, I do not assume any kind of responsibility for any injury or damages and suggest that you exercise caution.
Step 1: Wiring It Up.
My relay board came in shield form so it was as simple as plug and play, however many relay boards do not so for the sake of teaching i will be explaining how to wire up one that does not stack on the arduino.
first we'll start off wiring up the GROUND and 5V pins.
next is to wire each relay to the board
relay 1 - pin 7
relay 2 - pin 6
relay 3 - pin 5
relay 4 - pin 4
if you wish to test if your wiring is correct simply upload the blink code in the examples area (after making sure the pin that is supposed to blink is changed in the code to any of the relay pins). If you aren't using a solid state relay you should be able to hear an audible click coming from your relay! For redundancy I used the continuity tester on my multimeter which would beep each time the circuit was closed further confirming my relay was switching as it should. Testing things as you go makes for less potential hair pulling due to problems in the future.
Step 2: Wiring Up the Bluetooth Module.
The Bluetooth module was really easy to wire up, aside from the power and ground wires you only need one other wire.
The HC-05 module has labeled pins so wiring it up is pretty self explanatory.
A couple notes about it though.The En pin is the enable pin allowing you to change the settings of the module itself (such as visible name and password) using AT commands. The TX pin is the transmit pin and is usually wired to the RX pin of the arduino and vice versa for the RX pin. THE ARDUINO CANNOT RECEIVE AN UPLOAD WHEN THE RX PIN IS OCCUPIED so make sure to unplug the bluetooth module when uploading your code.
And finally the state pin is a status monitoring pin. wiring an led to it allows you to identify what state the module is in (like if it's paired to a device or not).
Step 3: Making It Work.
The last thing to do to get this thing working is to upload the code for it and get the thing running.
A quick note:
bluetooth likes to send the ascii code for the decimal characters to be sent.
for example in the code we send a number 1 but the ascii equivalent 49 is received. To make things happen we can send a decimal number but watch for an ascii code to show up.
Step 4: The App!!
This here is an optional step but for this to work over bluetooth you need at least some kind of bluetooth terminal application available at the app store. These work great but I wanted my own custom interface to control my devices the way I wanted.
I used the MIT App Inventor 2 to create my app. They have an interface much like the "scratch for arduino" that many use to first get into programming arduinos.
if any of you feel like using a copy of my app feel free to use it, but it will need modification to use with more than a
4 channel relay board.
the .apk file is the one to install onto your phone. the .aia file is uploaded to MIT app inventor to change it.
feel free to modify or change anything here to fit your needs!