Real-Time OLED Clock With RTC DS3231 and ESP32
by sarful in Circuits > Arduino
72 Views, 0 Favorites, 0 Comments
Real-Time OLED Clock With RTC DS3231 and ESP32
Objective
Create a real-time OLED clock using the DS3231 RTC module and display it on an SSD1306 OLED with the ESP32 microcontroller.
System Overview
- Displays real-time hours, minutes, seconds, and date.
- Uses an RTC DS3231 module for accurate timekeeping.
- Compatible with ESP32 for low power consumption and wireless connectivity.
- Displays weekday names along with date and time.
Supplies
Required Components
- Arduino Uno: Buy on Amazon
- RTC DS3231 Module: Buy on Amazon
- OLED Display (SSD1306): Buy on Amazon
- ESP32: Buy on Amazon
- Jumper Wires: Buy on Amazon
- Breadboard: Buy on Amazon
Affiliate Link Disclaimer: Links are affiliate links, meaning that purchases made through them help support free tutorials and projects, at no additional cost to you.
Circuit Connection
- RTC DS3231 Connections:
- SDA → GPIO21 (ESP32)
- SCL → GPIO22 (ESP32)
- VCC → 3.3V (ESP32)
- GND → GND (ESP32)
- OLED SSD1306 Display Connections:
- MOSI → GPIO23
- CLK → GPIO18
- DC → GPIO4
- CS → GPIO5
- RESET → GPIO2
Circuit Connection Analysis
The DS3231 provides accurate real-time clock data to the ESP32 through I2C communication, while SPI protocol drives the SSD1306 OLED display. The ESP32 retrieves data from the RTC and sends it to the OLED, allowing the time to refresh continuously.
Setting Up the ESP32
- Install ESP32 Board Support in Arduino IDE:
- Go to File > Preferences.
- Add the URL to "Additional Boards Manager URLs": https://dl.espressif.com/dl/package_esp32_index.json.
- Go to Tools > Board > Boards Manager, search for "ESP32", and install it.
- Required Libraries:
- Adafruit GFX and Adafruit SSD1306 for the OLED display.
- RTClib for the DS3231 RTC module.
Building the Web Interface Code (HTML and PHP)
If desired, the ESP32 can serve a basic HTML page to show time data.
Arduino Board and Library Configuration
- Libraries Needed:
- SPI for the OLED screen communication.
- Wire for I2C communication with the RTC.
- Adafruit GFX, Adafruit SSD1306, and RTClib.
- Board Configuration: Select ESP32 Dev Module under Tools > Board.
Arduino Code
Steps to Upload
- Connect ESP32 to your computer.
- Go to Tools > Board and select ESP32 Dev Module.
- Choose the correct port under Tools > Port.
- Click Upload.
Run
- Ensure all connections are secure.
- Power on the ESP32 and open the Serial Monitor at 9600 baud.
- Check for the real-time display on the OLED screen.
Check Output
- Verify that the OLED shows the current time and date.
- Ensure data updates every second.
- Cross-check date information for accuracy.
Frequently Asked Questions (FAQ)
- How do I adjust the time on the RTC?
- You can use rtc.adjust(DateTime(__DATE__, __TIME__)); in setup().
- What if the RTC loses power?
- The DS3231 includes a battery backup that retains time data during power interruptions.
- Is this project compatible with other microcontrollers?
- Yes, the code and connections can be adapted for other microcontrollers.
- Can I add extra information to the OLED display?
- Absolutely. Modify the display.print functions to show additional data.
Recommended Book
Arduino Programming for Absolute Beginners
Perfect for beginners, this book covers Arduino programming basics through practical projects, making it an ideal start for those new to electronics.
For more free tutorials and projects on Arduino, ESP8266, ESP32, and Raspberry Pi, visit: MechatronicsLab.net