Introduction: Arduino Powered Bluetooth Remote Relay Switch

Hi

I wanted to build a simple 2 channel bluetooth remote switch box. 
to allow me to remotely switch various devices on and off from my android phone.

The device had to be small easy to use and flexable enough to control anything I wanted.
some of the uses are controling my slr camera. and to switch on mains devices like lights.

parts needed.
1 arduino board ( i used a arduino nano as it was small and easy to attach to a computer to program)
1 relay board
1 bluetooth module (I used a jy-mcu module because it was cheap)
A plastic box to put everything in
A battery holder

I purchased the arduino board the bluetooth module and the relay board from ebay.
the plastic box and battery holder came from maplin.
be careful when purchasing the bluetooth module and check that its the board and bluetooth chip. as some on ebay are just the board without the bluetooth chip.

total cost was £20


Step 1: Connecting the Arduino Board to the Computer

first of all I connected the arduino board to my computer usb port.
the board should light up.

now if you havnt got the arduino IDE software you should go here http://arduino.cc/en/Main/Softwareto download it
it should already be in the repositorys if you are using ubuntu linux.

when the software has been installed and opened. check the port and board setting are correct.
this will be under tools > board (select the board option to match your arduino board)
and tools > serial port. if this is greyed out you will have to check that your drivers are installed correctly for your board.

when the software is set up and communicating with your arduino. its time to write the code.



Step 2: Arduino Sketch

here is a copy of my arduino sketch.

what will happen is when I send a command A to H the relay will be switched on and if I send a to h the relay will be switched off.
I have programmed it so that
A is relay one on (latched)
B is relay two on (latched)
C is relay one on for 1 second
D is relay two on for 1 second
E is relay one on for 5 second
F is relay two on for 5 seconds
G is relay one on for 1 second then relay two on then both off
H will switch relay one on and off for 1000 times

the relays switch on when the digital pin is grounded. and the relay switches off when the digital pin goes high

here is the code

/*
simple LED test
*/

char val;         // variable to receive data from the serial port
int ledpin = 2;  // LED connected to pin 2 (on-board LED)

void setup()
{
  pinMode(ledpin = 2, OUTPUT); // pin 2 (on-board LED) as OUTPUT
  pinMode(ledpin = 3, OUTPUT); // pin 3 (on-board LED) as OUTPUT

    Serial.begin(9600);       // start serial communication at 115200bps

}

void loop()

{
  if( Serial.available() )       // if data is available to read
  {
    ;
  }
  val = Serial.read();         // read it and store it in 'val'

  if( val == 'a' )               // if 'a' was received led 2 is switched off
  {
    digitalWrite(ledpin = 2, HIGH);    // turn Off pin 2
  }
 
  if( val == 'A' )               // if 'A' was received led 2 on
  {
    digitalWrite(ledpin = 2, LOW);  // turn ON pin 2
  }

  if( val == 'b' )               // if 'b' was received led 3 is switched off
  {
    digitalWrite(ledpin = 3, HIGH);    // turn Off pin 3
  }
 
  if( val == 'B' )               // if 'B' was received led 3 on
  {
    digitalWrite(ledpin = 3, LOW);  // turn ON pin 3
  } //else (ledpin = 3, LOW)        //set led pin 3 to low state

  if( val == 'C' )               // if 'C' was received led 2 on for 1 second
  {
    digitalWrite(ledpin = 2, LOW);  // turn ON pin 2
    delay(1000);                     // wait 1 second
    digitalWrite(ledpin, HIGH);      // turn Off pin 2
  }

  if( val == 'D' )               // if 'D' was received led 3 on for 1 second
  {
    digitalWrite(ledpin = 3, LOW);  // turn ON pin 3
    delay(1000);                     // wait 1 second
    digitalWrite(ledpin, HIGH);      // turn Off pin 3
  }
 
  if( val == 'E' )               // if 'E' was received led 2 on for 5 seconds
  {
    digitalWrite(ledpin = 2, LOW);  // turn ON pin 2
    delay(5000);                     // wait 500 milli seconds
    digitalWrite(ledpin, HIGH);      // turn Off pin 2
  }
 
  if( val == 'F' )               // if 'F' was received led 3 on for 5 seconds
  {
    digitalWrite(ledpin = 3, LOW);  // turn ON pin 3
    delay(5000);                     // wait 500 milli seconds
    digitalWrite(ledpin, HIGH);       // turn Off pin 3
  }
 
  if( val == 'G' )               // if 'G' was received turn led pin 2 on for 500ms then switch off and turn on pin 3 for 500 mili seconds then off
  {
    digitalWrite(ledpin = 2, LOW);  // turn ON pin 2
    delay(500);                     // wait 500mili second
    digitalWrite(ledpin, HIGH);      // turn Off pin 2
    digitalWrite(ledpin = 3, LOW);  // turn ON pin 2
    delay(500);                     // wait 500 mili second
    digitalWrite(ledpin, HIGH);      // turn Off pin 2
  }
 
  if( val == 'h' )               // if 'h' was received switch off all pins
  {
    digitalWrite(ledpin = 13, LOW);    // turn Off pin 13
    digitalWrite(ledpin = 2, HIGH);      // turn Off pin 2
    digitalWrite(ledpin = 3, HIGH);      // turn Off pin 3
}
 
  if( val == 'H' )               // if 'H' was received switch pin 2 on and off 1000 times

  for(int i = 0; i < 1000; i++)
  {
    digitalWrite(ledpin = 2, HIGH);  // turn ON pin 2
   delay (1000); //wait 1000 mili seconds
    digitalWrite(ledpin = 2, LOW);  // turn Off pin 2
   delay (1000); //wait 1000 mili seconds
  
  }

}



Step 3: Uploading the Code

