Hello,
I just built a light detector, that basically turns on an LED when it's dark.
It worked completely fine, until I changed the light parameter, and now LED won't turn on, when it should (even after changing it back to the original).
When looking at the serial monitor, the program is doing exactly what it's supposed to, but the LED just doesn't work.
I've tried troubleshooting most, if not all the parts, yet nothing works.
Here is the code:
const int lightSensorPin = A0;
const int lightPin = 8;
void setup() {
Serial.begin(9600);
}
void loop() {
int lightSensorReading = 0;
lightSensorReading = analogRead(lightSensorPin);
Serial.println(lightSensorReading);
delay(100);
if(lightSensorReading < 20){
Serial.print("It is dark.");
digitalWrite(lightPin,HIGH);
}
else {
Serial.print("It is light.");
digitalWrite(lightPin,LOW);
}
}
and the schematic:
Does anyone know what's wrong?
Thank you,
Mads