ESP32 Bluetooth Controlled 10Ch HomeAutomation System Using Android App.

ESP32 Bluetooth Controlled 10Ch HomeAutomation System Using Android App.

We all know ESP32 comes with WIFI, Bluetooth Low Energy and Bluetooth Classic,

In this Homeautomation project, we are going to use ESP32 Bluetooth classic feature to control our homeappliances .

Components Requried

1.ESP32 Board.

2.Relay (5volt).

3.IN4007 Diode.

4.BC547 NPN Transistor.

5.Two pin Terminal Connector.

6.Power Break (5volt). 

7.Coustom Designed PCB.

Coustom Made PCB.

Although we can make this project using esp32 and relay modules , but to look project more professional and compact, I used Coustom Designed PCB for this project and with this PCB, We are able to control total 10 no. of devices. 

Android App.

To  control the homeappliances via our smartphone we need an Application.

Download the APK file of this App and install in your phone.

Connection

Connect All the Bulb(any device) as shown in the schematic below.

Code

The code is very simple, and dos’nt need any modification.

#include "BluetoothSerial.h" 


#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run
`make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;


// define the GPIO connected with Relays and switches
#define RelayPin1 26  
#define RelayPin2 27
#define RelayPin3 14 
#define RelayPin4 12 
#define RelayPin5 13  
#define RelayPin6 21
#define RelayPin7 4 
#define RelayPin8 18
#define RelayPin9 19 
#define RelayPin10 2

char bt_data; // variable for storing bluetooth data 


void all_Switch_ON(){
  digitalWrite(RelayPin1, LOW);  delay(100);
  digitalWrite(RelayPin2, LOW);  delay(100);
  digitalWrite(RelayPin3, LOW);  delay(100);
  digitalWrite(RelayPin4, LOW);  delay(100);
  digitalWrite(RelayPin5, LOW);  delay(100);
  digitalWrite(RelayPin6, LOW);  delay(100);
  digitalWrite(RelayPin7, LOW);  delay(100);
  digitalWrite(RelayPin8, LOW);  delay(100);
  digitalWrite(RelayPin9, LOW);  delay(100);
  digitalWrite(RelayPin10, LOW);  delay(100);

}

void all_Switch_OFF(){
  digitalWrite(RelayPin1, HIGH); delay(100);
  digitalWrite(RelayPin2, HIGH); delay(100);
  digitalWrite(RelayPin3, HIGH); delay(100);
  digitalWrite(RelayPin4, HIGH); delay(100);
  digitalWrite(RelayPin5, HIGH); delay(100);
  digitalWrite(RelayPin6, HIGH); delay(100);
  digitalWrite(RelayPin7, HIGH); delay(100);
  digitalWrite(RelayPin8, HIGH); delay(100);
  digitalWrite(RelayPin9, HIGH); delay(100);
  digitalWrite(RelayPin10, HIGH); delay(100);

}

void Bluetooth_handle()
{
  bt_data = SerialBT.read();
  Serial.println(bt_data);
  delay(20);

  switch(bt_data)
      {
        case 'A': digitalWrite(RelayPin1, LOW);   break; // if 'A' received Turn off Relay1
        case 'a': digitalWrite(RelayPin1, HIGH);  break; // if 'a' received Turn on Relay1
        case 'B': digitalWrite(RelayPin2, LOW);   break; // if 'B' received Turn off Relay2
        case 'b': digitalWrite(RelayPin2, HIGH);  break; // if 'b' received Turn on Relay2
        case 'C': digitalWrite(RelayPin3, LOW);   break; // if 'C' received Turn off Relay3
        case 'c': digitalWrite(RelayPin3, HIGH);  break; // if 'c' received Turn on Relay3
        case 'D': digitalWrite(RelayPin4, LOW);   break; // if 'D' received Turn off Relay4
        case 'd': digitalWrite(RelayPin4, HIGH);  break; // if 'd' received Turn on Relay4
        case 'E': digitalWrite(RelayPin5, LOW);   break; // if 'E' received Turn off Relay5
        case 'e': digitalWrite(RelayPin5, HIGH);  break; // if 'e' received Turn on Relay5
        case 'F': digitalWrite(RelayPin6, LOW);   break; // if 'F' received Turn off Relay6
        case 'f': digitalWrite(RelayPin6, HIGH);  break; // if 'f' received Turn on Relay6
        case 'G': digitalWrite(RelayPin7, LOW);   break; // if 'G' received Turn off Relay7
        case 'g': digitalWrite(RelayPin7, HIGH);  break; // if 'g' received Turn on Relay7
        case 'H': digitalWrite(RelayPin8, LOW);   break; // if 'H' received Turn off Relay8
        case 'h': digitalWrite(RelayPin8, HIGH);  break; // if 'h' received Turn on Rela8
        case 'I': digitalWrite(RelayPin9, LOW);   break; // if 'I' received Turn off Relay9
        case 'i': digitalWrite(RelayPin9, HIGH);  break; // if 'i' received Turn on Relay9
        case 'J': digitalWrite(RelayPin10, LOW);   break; // if 'J' received Turn off Relay10
        case 'j': digitalWrite(RelayPin10, HIGH);  break; // if 'j' received Turn on Relay10
        case 'K': all_Switch_ON(); break;  // if 'K' received Turn on all Relays
        case 'k': all_Switch_OFF(); break; // if 'k' received Turn off all Relays
        default : break;
      }
}

void setup()
{
  Serial.begin(9600);

  btStart();  //Serial.println("Bluetooth On");
  
  SerialBT.begin("HA_BT_ESP32"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");
  delay(5000);

  pinMode(RelayPin1, OUTPUT);
  pinMode(RelayPin2, OUTPUT);
  pinMode(RelayPin3, OUTPUT);
  pinMode(RelayPin4, OUTPUT);
  pinMode(RelayPin5, OUTPUT);
  pinMode(RelayPin6, OUTPUT);
  pinMode(RelayPin7, OUTPUT);
  pinMode(RelayPin8, OUTPUT);
  pinMode(RelayPin9, OUTPUT);
  pinMode(RelayPin10, OUTPUT);



  //During Starting all Relays should TURN OFF
  digitalWrite(RelayPin1, LOW);
  digitalWrite(RelayPin2, LOW);
  digitalWrite(RelayPin3, LOW);
  digitalWrite(RelayPin4, LOW);
  digitalWrite(RelayPin5, LOW);
  digitalWrite(RelayPin6, LOW);
  digitalWrite(RelayPin7, LOW);
  digitalWrite(RelayPin8, LOW);
  digitalWrite(RelayPin9, LOW);
  digitalWrite(RelayPin10, LOW);
   
   delay(200);
}

void loop()
{  
  if (SerialBT.available()){
   Bluetooth_handle();
 }

}


One thing you could change if you want, the name of Bluetooth device and rest of thing is OK ,

Uplaod the code to your Arduino Board After selecting right board and COM Port.

SerialBT.begin("HA_BT_ESP32"); //Bluetooth device name

Video Tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *