#define BLYNK_TEMPLATE_ID "TMPL6BVx23ZeG"
#define BLYNK_TEMPLATE_NAME "LAB TEST DHT22"
#define BLYNK_AUTH_TOKEN "SwDyMau-xCjy_DZyDZVHi10p5I7KJD9A"
#define BLYNK_PRINT Serial
#include <BluetoothSerial.h>
BluetoothSerial SerialBT;
int bluedata; // variable for storing bluetooth data
int relay1 = 1;
char auth[] = "SwDyMau-xCjy_DZyDZVHi10p5I7KJD9A";
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BLYNK_WRITE(V1)
{
int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
digitalWrite(relay1, !pinValue);
// process received value
}
void setup()
{
Serial.begin(115200);
//btStart(); Serial.println("Bluetooth On");
SerialBT.begin("ESP32_Bluetooth"); //Bluetooth device name
Serial.println(F("The device started, now you can pair it with Bluetooth!"));
delay(10000);
pinMode(relay1, OUTPUT);
digitalWrite(relay1, LOW);
Serial.println("Connecting to Internet");
WiFi.begin(ssid, pass); Serial.println("WiFi On");
Blynk.config(auth);
}
void Bluetooth_handle() {
bluedata = SerialBT.parseInt();
delay(20);
switch(bluedata) {
case 1:
digitalWrite(relay1, LOW);
Blynk.virtualWrite(V1, 1);
SerialBT.println("relay1 on");
Serial.println("relay1 on");
break;
case 2:
digitalWrite(relay1, HIGH);
Blynk.virtualWrite(V1, 0);
SerialBT.println("relay1 off");
Serial.println("relay1 off");
break;
default:
break;
}
}
void loop()
{
if (WiFi.status() != WL_CONNECTED)
{
Serial.println("Not Connected");
}
else
{
Serial.println(" Connected");
Blynk.run();
}
if (SerialBT.available())
{
Bluetooth_handle();
}
}