#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL6IJ2_rR6c"
#define BLYNK_TEMPLATE_NAME "TA01"
#define BLYNK_AUTH_TOKEN "qSxJiUytrmHPXzARpFd3kXNaiT6ybkfM"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHTesp.h>
#include <DHTesp.h>
const int DHT_PIN = 15;
DHTesp dhtSensor;
const float GAMMA = 0.7;
const float RL10 = 50;
const int relay1=5;//tambahan
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
void sendSensor()
{
int analogValue = analogRead(35);
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(V13, lux);
//koding sensor temperatur dan kelembapan
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.println("---");
Blynk.virtualWrite(V0, data.temperature);
Blynk.virtualWrite(V4, data.humidity);
}
void setup() {
pinMode(relay1, OUTPUT);//tambahan
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
Blynk.begin(auth,ssid,pass);
timer.setInterval(1L, sendSensor);
}
void loop()
{
//sendSensor(); tidak perlu karena sudah kirimkan di void setup
Blynk.run();
timer.run();
float suhu = dhtSensor.getTemperature();//tambahan
if (suhu > 25){//tambahan
digitalWrite(relay1, HIGH);//tambahan
delay(1000);//tambahan
}else {//tambahan
digitalWrite(relay1, LOW);//tambahan
delay(1000);//tambahan
}
}
//lux = (RL10 x 1000 x 10^0.7 / resistansi) ^1/0.7