#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL6Dv30VOBm"
#define BLYNK_TEMPLATE_NAME "praktikum8"
#define BLYNK_AUTH_TOKEN "2fCNU026MPxFq4UxACrq1QDpOVoJTYJ-"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "DHTesp.h"
const int DHT_PIN = 26;
DHTesp dhtSensor;
const float GAMMA = 0.7;
const float RL10 = 50;
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
void sendSensorAndControl()
{
// Read sensor data
int analogValue = analogRead(33);
float voltage = analogValue * 5 / 4095.0;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
Serial.print("Lux : ");
Serial.println(lux);
Blynk.virtualWrite(V0, lux);
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp : " + String(data.temperature, 2) + "°C");
Serial.println("Humidity : " + String(data.humidity, 1) + "%");
Serial.println("---");
Blynk.virtualWrite(V13, data.temperature);
Blynk.virtualWrite(V14, data.humidity);
}
void setup()
{
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, sendSensorAndControl); // Adjust interval as needed
}
void loop()
{
Blynk.run();
timer.run();
sendSensorAndControl();
}