I am able to synch my ESP8266 running on Arduino core with the time.nist.gov-Server but how can I achieve to trigger i.e. a digital pin in 2 seconds even? What I mean is that following:

  1. The MC recieves the signal for trigger by the user on 09:25:18:312
  2. It waits until it is exactly 09:25:19:000
  3. It triggers the digital out on +2 seconds, on 09:25:21:000


Edit: Corrected Times.

  • The description isn't clear. Where did time 09:25:18:312 come from? If that's the time the request was issued, step 2 won't work out. Why is step 2 included anyway? Feb 21, 2017 at 21:01
  • Also, the time in step 2 is later than the time in step 1. You can't wait for something in the past, so that confuses it more.
    – Mark Smith
    Feb 22, 2017 at 7:37
  • Sorry that I didn't make that clear. What I meant was, that there is a (fictional) time and I want the ESP to wait for a specific time. I correct the upper values. Sorry! Feb 22, 2017 at 8:28

1 Answer 1


You can, but I think you are probably not looking at the best solution. This link has details of how to program the "OS" timer http://www.switchdoc.com/2015/10/iot-esp8266-timer-tutorial-arduino-ide/ I haven't tried it, I'm not even sure it will work, but...

The fact that setting the timer interval to 2uS causes issues with the WIFI implies that it might not be accurate enough for your purposes. It might be better to use "something" to trigger a HW interrupt. From the moment the interrupt triggers to the moment the signal is sent out on the pin is a calculable finite time, so rather than 2,000,000 uS you want the event to trigger after 1,999,524uS (that's a made up number).

Of course if you are using a device that can trigger a pin on the ESP8266 there is no reason it can't trigger the 'output' pin, without involving the ESP at all.

You could use an RTC DS3221(?), the ESP sets the time on the RTC and then sets the alarm. The alarm interrupt pin is connected to the ESP and it relays the signal to the output, or the alarm interrupt pin is directly connected to the output pin. The limiting factor here is the accuracy you require.

  • Probably yes. Is there a way to synch multiple RTC on different ESPs? As far as I know, the ESP-variant of the time.h library does not include the WiFi-Signal-lag. Feb 22, 2017 at 15:00
  • Have a look at NTP implementation (Network time protocol) if you want to do that, but it might be better to have only one RTC and then calculate the average hop time between the master and slaves. Feb 23, 2017 at 9:12
  • Indeed. the Arduino Core Library Time.h has a functions for synchronising time from an external time source: setSyncProvider(getTimeFunction) and setSyncInterval(interval) See: github.com/PaulStoffregen/Time
    – 6v6gt
    Feb 23, 2017 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.