// Define the pin numbers
const int redLEDPin = 2;
const int greenLEDPin = 3;
const int photoresistorPin = A0;
// Define the light level thresholds
const int semiDarkThreshold = 500; // Adjust this value based on your environment
const int veryDarkThreshold = 300; // Adjust this value based on your environment
void setup() {
// Initialize the LED pins as outputs
pinMode(redLEDPin, OUTPUT);
pinMode(greenLEDPin, OUTPUT);
// Initialize serial communication for debugging
Serial.begin(9600);
}
void loop() {
// Read the light level from the photoresistor
int lightLevel = analogRead(photoresistorPin);
// Print the light level to the serial monitor
Serial.println(lightLevel);
// Check the light level and turn on LEDs accordingly
if (lightLevel < veryDarkThreshold) {
// If it's very dark, turn on both LEDs
digitalWrite(redLEDPin, HIGH);
digitalWrite(greenLEDPin, HIGH);
} else if (lightLevel < semiDarkThreshold) {
// If it's semi-dark, turn on only the red LED
digitalWrite(redLEDPin, HIGH);
digitalWrite(greenLEDPin, LOW);
} else {
// If it's not dark, turn off both LEDs
digitalWrite(redLEDPin, LOW);
digitalWrite(greenLEDPin, LOW);
}
// Wait for a short period before reading the light level again
delay(200);
}