Contents
Bluetooth Based Home Automation project using Arduino
This project create a home automation system that will control home appliances via HC-05 Bluetooth and an Android application.
HC-05 Bluetooth will be used to communicate with Arduino using an Android Application known as the S2 Terminal. There are also other apps but this is free and easy to use.
HC-05 Bluetooth module
Connection Diagram of Bluetooth Controlled Home Automation Project In this section, we will explain the connections of the various components specified above with Arduino Uno to form the home automation system.
Arduino with HC-05 Bluetooth Module
The HC-05 comes with multiple pins and indicators, which helps to control different operations and view their states through indicators. This pinout diagram provides indications of all pins.
However, we will use 4 of these pins to connect with Arduino. These include the VCC, GND, RX, and TX pins.
The connection of the HC-05 Bluetooth module with Arduino UNO is very easy as we will be using the serial communication interface that consists of two pins TX and RX. As you know, in order to communicate with the HC-05 Bluetooth module, we need to use a UART communication port of the Arduino board.
RX and TX pins of the module will be connected with the UART pins of Arduino UNO. Arduino Uno has a single UART interface found on pin 0 (RX0) and pin 1 (TX0).
Bluetooth to Arduino Connection
HC-05 = Arduino UNO
VCC = 5V
GND = GND
TX = pin 0 (RX)
RX = pin1 (TX)
Arduino with 16×2 LCD
We will use a 16×2 LCD in our project to display the states of the appliances. To connect a 16×2 LCD with Arduino we will require an additional 10k potentiometer as well.
We have a dedicated tutorial regarding interfacing 16×2 LCD display with Arduino with some example sketches. Have a look at it before proceeding further for a better understanding of the LCD.
Arduino connections with 16×2 LCD
We are using the following connections as described below. Refer to the schematic diagram to have a clearer idea of the connections.
16×2 LCD with Arduino
D4 – D7 Pin = 10,11,12,13
Enable = Pin 9
RS = Pin 8
RW = GND
VEE = 10k POT (Middle Leg)
VSS = GND
VCC = +5V
LED+ = +5V
LED- = GND
4 Channel Relay module
The relay module for Arduino is one of the most powerful applications for Arduino as it can be used to control both A.C and D.C devices by simply controlling the relay by giving 5V. A relay is basically a switch which is operated electrically by an electromagnet.
A relay can be used to control high voltage electronic devices such as motors as well as low voltage electronic devices such as a light bulb or a fan
Relay Connection
External 5 volt to JD VCC.
Ground to ground.
IN1 to Pin 3.
IN2 to Pin 4.
IN3 to Pin5.
VCC to Arduino 5v.
Connect one end of all bulbs to the normally open terminal of relays.
One end of 220VAC to all common terminals of relay and other ends with other terminals of the light lamps.
Working Details
Throughout this guide, we will use an android smartphone that will connect to our Arduino development board. So, make sure you have an android phone at hand. We will also use a Bluetooth terminal application to pair the two devices together.
Go to the Play Store and download the application by the name: S2 Terminal.
Open the application and connect to the Bluetooth module. Write the specified commands and send it. Bluetooth module receives them and the Arduino performs the operation, displays the status on the LCD, and sends a message back to the mobile.
Arduino Sketch
#include <LiquidCrystal.h> LiquidCrystal lcd(8, 9, 10, 11, 12, 13); #define TV 3 #define FAN 4 #define LIGHT 5 int tx = 1; int rx = 0; char inSerial[15]; void setup() { Serial.begin(9600); pinMode(TV, OUTPUT); pinMode(FAN, OUTPUT); pinMode(LIGHT, OUTPUT); pinMode(tx, OUTPUT); pinMode(rx, INPUT); digitalWrite(TV, HIGH); digitalWrite(FAN, HIGH); digitalWrite(LIGHT, HIGH); lcd.begin(16, 2); lcd.clear(); lcd.setCursor(0, 0); lcd.print(" WELCOME TO "); lcd.setCursor(0, 1); lcd.print(" EEE DEPARTMENT "); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print(" THANKS TO HOD "); lcd.setCursor(0, 1); lcd.print("Dr.S.CHITRA.M.E "); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print("THANKS TO GUIDE "); lcd.setCursor(0, 1); lcd.print("Mr.V.VELU. M.E.,"); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print(" SUBMITTED BY "); lcd.setCursor(0, 1); lcd.print(" DIVYAPRABHA M "); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print(" DEVA C "); lcd.setCursor(0, 1); lcd.print(" GOPIKASRI S "); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print(" GUHANESH A "); lcd.setCursor(0, 1); lcd.print(" PRAVIN K "); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print(" RAGHUL A "); lcd.setCursor(0, 1); lcd.print(" THANKS TO ALL "); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print("1.LED TV SWITCH "); lcd.setCursor(0, 1); lcd.print("2.FAN SWITCH "); delay(2000); lcd.clear(); lcd.print("3.LIGHT SWITCH "); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print(" TV LIGHT FAN "); lcd.setCursor(0, 1); lcd.print(" OFF OFF OFF "); } void loop() { int i = 0; int m = 0; delay(500); if (Serial.available() > 0) { while (Serial.available() > 0) { inSerial[i] = Serial.read(); i++; } inSerial[i] = '\0'; Check_Protocol(inSerial); } } void Check_Protocol(char inStr[]) { int i = 0; int m = 0; Serial.println(inStr); if (!strcmp(inStr, "all on")) { digitalWrite(TV, LOW); digitalWrite(FAN, LOW); digitalWrite(LIGHT, LOW); Serial.println("ALL ON"); lcd.setCursor(4, 1); lcd.print("ON "); lcd.setCursor(8, 1); lcd.print("ON "); lcd.setCursor(12, 1); lcd.print("ON "); for (m = 0; m < 11; m++) { inStr[m] = 0; } i = 0; } if (!strcmp(inStr, "all off")) { digitalWrite(TV, HIGH); digitalWrite(FAN, HIGH); digitalWrite(LIGHT, HIGH); Serial.println("ALL OFF"); lcd.setCursor(4, 1); lcd.print("OFF "); lcd.setCursor(8, 1); lcd.print("OFF "); lcd.setCursor(12, 1); lcd.print("OFF "); for (m = 0; m < 11; m++) { inStr[m] = 0; } i = 0; } if (!strcmp(inStr, "tv on")) { digitalWrite(TV, LOW); Serial.println("TV ON"); lcd.setCursor(4, 1); lcd.print("ON "); for (m = 0; m < 11; m++) { inStr[m] = 0; } i = 0; } if (!strcmp(inStr, "tv off")) { digitalWrite(TV, HIGH); Serial.println("TV OFF"); lcd.setCursor(4, 1); lcd.print("OFF "); for (m = 0; m < 11; m++) { inStr[m] = 0; } i = 0; } if (!strcmp(inStr, "fan on")) { digitalWrite(FAN, LOW); Serial.println("FAN ON"); lcd.setCursor(8, 1); lcd.print("ON "); for (m = 0; m < 11; m++) { inStr[m] = 0; } i = 0; } if (!strcmp(inStr, "fan off")) { digitalWrite(FAN, HIGH); Serial.println("FAN OFF"); lcd.setCursor(8, 1); lcd.print("OFF "); for (m = 0; m < 11; m++) { inStr[m] = 0; } i = 0; } if (!strcmp(inStr, "light on")) { digitalWrite(LIGHT, LOW); Serial.println("LIGHT ON"); lcd.setCursor(12, 1); lcd.print("ON "); for (m = 0; m < 11; m++) { inStr[m] = 0; } i = 0; } if (!strcmp(inStr, "light off")) { digitalWrite(LIGHT, HIGH); Serial.println("LIGHT OFF"); lcd.setCursor(12, 1); lcd.print("OFF "); for (m = 0; m < 11; m++) { inStr[m] = 0; } i = 0; } else { for (m = 0; m < 11; m++) { inStr[m] = 0; } i = 0; } }