#include <ESP32Servo.h>
const int servoPin = 27; // GPIO pin connected to the servo signal
const int ldrPin = 34; // GPIO pin connected to the LDR
Servo myservo; // Create a Servo object
void setup() {
Serial.begin(115200);
myservo.attach(servoPin); // Attach the servo to the specified pin
}
void loop() {
int ldrValue = analogRead(ldrPin); // Read the LDR value (0 to 409)
Serial.print("LDR Value: ");
Serial.println(ldrValue);
// Map the LDR value to a servo angle (0 to 180 degrees)
int servoAngle = map(ldrValue, 0, 409, 0, 180);
myservo.write(servoAngle); // Set the servo position
delay(100); // Wait for the servo to reach the position
}