ESP32WIFI&BLUETOOTH AUTOMATION


ESP32 WIF AND BLUETOOTH AUTOMATION PROJECT

ESP32WIFI &BLUETOOTH APP

 https://drive.google.com/file/d/1z-R4FT0b_K4UCcvJO7Imk8fGrJe8UETx/view?usp=sharing


ARDUINO SKETCH FOR THE ABOVE PROJECT

#define BLYNK_PRINT Serial


#include <BlynkSimpleEsp32.h> // https://github.com/blynkkk/blynk-library

#include "BluetoothSerial.h" // https://github.com/espressif/arduino-esp32/tree/master/libraries/BluetoothSerial



#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;

int bluedata; // variable for storing bluetooth data 

int relay1 = 18; //GPIO PI N 18 IS ASSIGNED AS VARIABLE NAME RELAY1-1

int relay2 = 19;//GPIO PI N 19 IS ASSIGNED AS VARIABLE NAME RELAY1-2

int relay3 = 21;//GPIO PI N 21 IS ASSIGNED AS VARIABLE NAME RELAY1-3

int relay4 = 22;//GPIO PI N 22 IS ASSIGNED AS VARIABLE NAME RELAY1-4

int relay5 = 23;//GPIO PI N 23 IS ASSIGNED AS VARIABLE NAME RELAY1-5

char auth[] = "2-DNFBbJvD4TV_LB0HDu809M_dP0uqcZ"; //  BLYNK AUTHCODE HERE

char ssid[] = "dewa406";  // YOUR SSID

char pass[] = "Ramesh16384"; // YOUR WIFI PASSWORD

BLYNK_WRITE(V1)

{

  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable

  digitalWrite(relay1, !pinValue);

  // process received value

}


BLYNK_WRITE(V2)

{

  int pinValue = param.asInt(); // assigning incoming value from pin V2 to a variable

  digitalWrite(relay2, !pinValue);

  // process received value

}


BLYNK_WRITE(V3)

{

  int pinValue = param.asInt(); // assigning incoming value from pin V3 to a variable

  digitalWrite(relay3, !pinValue);

  // process received value

}


BLYNK_WRITE(V4)

{

  int pinValue = param.asInt(); // assigning incoming value from pin V4 to a variable

  digitalWrite(relay4, !pinValue);

  // process received value

}




void setup() 

{

  Serial.begin(115200);


  btStart();  Serial.println("Bluetooth On");


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

  Serial.println("The device started, now you can pair it with bluetooth!");

  delay(10000);


  pinMode(relay1, OUTPUT); //DECLARED PIN 18 AS OUTPUT

  pinMode(relay2, OUTPUT);//DECLARED PIN 19 AS OUTPUT

  pinMode(relay3, OUTPUT);//DECLARED PIN 21 AS OUTPUT

  pinMode(relay4, OUTPUT);//DECLARED PIN 22 AS OUTPUT

  pinMode(relay5, OUTPUT);//DECLARED PIN 23 AS OUTPUT

  digitalWrite(relay1, LOW);//RELA Y 1 DEFAULT STATUS IS ASSIGNED IN OFF

  digitalWrite(relay2, LOW);//RELA Y 2 DEFAULT STATUS IS ASSIGNED IN OFF

  digitalWrite(relay3, LOW);//RELA Y 3 DEFAULT STATUS IS ASSIGNED IN OFF

  digitalWrite(relay4, LOW);//RELA Y 4 DEFAULT STATUS IS ASSIGNED IN OFF

  digitalWrite(relay5, LOW);//RELA Y5 DEFAULT STATUS IS ASSIGNED IN OFF


  Serial.println("Connecting to Internet");

  delay(2000);


  WiFi.begin(ssid, pass); Serial.println("WiFi On");

  Blynk.config(auth);


  delay(2000);


}

void loop() 