when you are happy with the sketch it can be uploaded to the arduino by pressing the upload button in the IDE.

you will not be able to upload the code if the bluetooth module is already connected to the arduino.


Step 4: Wiring It All Together.

the relay board and arduino will need a 5volt power supply.
the bluetooth module can be powered from the 3.3 volt pin on the arduino.
the tx on the bluetooth board will be connected to the rx pin on the arduino
the rx pin on the bluetooth board will be connected to the tx pin on the arduino
and the digital output pins 2 and 3 on the arduino will be wired to the relay board as shown in the diagram.


Step 5: Connecting to Your Phone and Testing

now if you have uploaded the code ok.
and everything is wired correctly the boards should power on and the light on the bluetooth module should flash.

I wanted to be able to control it from my android phone.
luckly for me Amphan had already done all the hard work and writen a very good android app called Arduino Bluetooth Control. which is on the google play store
https://play.google.com/store/apps/details?id=com.app.control&hl=en


after installing and opening the arduino bluetooth control app. I had to pair the phone to the bluetooth module.
my module was listed as HC-06 and the pin was 1234.

after pairing it was just a matter of pressing the connect button on the bottom of the app.

they connected ok and I was able to switch the relays on and off using the buttons on the app.

if you have problems connecting or controlling the arduino check that the baud rate in the software matches the baud rate of the bluetooth module.



Step 6: Fitting Everthing in the Box

the next step was to mount everthing in a plastic box.

the box i got from maplin was quite small and the battery holder just fitted after a little alteration.

I had to cut a few holes and drill some mounting holes for the relay board.


and here is the finished device.

after checking that it all still worked propperly.
I wired up a light to the relay to check that it all switched as required.

Comments

author
Mr innovative (author)2015-03-02

i need help.

dear simon72post i am building bluetooth remote relay switch same as yours. i am using components as mention below

1) arduino uno.

2) 4 channel, 12vdc relay card.

3) HC-05 Bluetooth module.

4) Arduino bluetooth control device android app

5) jumper wires etc.

How i wired my componnents i have shown in blow pic.

now please can you provide me a sketch so that i can operate relay via my android mobile using Arduino bluetooth control device android app.

i think u understand what i want from you i am a bignner in this arduino world and i found your this post very much closer to my need

and please guied me my friend

please my friend help me you can mail me on sharmaz747@gmail.com

MY CIRCUIT.png
author
IlhamB6 (author)Mr innovative2016-08-25

please send the skecth to my email ilhambintang559@gmail.com

author
Westwatts (author)2016-08-09

I have a questiin you may can help with i do heating and air have a unit that has bad tstat wire going from indoor to outdoor unit so it wont allow anything outside to kick on and cant run new wire its not possible is there any bluetooth relay i can build so when thermostat calls for ac it will send signal to od unit and close a relay to allow 24 volts to contator i can put a transformer out there to. Make the 24v but having trouble finding away to control it

author
BharatY1 (author)2016-07-18

i have made this and followed all the instructions,but when i connect by arduino power ,the relays are switching on,my phone connected to bluetooth device but unable to control the relays,they are continously switched on

author
RokibR1 (author)2016-04-18

how many days this project would run if i operate it whole day ?

author
VikT1 made it! (author)2015-11-23

Really cool thing, I just built it, the only change I made I supplied the power from an old phone charger and used a really cheap HC-06 which only operates from 5V+ instead of 3.3V+, otherwise perfect tutorial to control anything around your house under 10A ;-)

20151123_224335.jpg
author
g_nes (author)2015-09-28

I have a problem, when I press the button on my android device sometimes the relay doesn't respond. but I can see TX and RX LED on my arduino blinking.

Can somebody help me?

Thanks,

author
AejazK (author)2015-06-28

Great and thanks it worked for me on 4 relays

author
PriyanS1 (author)AejazK2015-09-15

how can 4 relay, how improve its

author
marsekal (author)2015-06-01

GOOD JOB MR

author
PeppoF (author)2015-01-28

Hi and thanks for sharing project. I was looking for a way to strengthen my remote heat controller, that now uses RF transmitter and receiver, but unfortunately it is not so reliable.

I made your project, but I have some questions;

- in similar projects I saw that is better to make a level converter to 3.3V on the RXD line on HC-06, because the module may not like upper voltages. Did you have problems without?

- I tried to connect the bluetooth module to 3.3V from arduino, but the module seems unstable, cannot accept connections, sometimes switches off. Using the 5V seems fine. Is it dangerous for the module?

In my project I would like to have a feedback on digital input status, and to do this I have to send the digital pin status from the bluetooth module. I realized too late that HC-06 is only a slave device, so I have to buy an HC-05.. is that correct?

Thanks..

author
Ayush Sharma (author)PeppoF2015-03-31

No, you wont need an level converter until and unless you see a base on which bluetooth module is soldered...

and for the hc-06 thing. it would work fine. hc-05 is not necessary.

author
joe.tarin.18 (author)2015-02-27

Thank you very much for your instruction -- Kudos!!!

author
ShrutiM1 (author)2015-02-24

Canweusea6voltsupplyhere?

author
Anth0ny (author)2014-11-19

Hello,

Is there a way to make this and to control this with a iphone ?

Can somebody help me ???

Grz

author
TimothyB2 (author)2014-10-02

I just ordered all the parts to make this

author
incognito0288 (author)2014-02-09

There is a link to this guy's ible.

author
incognito0288 (author)2014-02-09

Check out this awesome Instructable. How to control arduino board using an android phone and a bluetooth module https://www.instructables.com/id/E2CCMJ4HD4VPR0Z/?lang=en

author
incognito0288 (author)2014-02-09

nice...I've made this before. . almost identically. . If you wanted to you can easily make a custom Android app with app inventor...Nice work