Hello.
Maybe i could get some advices how to improve this code. Working principle should be:
If Value is less than ..., then led should light up and shine for specific time. After that it should turn off.
`
const int ledPin = 4;
int ldr=A0;//Set A0(Analog Input) for LDR.
int value=0;
int ledState = LOW;
unsigned long previousMillis = 0;
const long interval = 2000;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
value=analogRead(ldr);//Reads the Value of LDR(light).
if(value<300 ){
digitalWrite(ledPin, HIGH);
unsigned long currentMillis = millis();
If value is < 300 the light will always be on the way you have it coded. Also if the value is < 300 and then the value is >= 300 the light may not turn off.
It is likely that once the light turns on then it will stay on.
It depends. Do you want the LED to always be on if the value is <300? If not, do you want the LED to turn off after the interval and not turn back on until value is >= 300 and then less than 300 again?