#include <DHTesp.h>
#include <ESP32Servo.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPLcYnzzZ7k"
#define BLYNK_DEVICE_NAME "Chicken Farm"
#define BLYNK_AUTH_TOKEN "GL0GGrCz_OdmlKxnlxbVj8-01U6oAuw0"
#define lamp 19
#define ldr 12
#define dht 13
#define relay 15
#define servo 2
DHTesp DHTku;
Servo servoku;
BlynkTimer timer;
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
const float GAMMA = 0.7;
const float RL10 = 50;
void sendSensor() {
TempAndHumidity data = DHTku.getTempAndHumidity();
int analogValue = analogRead(ldr);
float voltage = analogValue * 5 / 4095.0;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
Blynk.virtualWrite(V0, data.temperature);
Blynk.virtualWrite(V1, data.humidity);
Blynk.virtualWrite(V2, lux);
}
void setup() {
// put your setup code here, to run once:
pinMode(lamp, OUTPUT);
pinMode(relay, OUTPUT);
pinMode(ldr, INPUT);
digitalWrite(lamp, HIGH);
servoku.attach(servo);
DHTku.setup(dht, DHTesp :: DHT22);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1L, sendSensor);
}
void loop() {
// put your main code here, to run repeatedly:
Blynk.run();
timer.run();
}