Source: https://mokxi.com/teachers/plans/clocks-and-time
Updated: 2026-11-19

Lesson plan

# 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.

4 chapters, 7 lessons, about 6 hours, on the Arduino Uno R3. Every lesson runs in the browser, with nothing to install.

Start a class from this course

The unit

## 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.

Chapter 1. About 2 h 30 min

## Counting time

millis() and the clock chips that keep the calendar.

Lesson | Time | What students do

millis() rollover millis() 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

- Run it: five seconds to the wrap
- The wrap
- Yellow goes haywire
- Why subtraction is safe
- Fix the yellow lamp
- Testing what takes 49 days

DS3231 vs DS1307 Inside 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

- Run it: a clock on the bus
- Numbers in BCD
- The clock-halt bit
- How far it drifts
- A better crystal
- Choosing an RTC

The DS1302 on three wires A 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

- Run it: a clock on a display
- Three wires, one of them both ways
- Halted and protected
- RAM that lasts
- Set the time
- When to use a DS1302

### 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".

Chapter 2. About 1 h 40 min

## Wall clock time

Time zones, daylight saving and the network.

Lesson | Time | What students do

Time zones and daylight saving Keep 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

- Run it: UTC in, local time out
- The rules, worked out each year
- Spring forward
- Fall back
- Berlin
- Time zone rules for real products

NTP: time from the network An 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

- Run it: ask the network
- A simulated server
- NTP knows only UTC
- The seconds on a strip
- Another time zone
- NTP and an RTC together

### 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".

Chapter 3. About 50 min

## Alarms

Let the clock chip watch the time.

Lesson | Time | What students do

Alarms and schedules Two 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

- Run it: alarm set
- Two alarms, two flags
- Waking a sleeping board
- A schedule
- Add to the schedule
- Alarms and daylight saving

### 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".

Chapter 4. About 1 h 5 min

## Boss project

A sunrise alarm clock that wakes you with light.

Lesson | Time | What students do

Boss: a sunrise alarm clock Wake 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

- Run it: before dawn
- The sun comes up
- Good morning
- Full sunlight
- Snooze
- Sleep in on weekends
- An earlier alarm
- Make it your clock

### 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".

Your class

## 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.

Start a class from this course See the demo class

More units

## Other lesson plans

Electronics basics 20 lessons, about 10 h. Embedded on the Arduino Uno 16 lessons, about 12 h. Embedded on the ESP32-C3 13 lessons, about 11 h. Embedded on the Raspberry Pi Pico 7 lessons, about 6 h. Build your own fight stick 5 lessons, about 4 h. Embedded on the STM32F411 6 lessons, about 6 h. C++ on a board 13 lessons, about 10 h. Digital logic and memory 4 lessons, about 4 h. Interactive devices on the Uno 9 lessons, about 8 h. From gates to a computer 23 lessons, about 16 h. Build a claw machine 8 lessons, about 6 h. Every unit All the courses as ready-made units, on the teachers page.
