#define BLYNK_TEMPLATE_ID "TMPL6oTw0EEtr"
#define BLYNK_TEMPLATE_NAME "Jemuran Pintar"
#define BLYNK_AUTH_TOKEN "Qx5ExQcZyVnYPYpVOjRJPHeOrI77V1sM"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>
#define PHOTO_SENSOR_PIN 35
#define POTENTIOMETER_PIN 34
#define SERVO_PIN 25
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST"; // Enter your WIFI name
char pass[] = ""; // Enter your WIFI password
Servo servoMotor;
int ldrSensor = 34; // Pin analog untuk sensor hujan
void setup() {
Serial.begin(115200);
delay(100);
servoMotor.attach(SERVO_PIN);
pinMode(PHOTO_SENSOR_PIN, INPUT);
pinMode(POTENTIOMETER_PIN, INPUT);
pinMode(ldrSensor, INPUT);
Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
}
void loop() {
int lightIntensity = analogRead(PHOTO_SENSOR_PIN);
int humidityLevel = analogRead(POTENTIOMETER_PIN);
// Map sensor values to servo angle
int servoAngle = map(lightIntensity, 0, 1023, 0, 180);
int humidityThreshold = map(humidityLevel, 0, 1023, 0, 100);
// Adjust servo position based on light intensity
if (humidityThreshold < 50) { // If humidity is below 50%, adjust the servo
servoMotor.write(servoAngle);
delay(1000); // Delay for servo movement
} else {
// If humidity is too high, stop the servo
servoMotor.write(0); // Assuming 0 degree is a position where the clothesline is closed
}
delay(100); // Adjust delay as needed for responsiveness
int ldrLevel = analogRead(ldrSensor);
int mappedLDR = map(ldrLevel, 0, 1023, 0, 255); // Map analog reading to virtual pin range
Blynk.virtualWrite(V34, mappedLDR); // Write mapped value to virtual pin 34
Serial.print("Test Level: ");
Serial.println(ldrLevel);
delay(1000); // Delay untuk menghindari pembacaan yang terlalu cepat
Blynk.run();
}