# ESP8266 with DS3231 RTC

**URL:** <https://forum.arduino.cc/t/esp8266-with-ds3231-rtc/539317>\
**Category:** Programming\
**Created:** [July 31, 2018, 4:36pm UTC](https://forum.arduino.cc/t/esp8266-with-ds3231-rtc/539317 "2018-07-31T16:36:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mr\_boris](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mr\_boris](https://forum.arduino.cc/u/mr_boris)\
**Post date:** [July 31, 2018, 4:36pm UTC](https://forum.arduino.cc/t/esp8266-with-ds3231-rtc/539317/1 "2018-07-31T16:36:00Z")

</div>

Hi, I want to use RTC with my ESP8266 for water pump.

After looking at this [library](https://github.com/Makuna/Rtc) examples I started to thinking not to deal with RTC 😕

Is there any other more convenient libraries or may be simple way to set rtc time and then sat an alarm?

I thought it can be done in a few lines of code but not in 100+ lines :o

Just want to trigger custom function once a day..

Any advice will be appreciated!

---

<div class="post-metadata">

**Author:** ![pylon](https://avatars.discourse-cdn.com/v4/letter/p/59ef9b/32.png) [@pylon](https://forum.arduino.cc/u/pylon)\
**Post date:** [August 2, 2018, 3:14pm UTC](https://forum.arduino.cc/t/esp8266-with-ds3231-rtc/539317/2 "2018-08-02T15:14:37Z")

</div>

> Just want to trigger custom function once a day..

You don't need an RTC for this. Just using millis() should be sufficient for the task.

> I thought it can be done in a few lines of code but not in 100+ lines

It could be but examples are not made to be as compact code as possible but as informative as possible (at least they should be).

---

<div class="post-metadata">

**Author:** ![Riva](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/riva/32/1013044_2.png) [@Riva](https://forum.arduino.cc/u/Riva)\
**Post date:** [August 3, 2018, 10:01am UTC](https://forum.arduino.cc/t/esp8266-with-ds3231-rtc/539317/3 "2018-08-03T10:01:07Z")

</div>

Is the ESP8266 connected to WiFi & the internet?  
If it is then you could use NTP code to get the date/time from the internet every so often to synchronise an internal clock.

---

<div class="post-metadata">

**Author:** ![surepic](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@surepic](https://forum.arduino.cc/u/surepic)\
**Post date:** [August 3, 2018, 11:55am UTC](https://forum.arduino.cc/t/esp8266-with-ds3231-rtc/539317/4 "2018-08-03T11:55:50Z")

</div>

@Riva thats not a good solution. What if there will be internet outage at some point.  
Im using ntp request in my codes but am not relying on it because of possible outage. Better to use millis or rtc.

---

<div class="post-metadata">

**Author:** ![pylon](https://avatars.discourse-cdn.com/v4/letter/p/59ef9b/32.png) [@pylon](https://forum.arduino.cc/u/pylon)\
**Post date:** [August 3, 2018, 4:32pm UTC](https://forum.arduino.cc/t/esp8266-with-ds3231-rtc/539317/5 "2018-08-03T16:32:26Z")

</div>

> surepic:  
> @Riva thats not a good solution. What if there will be internet outage at some point.  
> Im using ntp request in my codes but am not relying on it because of possible outage. Better to use millis or rtc.

You could use millis() and from time to time synchronize using NTP if you have connection. The question is: Is the time really needed or is it sufficient to trigger that function once a day?

---

<div class="post-metadata">

**Author:** ![surepic](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@surepic](https://forum.arduino.cc/u/surepic)\
**Post date:** [August 3, 2018, 11:17pm UTC](https://forum.arduino.cc/t/esp8266-with-ds3231-rtc/539317/6 "2018-08-03T23:17:55Z")

</div>

That also depends how exact you need time. If via at command then for every ntp request timezone must be set then request sent to time server then wait for response and parse received ascii data back. So correction of time will be needed by calculating how long is taking response i think its about a second or 2 seconds.  
But via rtc its fastest.

---

<div class="post-metadata">

**Author:** ![Wawa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wawa/32/1211303_2.png) [@Wawa](https://forum.arduino.cc/u/Wawa)\
**Post date:** [August 4, 2018, 4:27am UTC](https://forum.arduino.cc/t/esp8266-with-ds3231-rtc/539317/7 "2018-08-04T04:27:41Z")

</div>

> surepic:  
> @Riva thats not a good solution. What if there will be internet outage at some point.  
> Im using ntp request in my codes but am not relying on it because of possible outage. Better to use millis or rtc.

A 'time' program running on the ESP8266 is AFAIK always using millis().  
It only gets synchronised with an internet time server when you want it to (code).

That could be once an hour, or once a day, or not at all if internet isn't available.  
You need ofcourse to synchronise on bootup, after ESP power loss.

I run some of my ESP (WemosD1 mini) projects with NTP on a powerbank under constant charge,  
so I never have a power cut (~36hours on a 5Ah powerbank).  
Leo..

---

<div class="post-metadata">

**Author:** ![surepic](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@surepic](https://forum.arduino.cc/u/surepic)\
**Post date:** [August 4, 2018, 12:00pm UTC](https://forum.arduino.cc/t/esp8266-with-ds3231-rtc/539317/8 "2018-08-04T12:00:37Z")

</div>

Im using at firmare and request to ntp server is being sent every time i ask for time. So dont think its using millis().

Easy check will be disconnect from internet and request time.  
Connect to internet get time then switch off your router do same thing agaib you will see that time is going to default 1970year.

---

<div class="post-metadata">

**Author:** ![Riva](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/riva/32/1013044_2.png) [@Riva](https://forum.arduino.cc/u/Riva)\
**Post date:** [August 4, 2018, 4:56pm UTC](https://forum.arduino.cc/t/esp8266-with-ds3231-rtc/539317/9 "2018-08-04T16:56:36Z")

</div>

Use something like the [Time library](https://playground.arduino.cc/Code/Time) to supply RTC like time to your sketch. It uses millis() to keep time but it can be periodically synchronized to a real time source like an RTC, NTP, GPS.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 11:18pm UTC](https://forum.arduino.cc/t/esp8266-with-ds3231-rtc/539317/10 "2021-05-05T23:18:43Z")

</div>

Closed on May 5, 2021, 11:18pm UTC


