//I Made Satria Mahawira 20220801213
//Eric Pratama 20220801011
//vigo prisandy yudha 20220801192
//Ramadhan Linggar Karan 20220801013
#define BLYNK_TEMPLATE_ID "TMPL6zv84TbB9"
#define BLYNK_TEMPLATE_NAME "ESP32 DHT22 Lampu"
#define BLYNK_AUTH_TOKEN "72pZT5nBfEATttH2dSOpIBGA7kibCLF3"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <DHT.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST"; //nama hotspot yang digunakan
char pass[] = ""; //password hotspot yang digunakan
#define DHTPIN 2 // Mention the digital pin where you connected
#define DHTTYPE DHT22 // DHT 11
#define LED_PIN_1 12 // Pin LED 1
#define LED_PIN_2 13 // Pin LED 2
#define LED_PIN_3 14 // Pin LED 3
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
bool ledState1 = false;
bool ledState2 = false;
bool ledState3 = false;
BLYNK_WRITE(V2) { // Handle the virtual button state change for LED 1 On/Off
ledState1 = param.asInt();
digitalWrite(LED_PIN_1, ledState1 ? HIGH : LOW); // Set the LED 1 state based on the button state
}
BLYNK_WRITE(V3) { // Handle the virtual button state change for LED 2 On/Off
ledState2 = param.asInt();
digitalWrite(LED_PIN_2, ledState2 ? HIGH : LOW); // Set the LED 2 state based on the button state
}
BLYNK_WRITE(V4) { // Handle the virtual button state change for LED 3 On/Off
ledState3 = param.asInt();
digitalWrite(LED_PIN_3, ledState3 ? HIGH : LOW); // Set the LED 3 state based on the button state
}
void setup(){
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
dht.begin();
timer.setInterval(2500L, sendSensor);
pinMode(LED_PIN_1, OUTPUT); // Set LED 1 pin as output
pinMode(LED_PIN_2, OUTPUT); // Set LED 2 pin as output
pinMode(LED_PIN_3, OUTPUT); // Set LED 3 pin as output
}
void loop(){
Blynk.run();
timer.run();
}
void sendSensor(){
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V1, h);
Blynk.virtualWrite(V0, t);
Serial.print("Temperature : ");
Serial.print(t);
Serial.print(" Humidity : ");
Serial.println(h);
if(t > 30){
Blynk.logEvent("temp_alert","Temp above 30 degrees");
}
}
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4