#include "DHTesp.h"
const int DHT_PIN = 21;
const int switch_relay = 26;
const int solinoid_relay = 2;
DHTesp dhtSensor;
int temp;
int humd;
int switch_value;
//blynk
/*************************************************************
This sketch shows how to write values to Virtual Pins
NOTE:
BlynkTimer provides SimpleTimer functionality:
App dashboard setup:
Value Display widget attached to Virtual Pin V5
*************************************************************/
#define BLYNK_TEMPLATE_ID "TMPL6grvmp5FP"
#define BLYNK_TEMPLATE_NAME "Smart Door Lock with Authentication"
#define BLYNK_AUTH_TOKEN "RTXgTadrl_1fcXrZzNbifOPNeTZSspLS"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
WidgetLED led1(V2);
BlynkTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
TempAndHumidity data = dhtSensor.getTempAndHumidity();
temp=data.temperature;
humd=data.humidity;
Blynk.virtualWrite(V0, temp);
Blynk.virtualWrite(V1, humd);
Blynk.virtualWrite(V4, temp);
Blynk.virtualWrite(V5, humd);
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.println("---");
}
BLYNK_WRITE(V3) // this command is listening when something is written to V1
{
switch_value = param.asInt(); // assigning incoming value from pin V1 to a variable
if (switch_value == 1)
{
Blynk.virtualWrite(V6, "System started ");
Blynk.virtualWrite(V6, "2 step verificaton triggered ");
Blynk.virtualWrite(V6, "Enter Password");
Serial.println("System started");
Serial.println("2 step verificaton triggered");
digitalWrite(switch_relay, HIGH);
}
else if (switch_value == 0)
{
digitalWrite(switch_relay, LOW);
digitalWrite(solinoid_relay, HIGH);
led1.off();
}
Serial.print("Switch relay value is: "); // printing value to serial monitor
Serial.println(switch_value);
}
//to get the value from the terminal text input
BLYNK_WRITE(V6) {
String input = param.asStr();
Serial.println(input);
if(input.toInt()==1234 && switch_value==1)
{
Blynk.virtualWrite(V6, "door unlocked");
Serial.println("Door is Unlocked");
digitalWrite(solinoid_relay, LOW);
led1.on();
}
else
{
Blynk.virtualWrite(V6, "wrong code");
Serial.println("wrong code");
digitalWrite(solinoid_relay, HIGH);
}
}
void setup() {
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
pinMode(switch_relay, OUTPUT);
pinMode(solinoid_relay, OUTPUT);
digitalWrite(solinoid_relay, HIGH);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
timer.setInterval(1000L, myTimerEvent);
}
void loop() {
Blynk.run();
timer.run(); // Initiates BlynkTimer
}