// Define the pins for LDR and relay module
const int ldrPin = A0; // Analog pin for LDR module
const int relayPin = 7; // Digital pin for relay module control
void setup() {
// Initialize the serial communication for debugging
Serial.begin(9600);
// Set relayPin as OUTPUT
pinMode(relayPin, OUTPUT);
}
void loop() {
// Read the analog value from the LDR
int ldrValue = analogRead(ldrPin);
// Print the LDR value for debugging
Serial.print("LDR Value: ");
Serial.println(ldrValue);
// Check the LDR value to determine if it's dark or light
// You may need to adjust the threshold value based on your environment
if (ldrValue < 500) { // Adjust the threshold value as needed
// If it's dark, activate the relay
digitalWrite(relayPin, HIGH);
Serial.println("It's dark. Turning on the streetlight.");
} else {
// If it's light, deactivate the relay
digitalWrite(relayPin, LOW);
Serial.println("It's light. Turning off the streetlight.");
}
// Delay for a short duration to avoid rapid reading
delay(1000); // Adjust delay time as needed
}