Help with millis and ldr

Hi again, i connect my 5110 lcd screens bl pin to pin 8 of arduino nano. and now control it with ldr which is connected to pin a1.

Just use basic code because i am noob at this for now.

if (ldr > 400) {
digitalWrite(led, LOW);
}

if (isik < 400) {
digitalWrite(led, HIGH);
}

I want to use millis here because dont want to instant turn on and off backlight. If i use delay, reading from temp sensor is interrupted. But i am confused about how to use basicly millis on here. I want backlight turn on when readings below 400 and wait 5 seconds before turn off when readings goes up.
I dont understand how to use it. Please help me understand. Thank you.

Did you look at File|Examples|02.Digital|BlinkWIthoutDelay for an example of using millis()?

There are many resources about millis() on this site, use the search box.

As you don’t want anything to happen during that time , delay is ok….

( I’ll get my coat)

1 Like

Have you tried adding some deadband?

if (ldr > 425 {
digitalWrite(led, LOW);
}

else if (isik < 375) {
digitalWrite(led, HIGH);
}
1 Like
if ldr > 400
{
  if backlight is off
  {
    backlight on
    timeStamp = now
  }
}
else if backlight is on and (now - timeStamp > 5 seconds)
{
  backlight off
}
1 Like

Yes, this is a small mistake, it should be
if ldr <= 400

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.