#define BLYNK_TEMPLATE_ID "TMPL6ebPyFyNd"
#define BLYNK_TEMPLATE_NAME "Control LED"
#define BLYNK_AUTH_TOKEN "7qCwz6X0oANwd9Tos24NJfg_6Cga3eTx"
/* Comment this out to disable prints and save space */
#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[] = "";
#include <DHT.h>
// DHT define
#define DHTPIN 15
#define DHTTYPE DHT22
DHT dht(DHTPIN,DHTTYPE);
#define LIGHT_SENSOR_PIN 34
float t;
float h;
const int pir =14;
BlynkTimer timer;
int analogValue;
void myTimerEvent()
{
Blynk.virtualWrite(V5, millis() / 1000);
}
void setup()
{
// Debug console
Serial.begin(115200);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
dht.begin();
pinMode(pir,INPUT);
timer.setInterval(1000L, myTimerEvent);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
const int IP=digitalRead(pir);
Blynk.virtualWrite(V4, IP);
SEN();
Blynk.virtualWrite(V0, t);
Blynk.virtualWrite(V2, h);
LIGHT();
Blynk.virtualWrite(V1, analogValue);
}
void SEN()
{
t = dht.readTemperature();
h = dht.readHumidity();
}
void LIGHT()
{
analogValue = analogRead(LIGHT_SENSOR_PIN);
Serial.print("Analog Value = ");
Serial.print(analogValue); // the raw analog reading
// We'll have a few threshholds, qualitatively determined
if (analogValue < 40) {
Serial.println(" => Dark");
} else if (analogValue < 800) {
Serial.println(" => Dim");
} else if (analogValue < 2000) {
Serial.println(" => Light");
} else if (analogValue < 3200) {
Serial.println(" => Bright");
} else {
Serial.println(" => Very bright");
}
}