Most of the Arduino projects execute an operation in a cycle where timing is not that critical. The loop() continues to execute and often can report back how many times it was executed, it can wait for a certain time period or simply repeat over and over again to check if the conditions have changed.
However, there are some projects that require a bit more precision if we want to automate a certain action at a specific time. Let say that you want to wake up at 7 AM, so we can instruct an Arduino to open the window blinds and 6:45 AM.
Without a specific time reference, this will be impossible.
And for sure, we can also tell the Arduino that it needs to keep track of the time but what if that Arduino also controls the house lights, monitors the plants in the garden, regulates the temperature in the house, or does a million more other things? Then, the Arduino will spend valuable processing time just keeping track of the time and it might not react fast enough to changing input. And what if the power goes down? Once restored, the Arduino would have lost track of the time so we would need to set it again.
To prevent this from happening, there are certain special-purpose chips, called real-time clocks (RTC) whose sole purpose is to keep track of time.
One such chip is the DS1302 which I recently got and played with a bit.
Make sure to watch the video to learn more about how you can work with RTCs and more specifically with the DS1302 IC. For step-by-step instructions and the code used in the example, check out the Instructable for the project.
Tools and materials used in this video:
- NodeMCU v3 - https://s.click.aliexpress.com/e/_9zsjMa
- DS1302 RTC Module - https://s.click.aliexpress.com/e/_9vbjPg
- Mini Breadboards - https://s.click.aliexpress.com/e/_9vg9cK
- Jumper Wires - https://s.click.aliexpress.com/e/_AZwpjC
- CR2032 Battery - https://s.click.aliexpress.com/e/_9fZL2e