Hello guys, what I'm trying to do is light up a led when it gets dark. I'm fairly certain I have connected everything correctly (example) and I have used the right pins for my code.
When I try to use analogRead I lose control of the led, I can't turn in to HIGH.
Any idea why this happens? I have tried to use delay(), millis() and yield() but with no results.
Both the LED and photoresistor work seperetely.
const int led = 6;
const int ldr = A0;
int ldrStatus = 0;
void setup() {
//Serial.begin(9600);
pinMode(led,OUTPUT);
pinMode(ldr,INPUT);
}
void loop() {
int ldrStatus = analogRead(ldr);
//Serial.println(ldrStatus);
delay(200);
//if (ldrStatus <=500)
//{
digitalWrite(led,HIGH);
// delay(200);
//}
//else
// {
// digitalWrite(led,LOW);
//delay(200);
//}
}
What values do you see when you un-comment this line?
Please, be more descriptive. Do the LEDs adjust with light changes? Do they not change to what you hope? Pro-tip: You do not need to turn your lights off to see the change... you can just cover the LDR.
Normal values depending on the lighting mostly around 200-500 with minimal change if I don't change the lighting.
The LEDs cannot be controlled, for example my commented code should just turn the LED to high but it doesn't work if I don't comment out the analogRead line.