#define BLYNK_TEMPLATE_ID "TMPL4CHuty37O"
#define BLYNK_TEMPLATE_NAME "Temp Sensor"
#define BLYNK_AUTH_TOKEN "MCbh6A9z_Kyg-aDsVLXJAyy0qkRrm9EJ"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>
#include <DHTesp.h>
#include <map>
// Your WiFi credentials
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
Servo myServo1;
Servo myServo2;
Servo myServo3;
DHTesp dhtSensor;
BlynkTimer timer;
BLYNK_WRITE(V2)
{
// Read the switch state (0 or 1)
int switchState = param.asInt();
Serial.println("State:");
Serial.println(switchState);
// Set the servo angle based on the switch state
int servoAngle = switchState ? 180 : 0;
Serial.println("Angle:");
Serial.println(servoAngle);
// Move the servo to the specified angle
myServo1.write(servoAngle);
myServo2.write(servoAngle);
myServo3.write(servoAngle);
}
BLYNK_CONNECTED()
{
// You can add any Blynk-connected initialization here
}
void myTimerEvent()
{
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.println("---");
// You can send any value at any time.
// Please don't send more than 10 values per second.
Blynk.virtualWrite(V0, data.temperature);
Blynk.virtualWrite(V1, data.humidity);
}
void setup()
{
// Debug console
Serial.begin(115200);
dhtSensor.setup(15, DHTesp::DHT22); // Assuming DHT sensor is connected to pin 15
myServo1.setPeriodHertz(50); // Standard 50 Hz servo
myServo1.attach(18); // Attach the servo to pin 18
myServo2.setPeriodHertz(50);
myServo2.attach(17);
myServo3.setPeriodHertz(50);
myServo3.attach(16);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
while (Blynk.connect() == false)
{
// Wait until connected
}
// Setup a function to be called every 2 seconds
timer.setInterval(2000L, myTimerEvent);
}
void loop()
{
Blynk.run();
timer.run();
}