#include "DHTesp.h"
#define BLYNK_TEMPLATE_ID "TMPL3w0JRYaGj"
#define BLYNK_TEMPLATE_NAME "Home Automation"
#define BLYNK_AUTH_TOKEN "rPHXOBWYaA0Agrs8yNvpTKiVd94ykDAf"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>
#define DHTPIN 15 // Define the GPIO pin connected to the DHT22 sensor.
#define DHTTYPE DHT22
DHTesp dht;
Servo myservo;
int servoPin = 14; // The GPIO pin connected to the servo.
// int motorPin = 15; // The GPIO pin connected to the motor.
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
void setup() {
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
dht.setup(DHTPIN, DHTesp::DHT22);
myservo.attach(servoPin);
// pinMode(motorPin, OUTPUT); // You can remove this line if you are not using a motor
}
void loop() {
Blynk.run();
delay(2000); // Wait a few seconds between measurements.
float humidity = dht.getHumidity();
float temperature = dht.getTemperature();
Blynk.virtualWrite(V3, temperature); // Send temperature data to virtual pin V3
Blynk.virtualWrite(V4, humidity); // Send humidity data to virtual pin V4
// Control the servo based on temperature
if(temperature > 25){
for (int pos = 0; pos <= 180; pos++){
myservo.write(pos);
delay(15);
}
for (int tos = 180; tos >= 0; tos--){
myservo.write(tos);
delay(15);
}
} else {
myservo.write(0); // Rotate the servo to 0 degrees.
}
// Control the DC motor based on humidity
// if (humidity > 60) {
// digitalWrite(motorPin, HIGH); // Turn on the motor.
// } else {
// digitalWrite(motorPin, LOW); // Turn off the motor.
// }
}