The objective of this project is to create a digital clock system using the ESP8266 NodeMCU microcontroller, a DS1302 Real-Time Clock (RTC) module, and an LCD I2C display. The system is designed to display the current time and date accurately and continuously. The RTC module, developed by Maxim Integrated, maintains precise timekeeping even when the main power is turned off, thanks to its backup battery. The ESP8266 NodeMCU, produced by Espressif Systems, serves as the main controller that manages communication between the RTC module and the display.
The functioning of the project is based on reading, processing, and displaying real-time data. The DS1302 RTC module continuously keeps track of the current time and date. The ESP8266 NodeMCU reads this information through its digital pins, formats it into a readable form, and sends it to the LCD I2C display. The display then shows the time and date clearly for the user. This process repeats continuously, ensuring that the displayed information remains accurate and updated in real time.
1. ESP8266 NodeMCU

The ESP8266 NodeMCU is a microcontroller. It acts as the main controller of the project. Its role is to communicate with the DS1302 RTC module to read the current time and date, process the data, and send it to the LCD I2C display.
2. DS1302 RTC Module

The DS1302 is a Real-Time Clock (RTC) module used to keep track of the current time and date. It can maintain accurate time even when the ESP82866 is powered off because it uses a backup battery. It provides information such as year, month, day, hour, minute, and second. The ESP8266 reads this data through digital communication pins.
5. LCD Display with I2C Module

The LCD I2C display is used to show the date and time to the user. It uses the I2C communication protocol, which requires only two wires (SDA and SCL), making connections simpler. The display can show text such as the day, date, and current time in real time.
6. Breadboard

A breadboard is a reusable prototyping board used to build and test electronic circuits without soldering. It allows you to easily connect components such as the ESP8266 NodeMCU, DS1302 RTC module and LCD I2C display.
7. Jumper Wires

Jumper wires are used to connect the ESP32 to the RTC module and the LCD display. They allow electrical signals and power to flow between the components.


1- Connection of DS1302 RTC Module to ESP8266
| DS1302 RTC | ESP8266 NodeMCU |
|---|---|
| CLK | D5 (GPIO 14) |
| DAT | D6 (GPIO 12) |
| RST | D7 (GPIO 14) |
| VCC | 3V |
| GND | GND |
2- Connection of LCD I2C display to ESP8266
| LCD display | ESP8266 NodeMCU |
|---|---|
| VCC | VIN |
| GND | GND |
| SDA | D2 (GPIO4) |
| SCL | D1 (GPIO5) |
This program is designed to create a digital clock system using the ESP8266 NodeMCU, a DS1302 RTC Module, and an LCD I2C Display 20x4. It reads the current date and time from the RTC module and displays them on the LCD screen in real time.
You need to install this libraries :
i2c_lcd et lcd_api for I2C LCD screen
ds1302 for DS1302 RTC module
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# Import the Pin class to control GPIO pins # Import SoftI2C for software I2C communication (used with ESP8266) from machine import Pin, SoftI2C # Import the I2C LCD display library from i2c_lcd import I2cLcd # Import the DS1302 RTC module library import ds1302 # Import the time management library import time # ================= LCD I2C CONFIGURATION ================= # I2C address of the LCD display (commonly 0x27 or 0x3F) I2C_ADDR = 0x27 # Number of rows of the LCD display totalRows = 4 # Number of columns of the LCD display totalColumns = 20 # === Initialize I2C Communication === # Create a software I2C object # scl connected to GPIO5 # sda connected to GPIO4 # freq = I2C communication frequency i2c = SoftI2C(scl=Pin(5), sda=Pin(4), freq=10000) # Create the LCD object using I2C parameters lcd = I2cLcd(i2c, I2C_ADDR, totalRows, totalColumns) # Clear the LCD screen at startup lcd.clear() # ================= DS1302 RTC CONFIGURATION ================= # Define the pins connected to the RTC module clk = Pin(14) # CLK pin (clock signal) dat = Pin(12) # DAT pin (data line) rst = Pin(13) # RST pin (reset signal) # Create the RTC object rtc = ds1302.DS1302(clk, dat, rst) # ⚠️ Execute ONLY ONCE, then comment this line # This line sets the initial date and time of the RTC rtc.date_time([2026, 2, 6, 5, 9, 6, 0]) # Format: # [year, month, day, weekday, hour, minute, second] # ================= FUNCTION TO CONVERT WEEKDAY ================= # This function converts the weekday number into the weekday name def get_day(d): if d == 1: return "Monday" if d == 2: return "Tuesday" if d == 3: return "Wednesday" if d == 4: return "Thursday" if d == 5: return "Friday" if d == 6: return "Saturday" if d == 7: return "Sunday" # ================= MAIN LOOP ================= # Infinite loop to display real-time clock continuously while True: # Read date and time from the RTC module t = rtc.date_time() # Move cursor to column 0, row 0 lcd.move_to(0, 0) # Display title lcd.putstr("ESP8266 Clock") # Move cursor to row 1 lcd.move_to(0, 1) # Display day of the week lcd.putstr("Day: " + get_day(t[3])) # Move cursor to row 2 lcd.move_to(0, 2) # Display date (day/month/year) lcd.putstr("Date: {}/{}/{}".format(t[2], t[1], t[0])) # Move cursor to row 3 lcd.move_to(0, 3) # Display time (hour:minute:second) with leading zeros lcd.putstr("Hour: {:02d}:{:02d}:{:02d}".format(t[4], t[5], t[6])) |
Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.
Zaouiet Kontech-Jemmel-Monastir-Tunisia
+216 92 886 231
medaliprof@gmail.com
Robotic site created by Mohamed Ali Haj Salah - Teacher info