Clocks, RTCs and time lesson plan
Keep real time: millis() rollover tested in seconds, the DS1307, DS3231 and DS1302 clocks, time zones and the US and EU daylight saving rules, NTP on an ESP32-C3, alarms and schedules, and a sunrise alarm clock.
Objectives and materials
By the end, students can
- millis() and the clock chips that keep the calendar.
- Time zones, daylight saving and the network.
- Let the clock chip watch the time.
- A sunrise alarm clock that wakes you with light.
Materials for the whole unit
- Addressable RGB LEDs
- Arduino Uno R3
- Character LCD with I2C backpack
- ESP32-C3-DevKitM-1
- Four-digit display, TM1637
- Full-size breadboard
- Half breadboard
- I2C EEPROM, 24LC256
- LED x 3
- Logic analyzer, four channels
- Piezo speaker
- Potentiometer
- Pushbutton
- Real-time clock, DS1302
- Real-time clock, DS1307
- Real-time clock, DS3231
- Resistor x 3
Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.
Counting time
millis() and the clock chips that keep the calendar.
| Lesson | Time | What students do |
|---|---|---|
| millis() rollovermillis() is a 32-bit count that wraps to 0 after 49.7 days: a clock that starts five seconds before the wrap, a blinker that survives it with subtraction, and one that goes haywire. | 50 min |
|
| DS3231 vs DS1307Inside a DS1307: a 32.768 kHz crystal, seven BCD registers, the clock-halt bit and a coin cell, and why the DS3231 drifts ten times less. | 50 min |
|
| The DS1302 on three wiresA DS1302 on its own three-wire bus: CE, a clock and one data line both ways, write-protect and halt bits, 31 bytes of battery-backed RAM, and setting the time. | 50 min |
|
Materials
- Arduino Uno R3
- Character LCD with I2C backpack
- Four-digit display, TM1637
- Full-size breadboard
- Half breadboard
- I2C EEPROM, 24LC256
- LED x 3
- Piezo speaker
- Potentiometer
- Pushbutton
- Real-time clock, DS1302
- Real-time clock, DS1307
- Resistor x 3
Check for understanding
Each student finishes "The DS1302 on three wires" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "When to use a DS1302".
Wall clock time
Time zones, daylight saving and the network.
| Lesson | Time | What students do |
|---|---|---|
| Time zones and daylight savingKeep UTC on the RTC and show local time: a zone offset, the US and EU daylight saving rules worked out for any year, and the hour that is skipped in spring and repeated in the fall. | 50 min |
|
| NTP: time from the networkAn ESP32-C3 asks an NTP server for the time: Unix time in UTC, an offset added by the sketch, a resync interval, and the seconds of the minute running around a strip. | 50 min |
|
Materials
- Addressable RGB LEDs
- Arduino Uno R3
- ESP32-C3-DevKitM-1
- Four-digit display, TM1637
- Full-size breadboard
- Half breadboard
- Logic analyzer, four channels
- Real-time clock, DS3231
Check for understanding
Each student finishes "NTP: time from the network" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "NTP and an RTC together".
Alarms
Let the clock chip watch the time.
| Lesson | Time | What students do |
|---|---|---|
| Alarms and schedulesTwo DS3231 hardware alarms, one at a set time and one every minute, flags that wait to be read, and a daily schedule table checked against the clock. | 50 min |
|
Materials
- Arduino Uno R3
- Four-digit display, TM1637
- Half breadboard
- Logic analyzer, four channels
- Real-time clock, DS3231
Check for understanding
Each student finishes "Alarms and schedules" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Alarms and daylight saving".
Boss project
A sunrise alarm clock that wakes you with light.
| Lesson | Time | What students do |
|---|---|---|
| Boss: a sunrise alarm clockWake up to light: a DS3231 in UTC, New York time with daylight saving on a TM1637, a 16 LED ring that rises from deep red to warm white before the alarm, weekdays only, and a snooze. | 65 min |
|
Materials
- Addressable RGB LEDs
- Arduino Uno R3
- Four-digit display, TM1637
- Half breadboard
- Real-time clock, DS3231
- Resistor
Check for understanding
Each student finishes "Boss: a sunrise alarm clock" on their own, without opening the hints. The simulator checks 8 of its 8 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make it your clock".
Teach this unit as a class
Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.
The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.