Internet of Things (IoT)
Architecture & Domains
IoT Platforms
IoT + Arduino
MCQ
controlling home light using Bluetooth
IoT project of controlling home light using Bluetooth module, Arduino device, and 4 Channel relay module
In this project, we are going to build a home light controlling system using the Bluetooth network. In this project, we use Bluetooth Module HC-05, Arduino Device, 4 Channel Relay module, etc.
Hardware Requirements
- Arduino UNO board
- USB cable for connecter Arduino UNO
- Bluetooth Module HC-05
- 4 Channel Relay module (5V)
- Jumper wires male to female
- Home Light (Bulb)
- Bulb holder
- Wire
- AC 220v/120v home appliances or 9v Hi-Walt Battery
Software requirements
- Arduino software
Working principle of Arduino-Bluetooth Module
In this project, there are four main components used: Android smartphone Bluetooth application, Bluetooth transceiver, Arduino device, and 4 Channel Relay module.
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.
When the Bluetooth application's button turns ON, it sets the home light ON, and when the Bluetooth application's button turns OFF, it sets the home light OFF.
Write an Arduino program to control the home light using Bluetooth Module, 4 Chanel Relay Module with Android application.
#define relay1 2 //connect relay1 to pin 9
#define relay2 3 //connect relay2 to pin 8
#define relay3 4 //connect relay3 to pin 7
#define relay4 5 //connect relay4 to pin 6
#define relay5 6 //connect relay5 to pin 5
#define relay6 7 //connect relay6 to pin 4
#define relay7 8 //connect relay7 to pin 3
#define relay8 9 //connect relay8 to pin 2
void setup(){
Serial.begin(9600); //set rate for communicating with phone
pinMode(relay1, OUTPUT); //set relay1 as an output
pinMode(relay2, OUTPUT); //set relay2 as an output
pinMode(relay3, OUTPUT); //set relay1 as an output
pinMode(relay4, OUTPUT); //set relay2 as an output
pinMode(relay5, OUTPUT); //set relay1 as an output
pinMode(relay6, OUTPUT); //set relay2 as an output
pinMode(relay7, OUTPUT); //set relay1 as an output
pinMode(relay8, OUTPUT); //set relay2 as an output
digitalWrite(relay1, LOW); //switch relay1 off
digitalWrite(relay2, LOW); //switch relay2 off
digitalWrite(relay3, LOW); //switch relay1 off
digitalWrite(relay4, LOW); //switch relay2 off
digitalWrite(relay5, LOW); //switch relay1 off
digitalWrite(relay6, LOW); //switch relay2 off
digitalWrite(relay7, LOW); //switch relay1 off
digitalWrite(relay8, LOW); //switch relay2 off
}
void loop(){
while(Serial.available()){ //check if there are available bytes to read
delay(10); //delay to make it stable
char c = Serial.read(); //conduct a serial read
if (c == '#'){
break; //stop the loop once # is detected after a word
}
inputs += c; //means inputs = inputs + c
}
if (inputs.length() >0){
Serial.println(inputs);
if(inputs == "A"){
digitalWrite(relay1, LOW);
}
else if(inputs == "a"){
digitalWrite(relay1, HIGH);
}
else if(inputs == "B"){
digitalWrite(relay2, LOW);
}
else if(inputs == "b"){
digitalWrite(relay2, HIGH);
}
else if(inputs == "C"){
digitalWrite(relay3, LOW);
}
else if(inputs == "c"){
digitalWrite(relay3, HIGH);
}
else if(inputs == "D"){
digitalWrite(relay4, LOW);
}
else if(inputs == "d"){
digitalWrite(relay4, HIGH);
}
else if(inputs == "E"){
digitalWrite(relay5, LOW);
}
else if(inputs == "e"){
digitalWrite(relay5, HIGH);
}
else if(inputs == "F"){
digitalWrite(relay6, LOW);
}
else if(inputs == "f"){
digitalWrite(relay6, HIGH);
}
else if(inputs == "G"){
digitalWrite(relay7, LOW);
}
else if(inputs == "g"){
digitalWrite(relay7, HIGH);
}
else if(inputs == "H"){
digitalWrite(relay8, LOW);
}
else if(inputs == "h"){
digitalWrite(relay8, HIGH);
}
inputs="";
}
}
Compile and upload your code into the Arduino device using Arduino USB cable. While uploading code doesn't connect other devices with Arduino.
Digital circuit diagram
Bluetooth Module HC-05 Arduino UNO
RX --------------------------------> TX
TX --------------------------------> RX
GND -----------------------------> GND
5V --------------------------------> 3.3V
4 Channel Relay Module Arduino UNO
GND ------------------------------> GND
IN1 --------------------------------> Pin 9
IN2 --------------------------------> Pin 8
IN3 --------------------------------> Pin 7
IN4 --------------------------------> Pin 6
VCC --------------------------------> 5V
Connection between Relay Module, Bulb, and input power:
- Connect common-point (com) of Relay Module with home light.
- Connect normally-close (nc) of Relay Module with power.
- Connect remaining one home light wire with the power source.
Download and install the Android application of Arduino Bluetooth Controller.apk file. Click Here to Download
Output of project: