I am going to make a project that needs four boards of Arduino which synchronization in time is needed. The project is about capturing the timestamp (in ms resolution) whenever something is crossing ultrasonic proximity sensor. The following are the modules I am going to use:

  1. Arduino Uno R3 4 units
  2. Ultrasonic Proximity sensor 4 units
  3. DS1302 RTC modules 4 units
  4. Micro SD Card modules 4 units

The boards will be placed in 4 different places which it is quite far from each other that makes it is hard to make wired connection. The detecting object will move back and forth during a certain interval of time, so that is why the time synchronization is needed.

My idea is, by using the timestamp from RTC modules, I turn all the boards together into deep sleep mode at the time I have set in the code and wake them up together after 10 seconds. I don't have any problem with RTC modules, but my problem lies in the millis() function which did not back to zero after woke up from deep sleep mode. I need this function since the DS1302 RTC does not provide ms resolution, yet I can not achieve sync if the millis() function does not back to zero.

I tried the code (edited with millis() added in the loop) from here: https://www.youtube.com/watch?v=8fiYvnBDsDE

Do you have any solutions? Or another RTC module which provides ms resolution instead. Thank you

  • 2
    why are not able to treat the millis() value, at wake time, as the zero reference point?
    – jsotola
    Commented Jun 23, 2019 at 17:13
  • 2
    I don't actually think that millis() is supposed to be reset on a wakeup...
    – Sim Son
    Commented Jun 23, 2019 at 18:18
  • 1
    This looks like an XY problem. X: you need to synchronize the times, Y: you want to reset millis(). Commented Jun 23, 2019 at 18:20
  • I can not achieve sync if the millis() function does not back to zero ... change your code so that it does not require millis() to be reset
    – jsotola
    Commented Jun 23, 2019 at 20:04
  • You should read edgar's reference to the XY problem. Although it sounds like it might relate to tracking an object in two dimensions. It is actually talking about something else.
    – GMc
    Commented Jun 23, 2019 at 22:26

2 Answers 2


Store millis() at boot, and if (resetCause == "Deep-Sleep Wake") zero out the stored copy of millis().


I do not understand how you will get them to sync with each other. The RTC modules work great but there is no communications to set or update them and they do drift. With the RTC it will be easy to generate a timestamp using Unix time. There is a lot of information posted on how to do this. syncing (making all the clocks the same) is where I believe your problem is. Consider adding WiFi to each and use NTP to sync everything, it would be automatic.

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.