-4
#include <stdio.h>      
#include <time.h>

time_t now;
struct tm *now_tm;
int h,m,s;

void setup(){
    pinMode(D6,OUTPUT);
}

void loop ()
{
    now = time(NULL);
    now_tm = localtime(&now);
    h = now_tm->tm_hour;
    m = now_tm->tm_min;
    s = now_tm->tm_sec;

    if(h == 17 && m == 0 && s==0)
    {
        digitalWrite(D6,HIGH);
        delay(100000);
        digitalWrite(D6,LOW);
    }
}

I don't know why my LED on pin D6 won't turn on when it's 17:00:00

I tried check it with other IF condition and it worked fine

I count the hour, the minute and the second on visual and they showed the right value

barbsan
  • 3,418
  • 11
  • 21
  • 28

1 Answers1

0

In order for your code to work, you need to have some type of external clock (arduino doesn't know what time it is) e.g. DS3231. You can find tutorial about it here: https://howtomechatronics.com/tutorials/arduino/arduino-ds3231-real-time-clock-tutorial/