Arduino Nano ESP32 - Web Apps Web Rtc
Overview
This tutorial covers the DIYablesWebRTCPage class from the DIYables ESP32 WebApps Library. The browser page displays the Arduino Nano ESP32's current RTC time alongside the browser's local time, and calculates the drift between them. A single button sends the browser's local time to the board, which updates its RTC module.
The board requires a DS3231 hardware RTC module connected over I2C. The RTClib library from Adafruit handles time read/write on the board side.

What This Tutorial Covers
- Wiring a DS3231 RTC module to the Arduino Nano ESP32
- Installing the RTClib dependency
- Reading and displaying RTC time in the browser
- Synchronizing the board RTC from the browser with one button press
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
Arduino Nano ESP32 - DS3231 RTC Module
| DS1307 RTC Module | Arduino Nano ESP32 |
|---|---|
| Vin | 3.3V |
| GND | GND |
| SDA | GPIO21 |
| SCL | GPIO22 |
Steps
Follow these instructions step by step:
- If this is your first time using the Arduino Nano ESP32, refer to the tutorial on setting up the Arduino Nano ESP32 development environment.
- Connect the Arduino Nano ESP32 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate board (e.g. Arduino Nano ESP32) and COM port.
- Navigate to the Libraries icon on the left bar of the Arduino IDE.
- Search "DIYables ESP32 WebApps", then find the DIYables ESP32 WebApps Library by DIYables
- Click Install button to install the library.
- Search for DIYables ESP32 WebApps created by DIYables and click the Install button.
- You will be asked for installing some other library dependencies
- Click Install All button to install all library dependencies.
- Search "RTClib", then find the RTC library by Adafruit
- Click Install button to install RTC library.
- Search for RTClib created by Adafruit and click the Install button.
- You may be asked to install dependencies for the library
- Install all dependencies for the library by clicking on Install All button.
- On Arduino IDE, Go to File Examples DIYables ESP32 WebApps WebRTC example, or copy the above code and paste it to the editor of Arduino IDE
- Update the WiFi credentials in the sketch:
- Click Upload button on Arduino IDE to upload code to Arduino Nano ESP32
- Open the Serial Monitor
- The Serial Monitor output should resemble the following:
- If nothing appears, press the reset button on the board.
- Enter the IP address from the Serial Monitor into a browser on the same network.
- Example: http://192.168.0.2
- The home page shows a card for the RTC application:

- Select the Web RTC card to open the clock interface:

- The page is also directly accessible at http://192.168.0.2/web-rtc.
Using the Web Interface
The RTC page displays three sections:
- Arduino Time — the current time from the board's DS3231 module
- Your Device Time — the current local time reported by the browser
- Time Difference — the difference between the two, in minutes
Synchronizing Time
Click the Sync ESP32 Time button to transfer the browser's local time to the board:

The synchronization process:
- The browser reads its local time (accounting for the local timezone offset)
- The timestamp is sent to the board over WebSocket
- The sketch writes the received time to the DS3231
- The page refreshes to display the updated board time
After synchronization the time difference is typically 0–1 minutes.
Troubleshooting
RTC time shows wrong value
- The DS3231 retains time from its battery even when the board is powered off
- Perform a sync from the browser to set the correct time
- Check that the CR2032 battery is installed in the RTC module
I2C not detected
- Verify the SDA and SCL wiring matches the table above
- Confirm the DS3231 VCC is connected to 3.3 V, not 5 V
- Add a Serial.println(rtc.isrunning()) check in setup
WebSocket drops frequently
- Confirm webAppsServer.loop() is called on every iteration of loop()
- Avoid long blocking delays after the server starts
Cannot access the page
- Check the IP address in the Serial Monitor
- Ensure the browser device and board are on the same 2.4 GHz WiFi network