Introduction: Control Relays With a Custom Android App!!

Picture of 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

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.

Picture of 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!!

Picture of 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!


GiaJ (author)2017-11-21

Thank you so much its so helpfull...

RustyOneTwo (author)2016-06-22

Using linked .apk, I get a "Runtime error. Permission Denial: starting Intent{act=android.intent.action.MAIN

there is more, but end is


any thoughts? this looked like just what I needed to learn with

I also tried to "build new apk, same result.

Using Gal S4


bodhi3523 (author)RustyOneTwo2016-06-23

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.

RustyOneTwo (author)bodhi35232016-06-23

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,
Thanks again, should I stumble across the needed change I will post.

Gaurav_2010 (author)2016-04-11

Hi Bodhi,

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?

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

bodhi3523 (author)Gaurav_20102016-04-12

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

Gaurav_2010 (author)bodhi35232016-04-29

Thanks Bodhi3523.

App For Tradies (author)2016-01-18

Very comprehensive guide, great work.

שיא1 (author)2015-10-27

Your project is awesome :)

I would be happy if you could help me: add a timer Button!!!

On or Off by timer (Selection of 5 ,10 ,15 Minutes -For example)



nikkpap (author)2015-05-03

wow thanks very nice tutorial... can you make it via http and not via bluetooth ???

like to use a static ip ....

bodhi3523 (author)nikkpap2015-09-08

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

marcoboers (author)nikkpap2015-05-09

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.

bodhi3523 (author)marcoboers2015-05-09

cool I'd love to see the finished product if either of you guys feel like linking it to me!

bodhi3523 (author)nikkpap2015-05-03

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.

Bullfrogerwytsch. (author)2015-06-11

Very nice, Thank you for the aia file.

no problem! feel free to make it better haha

no problem!

Faiqh (author)2015-05-16

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

bodhi3523 (author)Faiqh 2015-05-16

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!

efifi (author)2015-05-12

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 - - but i dont know java, so app inventor would be great for me.


bodhi3523 (author)efifi2015-05-13

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.

efifi (author)bodhi35232015-05-13

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.

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.

i have downloaded the aia file and tried several things as well as compare it to other sample on the forums - it looks fine.

why do i get 507 when selecting the arduino bluetooth?

bodhi3523 (author)efifi2015-05-13

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.

efifi (author)bodhi35232015-05-13

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

great instructable by the way

bodhi3523 (author)efifi2015-05-16

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

Raphango (author)2015-05-05

Great project!!!

bodhi3523 (author)Raphango2015-05-05


instructible01 (author)2015-05-04

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!

bodhi3523 (author)instructible012015-05-04

glad I could help

aditya jindal (author)2015-05-02

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

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.
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!

rhoddity (author)aditya jindal2015-05-03

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

bodhi3523 (author)aditya jindal2015-05-03

personally, I have never used eBay before. but I do know Amazon, adafruit, and all are good places to order stuff from.

paul dito (author)aditya jindal2015-05-03

There are other (safe) places to buy arduino stuff. The Make store or are good examples. Have fun!

chilefil (author)2015-05-03

Awesome tutorial. I've been wanting to try something like this with App Inventor. Nicely done!!

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.

bodhi3523 (author)chilefil2015-05-03

aahh so that's what you can do with those!

fred3655 (author)2015-05-01

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.

bodhi3523 (author)fred36552015-05-01

to be honest, I don't know. I'm still learning. But thanks for the tips about the circuit breaker and fuse

Gene Bond (author)bodhi35232015-05-03

Yes, the common practice is to use a transistor to switch a heavier load from the micro's output, such as:

Nice Instructable, BTW :)

bodhi3523 (author)Gene Bond2015-05-03

sweet thanks for the tip!

smilesfromnowhere (author)2015-05-03

Very cool Instructable!

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?

I go to Modesto Junior College

duncan_a (author)2015-05-03

Excellent Instructable...

Where did you find the graphics for the buttons? Do they change colour to indicate their state?

bodhi3523 (author)duncan_a2015-05-03

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

mostafa_et (author)2015-04-30

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:
1- coil voltage and current
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.
2- Contact voltage and current
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.

bodhi3523 (author)mostafa_et2015-04-30

thanks for the information! I will be the first to admit that I am lacking some knowledge.

mostafa_et (author)bodhi35232015-05-01

We all are. I learned about MIT app inventor from your instructable, thank you :)

littlehenry3 (author)2015-04-30

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

bodhi3523 (author)littlehenry32015-05-01

thanks for the tip!

tomatoskins (author)2015-04-30

Cool idea! What did you decide to control with your relays?

About This Instructable




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