{


  if (WiFi.status() != WL_CONNECTED)

  {

    Serial.println("Not Connected");

  }

  else

  {

    Serial.println(" Connected");

    Blynk.run();

  }


  if (SerialBT.available())

  {


    Bluetooth_handle();


  }


}


void Bluetooth_handle()

{

  //char bluedata;

  bluedata = SerialBT.parseInt();

  //Serial.println(bluedata);

  delay(20);

  if (1 == bluedata) {                 // IF THE VALUE IS 1 FROM BLUETOOTH APP 

    digitalWrite(relay1, LOW); //SWITCH THE RELAY 1 OFF

    Blynk.virtualWrite(V1, 1);

    SerialBT.println("relay1 on");

    Serial.print("relay1 on\n");

  }

  else if (2 == bluedata) {    // // IF THE VALUE IS 2 FROM BLUETOOTH APP 

    digitalWrite(relay1, HIGH);  //SWITCH THE RELAY 1 ON

    Blynk.virtualWrite(V1, 0);

    SerialBT.println("relay1 off");

    Serial.print("relay1 off\n");

  }

  else if (3 == bluedata) { // IF THE VALUE IS 3 FROM BLUETOOTH APP 

    digitalWrite(relay2, LOW); //SWITCH THE RELAY 2 OFF

    Blynk.virtualWrite(V2, 1);

    SerialBT.println("relay2 on");

    Serial.print("relay2 on\n");

  }

  else if (4 == bluedata) {   // IF THE VALUE IS 4 FROM BLUETOOTH APP 

    digitalWrite(relay2, HIGH); //SWITCH THE RELAY 2 ON

    Blynk.virtualWrite(V2, 0);

    SerialBT.println("relay2 off");

    Serial.print("relay2 off\n");

  }

  else if (5 == bluedata) {   // IF THE VALUE IS 5 FROM BLUETOOTH APP 

    digitalWrite(relay3, LOW); //SWITCH THE RELAY 3 OFF

    Blynk.virtualWrite(V3, 1);

    SerialBT.println("relay3 on");

    Serial.print("relay3 on\n");

  }

  else if (6 == bluedata) {  // IF THE VALUE IS 6 FROM BLUETOOTH APP 

    digitalWrite(relay3, HIGH);   //SWITCH THE RELAY 3 ON

    Blynk.virtualWrite(V3, 0);

    SerialBT.println("relay3 off\n");

    Serial.print("relay3 off\n");

  }

  else if (7 == bluedata) {  // IF THE VALUE IS 7 FROM BLUETOOTH APP 

    digitalWrite(relay4, LOW);   //SWITCH THE RELAY 4 OFF

    Blynk.virtualWrite(V4, 1);

    SerialBT.println("relay4 on\n");

    Serial.print("relay4 on\n");

  }

  else if (bluedata == 8) {// IF THE VALUE IS 8 FROM BLUETOOTH APP 

    digitalWrite(relay4, HIGH);  //SWITCH THE RELAY 4 ON

    Blynk.virtualWrite(V4, 0);

    SerialBT.println("relay4 off");

    Serial.print("relay4 off\n");

  }

  else if (9 == bluedata) { // IF THE VALUE IS 9 FROM BLUETOOTH APP 

    digitalWrite(relay5, LOW); //SWITCH THE RELAY 5 OFF

    Blynk.virtualWrite(V5, 1);

    SerialBT.println("relay5 on\n");

    Serial.print("relay5 on\n");

  }

  else if (bluedata == 10) {  // IF THE VALUE IS 10 FROM BLUETOOTH APP 

    digitalWrite(relay5, HIGH);//SWITCH THE RELAY 5 OFF

    Blynk.virtualWrite(V5, 0);

    SerialBT.println("relay5 off");

    Serial.print("relay5 off\n");

  }

  else

  {

  }

}

Comments

Popular posts from this blog

4 Stage Timer With DS3231RTC Module.

Interfacing KY038 sound sensor with Raspberry pi Pico

Interfacing MQ2 Gas & Smoke Sensor With Raspberry Pi Pico