#include <Servo.h>

const int ldrPin1 = A0;   // Pin connected to the LDR
const int carrelay = 13;   // Pin connected to the LED

Servo hornservo;

void setup() {
  pinMode(carrelay, OUTPUT);
  Serial.begin(9600);
  hornservo.attach(9);
}

void loop() {
  int lightIntensity = analogRead(ldrPin1);
  Serial.println(lightIntensity);  // Print the light intensity value (optional)

  if (lightIntensity > 500) {     // You can adjust this threshold value
    digitalWrite(carrelay, HIGH);
    delay(12000);
    hornservo.write(0);  // Turn off the servo
    delay(500);
    hornservo.write(180);  // Turn on the servo
    delay(900);
    hornservo.write(0);  // Turn off the servo
    delay(500);
    Serial.println("Light detected on LDR1");
  } else {
    digitalWrite(carrelay, LOW);
    hornservo.write(0); // Turn off the servo
  }

  delay(1000);  // Delay for stability
}
