loading

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.

materials:

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!

<p>Using linked .apk, I get a &quot;Runtime error. Permission Denial: starting Intent{act=android.intent.action.MAIN cmp=com.android.vending/com.google.android.finsky.setup. </p><p>there is more, but end is </p><p>requires com.android.vending.setup.PLAY_SETUP_SERVICE</p><p>any thoughts? this looked like just what I needed to learn with</p><p>I also tried to &quot;build new apk, same result. </p><p>Using Gal S4</p><p>TIA</p>
<p>I made this app over a year ago and there have been a few updates to android phones since then. im assuming that would be the reason it's not working any longer because I get the exact same error on my phone. what could be done though is to upload the .apk to the app inventor and tweak it till it works with the current version of the phones.</p>
Thanks for the reply, I am learning app inventor and will soon be able to make use of and alter the framework of the app you made,<br>Thanks again, should I stumble across the needed change I will post.
Hi Bodhi,<br><br>Very neat and handy instructable. I want to make a setup similar to this for powering on my air condition before I come home from work (India is very hot !!) But how do I make the command to android phone to turn on the Bluetooth relay when I am at work? <br><br>I think it would need one more app which can recognize a special command sms and when the android phone receives a sms, this auxiliary app recognizes the unique code in sms and triggers the corresponding relay to turn on. But This would require programming skills which I don't have. Any info would be helpful. Thanks
Well first off the Bluetooth won't have that kind of range to reach your home from work. You'll need some kind of web service to do that. If you don't know how to do that yourself, a website called carriots has a free (at least for the first one) intertnet of things service that will let you control the relays via the internet. As for programming the relays, it should be similar to how I've done it. Have them wait and watch for you to send something and, once they see it, perform an action such as turning on or off. Hope that helps
Thanks Bodhi3523.
<p>Very comprehensive guide, great work.</p>
<p>Your project is awesome :)</p><p>I would be happy if you could help me: add a timer Button!!!</p><p>On or Off by timer (Selection of 5 ,10 ,15 Minutes -For example)</p><p>thanks</p><p>david</p>
<p>wow thanks very nice tutorial... can you make it via http and not via bluetooth ???</p><p>like to use a static ip 192.168.10.10:4000 ....</p>
<p>sorry for the late reply, im still a bit new to this. I'm sure you could but i have no idea how to go about it. if you find out how let me know haha</p>
I had the same idea, I am currently setting up the ethernet board and will try to adjust his app to work through http this week. It has been a long time since I used appinventor but think I'll have it up and running next weekend.
cool I'd love to see the finished product if either of you guys feel like linking it to me!
you know, I have a WiFi and Ethernet shield but haven't gotten around to trying either of them yet so I'm not sure. I'll have to try it out.
<p>Very nice, Thank you for the aia file.</p>
<p>no problem! feel free to make it better haha</p>
no problem!
My final year project is to create an android app for my school with the following features 1) should have a logging panel for 2) profile where user can upload profile change password etc 3)a forum where student can post 4) panel where student can record lecture audio and Video 5)panel where student can access school lecture note. And I don't know how to start please I need help
my best advice would be to find something that is similar and modify it to fit your needs. the MIT app inventor has a kind of marketplace that other users upload their projects allowing you to try them out or modify them. my app above is a highly modified Bluetooth terminal. I hope that helps you get started!
<p>i keep on getting error 507 unable to connect on my android - reading the app inventor forums and help, i cannot find how to solve this. I have loaded both your app on my adruino and android and no joy. any ideas on what the problem might be? my android is 4.4.2 and support BLE - i can connect using this instructable - <a href="https://www.instructables.com/id/Control-RGB-lights-from-Android-with-Arduino-Bluet/" rel="nofollow">https://www.instructables.com/id/Control-RGB-lights...</a> - but i dont know java, so app inventor would be great for me.</p><p>thanks</p>
if I'm understanding you correctly, you're trying to load the app on arduino as well as your phone. The .apk file is only loaded on your phone and the .aia file is only there if you feel like editing it in app inventor. The file containing the code should be the only thing you load onto your arduino.
no, i am loading the .ino on arduina and the apk on andriod. i get the 507 error and cannot connect the two. i have been able to connect the arduino circuit to the android using the other instructable so i am sure the circuits are correct. i have rad about 507 errors and the forums dont help. <br><br>did you do anything else to get the 2 to communicate - i have paired the bluetooth with the arduino, i just cannot select it succesfully on the android. <br><br>i have downloaded the aia file and tried several things as well as compare it to other sample on the forums - it looks fine.<br><br>why do i get 507 when selecting the arduino bluetooth?
hmm that's weird. you're the first person that I've heard has this problem. I do know that you need to find the Bluetooth module with your phone (not in the app) and pair with it. the default password is 1234. then with your phones Bluetooth turned on you open the app and connect within the menu.
thanks - thats is what is supposed to happen but if you look at error 507 a lot of people just cannot get it sorted. maybe particular to a device, android version or some other esoteric problem. i pair with the bluetooth ok its just that the apk cannot see the device. as i said the other instructable worked. there is some mention in the forums if mit looking at this problem- i will persevere and pist when i find the answer<br><br>great instructable by the way
Yeah that's what I was reading too. maybe try it with a Bluetooth terminal that you can download from the app store for free. you should be able to send a 1,2,3,4,5, or 6 to activate the relays.and if the problem persists then it is most likely a phone specific issue or an issue MIT has with the app inventor.a classmate of mine was having a similar issue with a plain Bluetooth terminal on his windows phone. sorry you're having so much trouble but I hope this helps. and hopefully you find a fix. :p
<p>Great project!!!</p>
thanks!
You did a nice little instructable. thanks for the info on the app builder! I have been thinking about that off and on for a while and it saves me a lot of work!
glad I could help
<p>i like this tutorial very much. i also want to build it so i have ordered arduino uno from ebay. i just want to know if its safe to buy from ebay as it is my first time buying from ebay. have you had any bad experience from ebay</p>
I have bought literally hundreds of these little electronic gizmos from eBay (arduino mini, pro micro, mega, etc, as well as relays, led strips, motors, WiFi boards, and more) with less than 1% problems. shipping takes anywhere from 1-4 weeks depending on the seller and random luck.<br>For some components (resistors, capacitors, and other stuff) Tayda electronics is also a great place. adafruit and sparkfun are a little more expensive but they do a lot to support the maker community so I buy from them to. happy making!
<p>I've been using eBay to shop for things for a while now, and so far have yet to find a complaint. Sure I've had a couple of bad buys, but when you buy a $2 mp3 player, you kind of have it coming. In any case, if something goes wrong, the seller will usually accommodate your request for a refund. I try not to buy anything too big on there, and keep my electronics purchases under $50, just to be safe. =P</p>
personally, I have never used eBay before. but I do know Amazon, adafruit, and oddwires.com all are good places to order stuff from.
<p>There are other (safe) places to buy arduino stuff. The Make store or arduino.cc are good examples. Have fun!</p>
<p>Awesome tutorial. I've been wanting to try something like this with App Inventor. Nicely done!!</p><p>In regards to others questions about using a transistor, yes you can but it's hard to beat the relay boards. They are about $10 and they wire up easily to an Arduino or Raspberry Pi. So you can spend more of your time creating and coding. There are also solid state versions if you want the benefit of pulse width modulated output.</p>
aahh so that's what you can do with those!
Could a FET or transistor be used in between the output pin and the relay to prevent damage to the Arduino? Also, I would suggest a fuse or circuit breaker at the output to prevent fire, rated less than the relay, wire or connector capacity.
to be honest, I don't know. I'm still learning. But thanks for the tips about the circuit breaker and fuse
<p>Yes, the common practice is to use a transistor to switch a heavier load from the micro's output, such as: <a href="http://archive.wired.com/geekdad/2012/09/more-arduino-fun/" rel="nofollow">http://archive.wired.com/geekdad/2012/09/more-ardu...</a></p><p>Nice Instructable, BTW :)</p>
sweet thanks for the tip!
<p>Very cool Instructable!</p><p>You mention a microcontroller class at your local junior college. I'd love to take a class like that; what's the name of your school?</p>
I go to Modesto Junior College
<p>Excellent Instructable...<br><br>Where did you find the graphics for the buttons? Do they change colour to indicate their state?</p>
I found the graphics on Google images. and no they don't change sitting on state but they could (or at least the background) by tweaking a bit of the code for the app
Very nice Instructable, thank you for sharing. A quick note about relays in case someone needs it: Just like bodhi said, a relay is an electrically activated switch, which means it has a coil that you connect to your microcontroller and a contact that you connect to your high powered device. Each relay has at least two ratings: <br>1- coil voltage and current <br>This is the voltage and current that your microcontroller needs to provide to activate the relay (ex. 5V DC, 20 mA) make sure that the relay you use is suitable as some relays might need 100 mA which is beyond the microcontroller pin capabilities.<br>2- Contact voltage and current<br>This is the voltage and current that the relay can control (ex. 230 V AC, 5A). Make sure the rating is suitable for your load, especially if you are going to control a power socket which later might have a different device connected, you can get away with a 1A rated relay contact to switch a socket with a table lamp connected, but if you later connect a window air conditioner to this socket by mistake and switch it on the relay might overheat, melt and cause fire. Best practice is to use a relay rated for the maximum current rating for the socket (13A in British standard). I hope this helps.
thanks for the information! I will be the first to admit that I am lacking some knowledge.
We all are. I learned about MIT app inventor from your instructable, thank you :)
<p>Also remember if controlling relay with a transistor or similar, you need a diode in parallel with coil with cathode to +V. This protects transistor from cemf</p>
thanks for the tip!
<p>Cool idea! What did you decide to control with your relays?</p>
I wanted to control 4 electrical sockets independently allowing me to control whatever is plugged into them

About This Instructable

41,398views

595favorites

License:

More by bodhi3523:Control relays with a custom Android app!! 
Add instructable to: