// Define the analog pin where the LDR is connected
const int ldrPin = A0;
// Define the pin where the LED is connected
int red = 13; // Assuming the LED is connected to pin 13
int yellow = 12;
int srlPin = 9;
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Set the LED pin as an output
pinMode(srlPin, OUTPUT);
}
void loop() {
// Read the voltage value from the LDR
int ldrValue = analogRead(ldrPin);
// Print the raw analog value to the serial monitor
int brightness = map(ldrValue, 0, 1023, 0, 255);
// Set the LED brightness using PWM
analogWrite(srlPin, brightness);
Serial.print("LDR Value: ");
Serial.println(ldrValue);
// Turn on the LED if the LDR value is below a certain threshold
/*if (ldrValue < 500) { // Adjust this threshold based on your LDR and lighting conditions
digitalWrite(ledPin, HIGH); // Turn on the LED
digitalWrite(yellow, HIGH);
digitalWrite(green, HIGH);
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
digitalWrite(yellow, LOW);
digitalWrite(green, LOW);
}
*/
// Optional delay to slow down the serial output (for readability)
delay(500);
}