Careers 9: Code
Copy and Paste the Code below:
int ldrPin = A0;
int ledPin = 3;
int threshold = 500; // You may need to adjust this
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int ldrValue = analogRead(ldrPin);
Serial.println(ldrValue); // For debugging
if (ldrValue < threshold) {
digitalWrite(ledPin, HIGH); // Turn on LED
} else {
digitalWrite(ledPin, LOW); // Turn off LED
}
delay(200);
}