Week 9 ยท Integration & Task C

Session 42: Real-time clock and fixed-width text

Teach & build120 minLesson 26: DS1307 RTC & Formatted Text

Learning outcomes

  • Share one I2C bus between the RTC and the LCD
  • Set the RTC once and read hours, minutes and seconds
  • Show the date and time with snprintf padding
  • Explain why millis() is not a wall clock

Kit and components

  • Uno, DS1307 RTC module with backup cell, I2C LCD, breadboard

Pre-reading about 20 min

Students read these on their phones before class. They are listed on the student Before class page.

  1. Lesson 26: millis is not a wall clock
  2. Lesson 26: Set time only when needed
  3. Lesson 26: Fixed-width text with snprintf

Session plan

  1. 0:0010 min
    Recap

    Quiz: DHT11

  2. 0:1020 min
    Demo

    Setting the time safely

    Set the RTC from the compile time once, then comment the line out and re-upload so a reset does not overwrite the clock.

  3. 0:3040 min
    Build

    Clock on the LCD

    Students run the worked sketch, then show HH:MM:SS on row 1 and DD/MM/YYYY on row 2 using their formatDate() function.

  4. 1:1035 min
  5. 1:4515 min
    Wrap-up

    Power off, power on

    Unplug the Uno for a minute and confirm the RTC kept time.

Checkpoint: ready to move on?

Students' LCD shows the correct time and date from the RTC, and it survives a power cycle.

Extension for fast finishers

Start the clock and alarm capstone (extension lesson) with an alarm time and a buzzer.

Catch-up path

Show the time on Serial before moving it to the LCD.

Homework and practice

Read the Task C brief and draft success criteria for each subsystem.

Facilitator notes

  • A sketch that sets the RTC on every start-up resets the clock on every reset - the lesson's Set time only when needed section explains the fix.