Control Festival Lights Using Arduino and Bluetooth

by swastikchakraborty1203 in Circuits > Arduino

180 Views, 1 Favorites, 0 Comments

Control Festival Lights Using Arduino and Bluetooth

48y398.jpg

This Festival Season you can control your House lighting using your Smartphone. Using Arduino and Bluetooth module we can control our Christmas lights with our phones!

Supplies

download.jpg
yfju.png
  1. Arduino UNO board
  2. USB cable for connecter Arduino UNO
  3. Bluetooth Module HC-05
  4. 4 Channel Relay module (5V)
  5. And Christmas Lights Obviously.

Wiring

4_ch_JeSG5wMFMQ.png

You need to connect the Bluetooth module and the relay module with Arduino. The wiring between Arduino, bluetooth and relay is given above. Here's the Connection between Relay Module, Led strip, and input power:

  1. Connect common-point (com) of Relay Module with Christmas lights.
  2. Connect normally-close (nc) of Relay Module with power.
  3. Connect remaining one home light wire with the power source.

NOTE: Number of outputs depends on you relay module.

Code

The Android app sends the serial data to the connected Bluetooth Module HC-05 by clicking ON button. The Bluetooth device receives the data from the app and sends it through TX pin of Bluetooth module to RX pin of Arduino. The Arduino device read the input data and process it according to program uploaded inside it and generate the output to 4 Chanel Relay Module. Here's the Arduino code for it-

  1. String inputs;  
  2. #define relay1 2 //connect relay1 to pin 9  
  3. #define relay2 3 //connect relay2 to pin 8  
  4. #define relay3 4 //connect relay3 to pin 7  
  5. #define relay4 5 //connect relay4 to pin 6  
  6. #define relay5 6 //connect relay5 to pin 5  
  7. #define relay6 7 //connect relay6 to pin 4  
  8. #define relay7 8 //connect relay7 to pin 3  
  9. #define relay8 9 //connect relay8 to pin 2  
  10. void setup(){  
  11.   Serial.begin(9600); //set rate for communicating with phone  
  12.   pinMode(relay1, OUTPUT); //set relay1 as an output  
  13.   pinMode(relay2, OUTPUT); //set relay2 as an output  
  14.   pinMode(relay3, OUTPUT); //set relay1 as an output  
  15.   pinMode(relay4, OUTPUT); //set relay2 as an output  
  16.   pinMode(relay5, OUTPUT); //set relay1 as an output  
  17.   pinMode(relay6, OUTPUT); //set relay2 as an output  
  18.   pinMode(relay7, OUTPUT); //set relay1 as an output  
  19.   pinMode(relay8, OUTPUT); //set relay2 as an output  
  20.   digitalWrite(relay1, LOW); //switch relay1 off  
  21.   digitalWrite(relay2, LOW); //switch relay2 off  
  22.   digitalWrite(relay3, LOW); //switch relay1 off  
  23.   digitalWrite(relay4, LOW); //switch relay2 off  
  24.   digitalWrite(relay5, LOW); //switch relay1 off  
  25.   digitalWrite(relay6, LOW); //switch relay2 off  
  26.   digitalWrite(relay7, LOW); //switch relay1 off  
  27.   digitalWrite(relay8, LOW); //switch relay2 off  
  28. }  
  29. void loop(){  
  30.   while(Serial.available()){ //check if there are available bytes to read  
  31.     delay(10); //delay to make it stable  
  32.     char c = Serial.read(); //conduct a serial read  
  33.     if (c == '#'){  
  34.       break; //stop the loop once # is detected after a word  
  35.     }  
  36.     inputs += c; //means inputs = inputs + c  
  37.   }  
  38.   if (inputs.length() >0){  
  39.     Serial.println(inputs);  
  40.     if(inputs == "A"){  
  41.       digitalWrite(relay1, LOW);  
  42.     }  
  43.     else if(inputs == "a"){  
  44.       digitalWrite(relay1, HIGH);  
  45.     }  
  46.     else if(inputs == "B"){  
  47.       digitalWrite(relay2, LOW);  
  48.     }  
  49.     else if(inputs == "b"){  
  50.       digitalWrite(relay2, HIGH);  
  51.     }  
  52.     else if(inputs == "C"){  
  53.       digitalWrite(relay3, LOW);  
  54.     }  
  55.     else if(inputs == "c"){  
  56.       digitalWrite(relay3, HIGH);  
  57.     }  
  58.     else if(inputs == "D"){  
  59.       digitalWrite(relay4, LOW);  
  60.     }  
  61.     else if(inputs == "d"){  
  62.       digitalWrite(relay4, HIGH);  
  63.     }  
  64.     else if(inputs == "E"){  
  65.       digitalWrite(relay5, LOW);  
  66.     }  
  67.     else if(inputs == "e"){  
  68.       digitalWrite(relay5, HIGH);  
  69.     }  
  70.     else if(inputs == "F"){  
  71.       digitalWrite(relay6, LOW);  
  72.     }  
  73.     else if(inputs == "f"){  
  74.       digitalWrite(relay6, HIGH);  
  75.     }  
  76.     else if(inputs == "G"){  
  77.       digitalWrite(relay7, LOW);  
  78.     }  
  79.     else if(inputs == "g"){  
  80.       digitalWrite(relay7, HIGH);  
  81.     }  
  82.     else if(inputs == "H"){  
  83.       digitalWrite(relay8, LOW);  
  84.     }  
  85.     else if(inputs == "h"){  
  86.       digitalWrite(relay8, HIGH);  
  87.     }  
  88.     inputs="";  
  89.   }  
  90. }  

Compile and upload your code into the Arduino device using Arduino USB cable


Android App

87t87t8y.PNG

Download and install the Android application of Arduino Bluetooth Controller.