const int sensorPin = A0; // Analog pin connected to the light sensor
const int relayPin = 8; // Digital pin connected to the relay module
const int threshold = 500; // Threshold for light intensity (adjust as needed)
void setup() {
pinMode(sensorPin, INPUT);
pinMode(relayPin, OUTPUT);
}
void loop() {
int sensorValue = analogRead(sensorPin);
// If it's dark (low sensor value), turn on the garden lights
if (sensorValue > threshold) {
digitalWrite(relayPin, HIGH); // Turn on the relay
} else {
// If it's bright, turn off the garden lights
digitalWrite(relayPin, LOW); // Turn off the relay
}
delay(100); // Delay for stability
}