const int ldrPin = A0; // Analog pin for the LDR sensor
const int ledPin = 13; // LED connected to pin 13
const int buzzerPin = 9; // Buzzer connected to pin 9
void setup() {
Serial.begin(9600);
pinMode(ldrPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
int ldrValue = analogRead(ldrPin);
// Print the LDR value to the serial monitor
Serial.print("LDR Value: ");
Serial.println(ldrValue);
// Check if the LDR value is below a threshold (adjust as needed)
if (ldrValue < 300) {
digitalWrite(ledPin, HIGH); // Turn on the LED
tone(buzzerPin, 1000); // Turn on the buzzer
Serial.println("Dark environment detected!");
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
noTone(buzzerPin); // Turn off the buzzer
}
delay(1000); // Delay for readability
}