const int LDRPin = 34; // ldr connected to analog pin a0
const int LED1Pin = 12;
const int LED2Pin = 13; // led connected to digital pin 13
const int LED3Pin = 14;
const int LED4Pin = 32;
//int threshold; // threshold value for light level(adjust as needed)
void setup(){
pinMode(LDRPin, INPUT); //set ldr pin as input
pinMode(LED1Pin, OUTPUT); // set led pin as output
pinMode(LED2Pin, OUTPUT);
pinMode(LED3Pin, OUTPUT);
pinMode(LED4Pin, OUTPUT);
Serial.begin(9600); // initialize serial communication for debugging
}
void loop(){
int LDRValue = analogRead(LDRPin); // read the value from the ldr
Serial.println(LDRValue); // print the ldr value to the serial monitor
//int brightness = map(LDRValue,0,4095,0,255); /// map to the led brightness
if(LDRValue < 1000){
// if the light level is below the threshold, turn on the led
digitalWrite(LED1Pin, HIGH);
digitalWrite(LED2Pin, HIGH);
digitalWrite(LED3Pin, HIGH);
digitalWrite(LED4Pin, HIGH);
delay(1000);
}
else if(LDRValue<2000){
// if the light level is above the threshold, turn off the led
digitalWrite(LED1Pin, LOW);
digitalWrite(LED2Pin, HIGH);
digitalWrite(LED3Pin, HIGH);
digitalWrite(LED4Pin, HIGH);
delay(1000);
}
else if(LDRValue<3000){
digitalWrite(LED1Pin, LOW);
digitalWrite(LED2Pin, LOW);
digitalWrite(LED3Pin, HIGH);
digitalWrite(LED4Pin, HIGH);
delay(1000);
}
else if(LDRValue<4000){
digitalWrite(LED1Pin, LOW);
digitalWrite(LED2Pin, LOW);
digitalWrite(LED3Pin, LOW);
digitalWrite(LED4Pin, HIGH);
delay(1000);
}
delay(100); // small delay for stability
}