ESP8266 ESP-01 Real time clock with DS3231/DS1307

This post shows how to build a real time clock using ESP8266 (ESP-01) module, DS3231 RTC or DS1307 RTC and 16×2 LCD. Time and date are displayed on the 16×2 LCD screen and they (time and date) can be set with 2 push buttons.
As known the ESP-01 module has 8 pins of which 4 can be used as I/O (Input/Output) pins. In this project all the I/O pins will be used, and due to the number of I/O pins I’m going to use an I2C LCD which provided with PCF8574 I/O expander. So, the I2C LCD will take 2 pins (SDA and SCL) and each button will take 1 pin.

If you want to see how to use the ESP-01 module for the first time, how to use it with Arduino IDE and how to program (upload sketches) it with Arduino, visit the following topic:
ESP8266 WiFi module programming with Arduino UNO board

Also, the page below shows how to interface the ESP-01 module with I2C LCD:
Interfacing ESP8266 ESP-01 module with I2C LCD

Both DS3231 and DS1307 can be used in this project, the DS3231 is more accurate.

Hardware Required:
The components required for this project are listed below.

  • ESP8266 ESP-01 module
  • DS3231 (or DS1307) board
  • 16×2 LCD screen
  • PCF8574 I/O expander (or PCF8574A)   —   PCF8574 datasheet
  • AMS1117 3V3 voltage regulator
  • 2 x pushbutton
  • 10uF capacitor
  • 0.1uF (100nF) ceramic capacitor
  • 7 x 10k ohm resistor
  • 330 ohm resistor
  • 10k ohm variable resistor or potentiometer
  • 3V coin cell battery
  • 5V source
  • Breadboard
  • Jumper wires

ESP8266 ESP-01 with DS3231 RTC and I2C LCD

The Circuit:
Project circuit diagram is shown below.
The DS3231 board is shown in the circuit diagram, the DS1307 board has the same pin names and should be connected as the DS3231 board.

ESP8266 ESP-01 DS3231 RTC, DS1307 RTC, I2C LCD, push button circuit

(All grounded terminals are connected together)

The I2C LCD and the DS3231 RTC board (or DS1307) share the same I2C bus which means the SDA line of the I2C LCD (presented by PCF8574) and the DS3231 RTC chip are connected together with GPIO0 of the ESP-01 module, the SCL line of the I2C LCD and the DS3231 are connected together with GPIO2 of the ESP-01 module.

The DS3231 RTC board and the I2C LCD (with PCF8574) are supplied with 5V, the ESP-01 module is supplied with 3.3V through the AMS1117 3V3 voltage regulator, this regulator steps down the 5V into 3.3V.

The two push buttons in the circuit are used to set time and date of the real time clock, button 1 (B1) is connected to RX pin (GPIO3) and button 2 (B2) is connected to TX pin (GPIO1) of the ESP-01 module.

The Code:
The code below works with DS3231 and DS1307 without any modification and it doesn’t use any library for the real time clock chip (DS3231 or DS1307).

I2C LCD and DS3231 RTC share the same I2C bus and the ESP8266 communicates only with 1 device at a time depending on the address, the I2C LCD address is 0x27 and the DS3231 (and DS1307) address is 0x68.

To be able to compile the code, we need a library for the I2C LCD which works with the ESP-01 module, download links are below:
LiquidCrystal_I2C Library   —   direct link

Finally, the small video below shows my prototype circuit result:

4 thoughts on “ESP8266 ESP-01 Real time clock with DS3231/DS1307”

  1. Thank you for sharing this informations, but you don’t use I2c in you schematic circuit.
    And how can you Running both 5v ( DS3231) and 3.3v (ESP01) devices on the same I2C ?

    1. This circuit uses the conventions of I2C SCL and SDA in the LCD and in the RTC, VCC and GND of the two go to 5V and GND of the circuit

    2. Ahmed, you really need to read up about I2C before commenting. It is a bus. So you can have multiple I2C devices on this bus, as long as each device has a unique address. And pin 14 and 15 of the ESP are clearly labelled SDA and SCL, these go to equally clearly-labelled pins on both the RTC and the LCD.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top