#include <Servo.h>

const int ldrPin = A5;      // Analog pin for LDR sensor
const int servoPin = 6;     // PWM pin for servo motor

Servo myservo;

void setup() {
  myservo.attach(servoPin);
  Serial.begin(9600);  // Optional: Open a serial connection for debugging
}

void loop() {
  int ldrValue = analogRead(ldrPin);

  // Map the LDR value to servo angles based on different light conditions
  int servoAngle;

  if (ldrValue < 300) {
    // Dark condition
    servoAngle = 180;
  } else if (ldrValue < 950) {
    // Medium light condition
    servoAngle = 5;
  } else {
    // Bright condition
    servoAngle = 0;
  }

  // Move the servo to the calculated angle
  myservo.write(servoAngle);

  // Optional: Print LDR value and servo angle to the serial monitor for debugging
  Serial.print("LDR Value: ");
  Serial.print(ldrValue);
  Serial.print(" | Servo Angle: ");
  Serial.println(servoAngle);

  delay(100);  // Optional: Adjust the delay as needed
}