Click "Follow" to Subscribe to my blog

MENU

SMART HOME USING GOOGLE ASSISTANT | BLYNK | ESP 32 | WIFI + BLUETOOTH


YOUTUBE -COMING SOON..






https://www.youtube.com/watch?v=LCNmMxvQVUM






CIRCUIT DIAGRAM









GOOGLE ASSISTANT CODE-UPLOADING SOON..SUSBCRIBE TO GET NOTIFIED





BLYNK-PROJECT CODE





/****************************************************************************************************************************
WiFi & BLE Control Home Automation using ESP32 and Blynk

Required Library:
Blynk library v0.6.1 https://github.com/blynkkk/blynk-library/releases
BlynkESP32_BT_WF by Khoi Hoang https://github.com/khoih-prog/BlynkESP32_BT_WF- Pls install the old version
Based on orignal code by Crosswalkersam https://community.blynk.cc/u/Crosswalkersam

The Sketch is Modified by Sayantan Pal https://github.com/palsayantan/12-ch-Ultimate-Home-Automation-using-ESP32

*****************************************************************************************************************************
Important Notes:
This code is intended to run on the ESP32 platform!
Check your Tools->Board setting. And select ESP32 Dev Module
To conmpile, use Partition Scheem with large APP size, such as -- Huge APP (3MB No OTA, 1MB SPIFFS)

****************************************************************************************************************************/
//modified by www.arvindunimap.com

#include <BlynkSimpleEsp32_BLE_WF.h>
#include <BlynkSimpleEsp32_WF.h>
#include <BLEDevice.h>
#include <BLEServer.h>
BlynkTimer timer;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth_WiFi[] = "Your Blynk Wifi Token";
char auth_BLE[] = "Your Blynk Ble Token";

char BLE_Device_Name[] = "ESP32_WiFi_BLE";

// Your WiFi credentials.
char ssid[] = "YourWifiName"; // Your Network SSID
char pass[] = "YourWifiPassword"; // Your Network PASSWARD


//www.arvindunimap.com
int RELAY[4] = {25,32,33,29}; // Define Output pins connected to Relay
//int SWITCH[12] = {29, 22, 21, 19, 18, 5, 33, 32, 35, 34, 39, 36}; // Define Input pins connected to Switch
int VPIN[4] = {V1, V2, V3, V4}; // Define Virtual pins assigned in the APP

bool RELAY_STATE[4] = {1, 1, 1, 1};


#define STATUS_LED 2 // Shows Network Status

BLYNK_WRITE(V1) {
RELAY_STATE[0] = param.asInt();
digitalWrite(RELAY[0], RELAY_STATE[0]);
}
BLYNK_WRITE(V2) {
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
digitalWrite(RELAY[1], !pinValue);
// process received value
}
BLYNK_WRITE(V3) {
RELAY_STATE[0] = param.asInt();
digitalWrite(RELAY[2], RELAY_STATE[0]);
}
BLYNK_WRITE(V4) {
RELAY_STATE[0] = param.asInt();
digitalWrite(RELAY[3], RELAY_STATE[0]);
}



//this function will synchronize Relay States when any network/Hardware interruption occurs

BLYNK_CONNECTED() {
//Uncomment this line if you want to follow app configurations
//Blynk.syncAll();

//Uncomment this line if you want to follow Hardware configurations
for (int i = 0; i < 4; i++) {
if (Blynk.connected())
Blynk_WF.virtualWrite(VPIN[i], RELAY_STATE[i]);
else
Blynk_BLE.virtualWrite(VPIN[i], RELAY_STATE[i]);
}
}

// Checks Network connection status in every 10 seconds
void Network_Checkup() {
if (WiFi.status() != WL_CONNECTED) {
WiFi.begin(ssid, pass);
delay(10);
}
}

/*void AUTOMATE() {
for (int i = 0; i < 4; i++) {
// if (digitalRead(SWITCH[i]) == LOW) {
// if (SWITCH_STATE[i] != LOW) {
// RELAY_STATE[i] = !RELAY_STATE[i];
// digitalWrite(RELAY[i], RELAY_STATE[i]);
if (Blynk.connected())
Blynk_WF.virtualWrite(VPIN[i], RELAY_STATE[i]);
else
Blynk_BLE.virtualWrite(VPIN[i], RELAY_STATE[i]);}*/

//SWITCH_STATE[i] = LOW;
//}
//else {
// SWITCH_STATE[i] = HIGH;
//}
// }
// }

// }
void setup() {
pinMode(STATUS_LED, OUTPUT);

for (int i = 0; i < 4; i++) {
// pinMode(SWITCH[i], INPUT);
pinMode(RELAY[i], OUTPUT);
digitalWrite(RELAY[i], HIGH);
}
//Setup BLE Connection
Blynk_BLE.setDeviceName(BLE_Device_Name);
Blynk_BLE.begin(auth_BLE);
//Setup WiFi Connection
Blynk_WF.begin(auth_WiFi, ssid, pass);
// timer enable function
timer.setInterval(10000L, Network_Checkup);
}

void loop() {
if (WiFi.status() == WL_CONNECTED) {
if (Blynk.connected()) {
digitalWrite(STATUS_LED, HIGH);
}
}
else {
digitalWrite(STATUS_LED, LOW);
}

//AUTOMATE();
Blynk_WF.run();
Blynk_BLE.run();
timer.run();
}



Comments

Popular posts from this blog

PART 1 | HOW TO CREATE A FREE BLOGSPOT

LAB 4 | FULL GUIDE | BASIC LINUX COMMANDS

PART 3 | HOW TO ADD SUBMENUS AND MAIN MENU | ADVANCED