

Serial.print("Setting alarm for date: ") Serial.println("NTP unavailable, using time of build") Rtc.adjust(DateTime(ntp.getEpochTime())) Serial.println("Using time from NTP client") Serial.println("RTC lost power, setting time") Serial.println("Connecting to " WIFI_SSID) apparently can lead to problems if not cleared Serial.println("Hello RTC wake deep sleep") #define SLEEP_SECONDS 10 // easier for testing uncomment to wake up at specific date and time ESP8266 NTP functions (configTime and localtime) TODO: NTPClient is redundant replace with native Make sure you uncomment SLEEP_DT and set a date and time to wake at a specific date and time (of course, you can set this programmatically to any date and time), otherwise it'll wake up every n seconds (value of SLEEP_SECONDS) but that might also be useful (ESP8266 deep sleep time isn't very accurate).
#DEEPSLEEP ALARM CLOCK CODE#
The following code will set an alarm to a specific time, and when the RST pin is pulled low (based on the SQW output of the DS3231), the ESP8266 then wakes up.

This is why this 2nd solution is less energy efficient compared to the 1st solution. That power consumption is significant if you're designing a low power system. The monostable circuit creates a pulse on the RST pin when the DS3231 SQW pin goes low.Ī note on power consumption: The ESP8266 should consume only 20 ♚ in deep sleep, but DS3231 modules actually tend to use about 1 mA when powered on (which is required to trigger the alarm), probably because of the EEPROM on the module. The monostable circuit is important because the RST pin can't stay low, as it won't boot. Using the DS3231, the SQW pin can be connected to the ESP8266 RST pin via a monostable circuit. Solution 2: Set an alarm on the external RTC to wake the MCU This is probably the most energy efficient you can get with wanting to keep accurate time. If restarted with WiFi off ( ESP.deepSleep(1e6, WAKE_RF_DISABLED)), the ESP8266 only needs to wake for about 200 ms consuming 20 mA to check the DS3231 if it's time to wake up fully. Don't forget to turn off the I2C pull-ups too, as they can provide parasite power to the RTC. To save power, before sleeping the ESP8266, you can simply use a transistor connected to GPIO to turn off the Vcc power supply on the DS3231 module (it'll use the onboard 2032 battery while no power is supplied). wake and check the RTC every minute once you're about 10 mins away from the target time). Probably, the most energy efficient solution (compared to using the alarm solution below) would be to wake the ESP8266 from deep sleep periodically to check the time on the external RTC and depending on desired accuracy, deep sleep for shorter periods as you approach the target wake time (e.g. Solution 1: Periodically wake the MCU and check the external RTC The DS3231 "maintains the RTC to within ☒ minutes per year accuracy from -40☌ to +85☌" "The DS3231 is a low-cost, extremely accurate I2C real-time clock (RTC)". The 3rd approach is useful if you don't want to add an external RTC. or more like 4.5V according to the datasheet). For low power, I prefer DS3231 over DS1307, since DS3231 modules seem to work fine at 2.6V (whereas DS1307 modules seem to require at least 3.3V. it's not capable of keeping very accurate time while in deep sleep) and is limited to a short time period, one solution is to use an external RTC (real time clock) but there is a way of doing it without.īelow are 3 approaches, the first two involve a DS3231 RTC (quite easy to get as a module). Since the ESP8266 doesn't have a real onboard RTC (i.e.
