Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32C3-Based LED Clock with RTC and MAX7219 Display

View and Edit Project In Cirkit DesignerImage of ESP32C3-Based LED Clock with RTC and MAX7219 Display

Circuit Documentation

Summary

This circuit is designed to function as a digital clock using an ESP32 microcontroller, a DS3231 RTC module, and two MAX7219 LED drivers. The circuit also includes multiple LEDs to display the time. The ESP32 microcontroller communicates with the DS3231 RTC module via I2C to get the current time and controls the MAX7219 LED drivers to display the time on the LEDs.

Component List

  1. XIAO ESP32C3

    • Description: Microcontroller
    • Pins: GPIO2/A0/D0, GPIO3/A1/D1, GPIO4/A2/D2, GPIO5/A3/D3, GPIO6/SDA/D4, GPIO7/SCL/D5, GPIO21/Tx/D6, 5V, GND, 3V3, GPIO10/MOSI/D10, GPIO9/MISO/D9, GPIO8/SCK/D8, GPIO20/Rx/D7
  2. DS3231 RTC

    • Description: Real-Time Clock Module
    • Pins: 32K, SQW, SCL, SDA, VCC, GND
  3. MAX7219

    • Description: LED Driver
    • Pins: DOUT, SEG D, SEG DP, SEG E, SEG C, V+, ISET, SEG G, SEG B, SEG F, SEG A, CLK, LOAD(CSn), DIG 1, DIG 5, GND, DIG 7, DIG 3, DIG 2, DIG 6, DIG 4, DIG 0, DIN
  4. LED: Two Pin (red)

    • Description: Red LED
    • Pins: cathode, anode
  5. LED: Two Pin (green)

    • Description: Green LED
    • Pins: cathode, anode

Wiring Details

XIAO ESP32C3

DS3231 RTC

MAX7219 (First Instance)

MAX7219 (Second Instance)

LED: Two Pin (red)

LED: Two Pin (green)

Code Documentation

#include <Wire.h>
#include <RTClib.h>
#include <LedControl.h>

// Initialize RTC
RTC_DS3231 rtc;

// Initialize MAX7219
LedControl lc = LedControl(10, 8, 9, 2); // DIN, CLK, LOAD, number of devices

void setup() {
  // Initialize I2C communication
  Wire.begin();
  
  // Initialize RTC
  rtc.begin();
  
  // Initialize MAX7219
  for (int i = 0; i < 2; i++) {
    lc.shutdown(i, false);
    lc.setIntensity(i, 8);
    lc.clearDisplay(i);
  }
}

void loop() {
  // Get the current time
  DateTime now = rtc.now();
  
  int minute = now.minute();
  int hour = now.hour() % 12; // Convert 24-hour format to 12-hour format
  
  // Clear previous display
  lc.clearDisplay(0);
  lc.clearDisplay(1);
  
  // Light up the minute LED on the first MAX7219
  lc.setLed(0, minute / 8, minute % 8, true);
  
  // Light up the hour LED on the second MAX7219
  lc.setLed(1, hour / 8, hour % 8, true);
  
  delay(1000); // Update every second
}

This code initializes the RTC and MAX7219 LED drivers, retrieves the current time from the RTC, and updates the LEDs to display the current hour and minute. The display is updated every second.