ESP32-C3 0.42" OLED Clock With WiFi, NTP, Alarm and Timer

by CheshirCa in Circuits > Microcontrollers

69 Views, 0 Favorites, 0 Comments

ESP32-C3 0.42" OLED Clock With WiFi, NTP, Alarm and Timer

ESP32-C3-Clock.jpg
ESP32-C3-Clock_Web.jpg

ESP32-C3 SuperMini clock project with built-in 0.42" OLED display (72x40 pixels), WiFi connectivity, NTP time synchronization, alarm and timer. The device stores settings in non-volatile storage (NVS) and is controlled via serial terminal, built-in BOOT button, and web interface.

✨ Features

  1. Real-time clock with NTP synchronization
  2. 📡 WiFi connectivity with persistent settings
  3. 🌐 Web interface for remote control
  4. 🔔 Flexible alarm:
  5. Daily
  6. Weekdays (Mon-Sun, any combination)
  7. Specific date
  8. Text message (up to 30 bytes, ~10 characters in English)
  9. Repeating or one-time
  10. Save to NVS
  11. ⏲️ Countdown timer:
  12. From 1 second to 24 hours
  13. Text message
  14. Formats: HH:MM:SS, MM:SS or SS
  15. High-precision counting based on esp_timer (microsecond accuracy)
  16. 💾 Non-volatile storage of WiFi, timezone and alarm settings
  17. 🔵 LED indication:
  18. Solid ON = alarm is active
  19. Blinking (500ms) = timer is running
  20. 🔊 Buzzer alerts with piezo buzzer (beep-beep-beep pattern)
  21. 📟 Information screens with detailed statistics
  22. 🔤 UTF-8 support (Cyrillic and Latin)
  23. 📜 Command history in Serial terminal (up/down arrows, 10 commands)


Quick Start

  1. Configure WiFi in code (or via Serial/Web after upload):
String defSSID = "your_SSID"; // Your WiFi SSID
String defPASS = "your_PASSWORD"; // Your WiFi password

  1. Configure timezone (default GMT+3):
long defGMTOffset = 3 * 3600; // GMT+3 (Moscow)
long defDaylightOffset = 0; // DST (0 = off)

  1. Upload sketch to ESP32-C3
  2. Open Serial Monitor (115200 baud, NL&CR) or web browser
  3. For web interface:
  4. Get IP address from Serial Monitor
  5. Open http://192.168.x.x in browser
  6. Control your clock through convenient interface!

🌐 Web Interface (NEW in v2.0!)

After connecting to WiFi, open the device's IP address in a browser for full-featured web interface access.

Web interface features:

📊 Main page:

  1. Current time (large font)
  2. Date and day of week
  3. WiFi SSID and connection status
  4. IP address
  5. Time sync status
  6. Free memory information

🔔 Alarm control:

  1. Type selection: daily / weekdays / specific date
  2. Time setting
  3. Text message (Cyrillic support!)
  4. Repeat and save to NVS flags
  5. Display of current active alarm

⏲️ Timer control:

  1. Duration setting (HH:MM:SS)
  2. Text message
  3. Real-time remaining time display

⚙️ System settings:

  1. Change NTP server
  2. Configure timezone (GMT offset)
  3. Configure daylight saving time (DST offset)
  4. Force sync button
  5. Manual time setting
  6. Save/restore settings from NVS
  7. Clear NVS
  8. Reboot device

🎨 Interface features:

  1. Responsive design (works on phone, tablet, PC)
  2. Auto-refresh data every 2 seconds
  3. Modern gradient design
  4. Confirmation for destructive operations
  5. UTF-8 support (type text in any language!)

💻 Serial Terminal Commands

Connection: 115200 baud, Newline & Carriage Return (NL&CR)

Command history (NEW in v2.0!): Use ↑/↓ arrows to navigate history (last 10 commands)

Help and status

HELP - Show all available commands
STATUS - Show detailed system status
SYNC - Force time synchronization with NTP
REBOOT - Reboot device


WiFi setup

WIFI <SSID> <password> - Set WiFi parameters
SAVE - Save settings to NVS
RESTORE - Load settings from NVS
ERASE - Clear all settings in NVS


Examples:

WIFI MyHomeWiFi password123
SAVE


Time setup

TIME YYYY-MM-DD HH:MM:SS - Set time manually
NTP <server> - Change NTP server (default: pool.ntp.org)
TZ <±hours> - Set timezone
DST <±hours> - Set daylight saving time offset


Examples:

TIME 2025-01-15 14:30:00
NTP time.google.com
TZ +3 # GMT+3 (Moscow)
TZ -5 # GMT-5 (New York)
DST +1 # Daylight saving +1 hour


Alarm

Command format:

ALARM [date/days] HH:MM [TEXT] [R] [S]


Parameters:

  1. HH:MM - trigger time (required)
  2. YYYY-MM-DD - specific date (optional)
  3. 1234567 - weekdays: 1=Mon, 2=Tue, 3=Wed, 4=Thu, 5=Fri, 6=Sat, 7=Sun (optional)
  4. TEXT - message text up to 30 bytes (~10 characters) (optional)
  5. R - repeat after trigger (optional)
  6. S - save to NVS (optional)

Examples:

# Daily alarm at 07:00
ALARM 07:00

# Alarm at 08:30 with text "Work"
ALARM 08:30 Work

# Alarm on specific date
ALARM 2025-12-31 23:59 NewYear

# Weekday alarm (Mon-Fri) at 07:00, repeating, with save
ALARM 12345 07:00 WakeUp R S

# Weekend alarm (Sat-Sun)
ALARM 67 10:00 Weekend

# Monday only
ALARM 1 09:00 Monday

# Clear alarm
ALARM CLEAR


Important:

  1. If starts with digits 1-7 WITHOUT colon, these are weekdays
  2. If starts with time (e.g., 17:00), this is a daily alarm
  3. Flags R and S are separate, case-insensitive letters
  4. Text should not start with letters R or S (will be treated as flag)

Timer

Command formats:

TIMER HH:MM:SS [TEXT] - Hours:Minutes:Seconds
TIMER MM:SS [TEXT] - Minutes:Seconds
TIMER SS [TEXT] - Seconds
TIMER CLEAR - Clear timer


Examples:

# 5 minutes
TIMER 5:00
TIMER 300

# 1 hour 30 minutes
TIMER 1:30:00
TIMER 90:00

# 3 hours with text
TIMER 3:00:00 Meeting

# 45 seconds
TIMER 45

# With text
TIMER 3:00 Tea

# Clear timer
TIMER CLEAR


Limitations:

  1. Minimum: 1 second
  2. Maximum: 24 hours (86400 seconds)

🖥️ Display Operation

Main screen

┌──────────────┐
│ 14:30 │ ← Time (blinking colon)
│ 15.01.2025 * │ ← Date, * = alarm active
└──────────────┘


Indicators:

  1. * - alarm active
  2. # - timer active

Info Screen 1 (press BOOT once)

INFO 1/2
Day: Wed
Alarm: 07:00
Timer: 45 sec
WiFi: ON


Info Screen 2 (press BOOT twice)

INFO 2/2
SSID: MyHomeWiFi
IP: 192.168.1.100
Time: SYNC
RAM: 285 KB


Auto-return: Returns to main screen after 10 seconds automatically

Trigger Screen

When alarm or timer triggers:

┌──────────────┐
│ ALARM │ ← or alarm/timer text
│ │
│ BOOT to STOP │ ← Press BOOT to stop
└──────────────┘


🎮 BOOT Button Control

ScreenActionResult

Main screen

1x press

Info Screen 1

Info Screen 1

1x press

Info Screen 2

Info Screen 2

1x press

Return to main screen

Alarm/Timer

1x press

Stop signal

💡 Blue LED Indication (IMPROVED in v2.0!)

  1. SOLID ON (active LOW) - alarm is set and active
  2. BLINKING (500ms) - timer is running
  3. OFF - alarm is disabled or triggered

🔊 Buzzer Operation (IMPROVED in v2.0!)

Signal pattern when triggered:

  1. First beep: 150ms
  2. Pause: 150ms
  3. Second beep: 150ms
  4. Pause: 150ms
  5. Third beep: 150ms
  6. Long pause: 1250ms
  7. Repeat...

Stop: Press BOOT button

💾 NVS Data Storage

Automatically saved:

  1. WiFi credentials (when using SAVE command)
  2. Timezone settings (when using SAVE command)
  3. NTP server settings (when using SAVE command)

Saving alarm:

  1. Use flag S when setting alarm
  2. Or save current configuration with SAVE command

Examples:

# Set alarm and save
ALARM 07:00 Work R S

# Configure WiFi and save
WIFI MyNetwork password123
SAVE

# Clear all settings
ERASE


📊 Usage Examples

Work alarm (Mon-Fri, 7:00, repeating)

# Connect to Serial Monitor (115200 baud)
> ALARM 12345 07:00 Work R S
Alarm set for Weekdays: Mon Tue Wed Thu Fri 07:00 [R] [S] 'Work'
Alarm saved to NVS

> STATUS
=== SYSTEM STATUS ===
...
Alarm: Weekdays: MonTueWedThuFri 07:00 [R] [S] 'Work'
...


Tea timer (3 minutes)

> TIMER 3:00 Tea
Timer set for 03:00 seconds, text='Tea'


New Year alarm

> ALARM 2025-12-31 23:59 NewYear S
Alarm set for 2025-12-31 23:59 [S] 'NewYear'
Alarm saved to NVS


Configure for different timezone

# London (GMT+0)
> TZ 0
GMT offset set to +0 hours

# New York (GMT-5)
> TZ -5
GMT offset set to -5 hours

# Tokyo (GMT+9)
> TZ +9
GMT offset set to +9 hours

# Save settings
> SAVE
Config saved


🐛 Troubleshooting

Issue: Buzzer not working

Solution:

  1. Check HCM1203X polarity
  2. GPIO10 should be connected to "+" of buzzer
  3. GND should be connected to "-" of buzzer
  4. If not working - try reversing the connections
  5. Verify you're using active buzzer (with built-in generator)

Issue: Display not working or shows garbage

Solution:

  1. Check I2C connections (SDA=GPIO5, SCL=GPIO6)
  2. Ensure U8g2 library is installed
  3. Check power supply voltage (should be 3.3V)

Issue: Cannot connect to WiFi

Solution:

  1. Verify SSID and password
  2. Ensure you're using 2.4 GHz WiFi (ESP32-C3 doesn't support 5 GHz)
  3. Use WIFI SSID password command to reconfigure
  4. Check network availability with STATUS command

Issue: Time not synchronizing

Solution:

  1. Check internet connection
  2. Use SYNC command to force synchronization
  3. Try different NTP server: NTP time.google.com
  4. Check timezone settings: TZ +3

Issue: Alarm triggers at wrong time

Solution:

  1. Check timezone with STATUS command
  2. Set correct timezone: TZ +3
  3. Check daylight saving setting: DST 0
  4. Save settings: SAVE

Issue: Settings not persisting after reboot

Solution:

  1. Use SAVE command after changing settings
  2. For alarm use S flag: ALARM 07:00 S
  3. Check NVS is not corrupted: ERASE, then reconfigure

📝 Known Limitations

  1. WiFi 5 GHz not supported - ESP32-C3 only works with 2.4 GHz
  2. Maximum text length for alarm/timer - 30 bytes (~10 characters)
  3. Single active alarm - only one alarm can be set at a time
  4. Single active timer - only one timer can be set at a time
  5. Auto-return from info screens after 10 seconds
  6. Time synchronization occurs at startup and can be triggered with SYNC command

🎯 Advanced Usage Tips

Creating Complex Alarm Schedules

Since only one alarm can be active, use these strategies:

Weekday morning + Weekend:

# Monday morning - Friday morning
ALARM 12345 07:00 Work R S

# When weekend comes, manually set:
ALARM 67 10:00 Weekend


Monthly reminders:

# Set specific date alarm
ALARM 2025-02-01 09:00 Rent S

# After trigger, set next month
ALARM 2025-03-01 09:00 Rent S


Using Timer for Pomodoro Technique

# Work session (25 minutes)
TIMER 25:00 Work

# After work, set break (5 minutes)
TIMER 5:00 Break

# Long break (15 minutes)
TIMER 15:00 LongBreak


Multiple NTP Servers for Reliability

If primary NTP server fails:

NTP pool.ntp.org # Primary
NTP time.google.com # Backup
NTP time.cloudflare.com # Alternative


🔐 Security Considerations

  1. WiFi credentials are stored in plain text in NVS
  2. Serial console is unprotected - anyone with USB access can control the device
  3. For production use, consider:
  4. Adding authentication to serial commands
  5. Encrypting sensitive data in NVS
  6. Disabling serial console in final builds


Supplies

ESP32-C3-Buzzer.jpg

Wiring:

Connection: GPIO10 (pin 16) → "+" buzzer, GND (pin 2) → "-" buzzer

Polarity is critical! If not working - swap the connections


Upload the attached sketch to Arduino IDE, change the SSID and password settings. Install support for ESP32 devices, and select the "ESP32C3 Dev Kit" device. Make sure "USB CDC on boot" is enabled. Compile and upload the script to the device. Reconnect the device and connect to its serial port using a terminal or to a website using a browser.

Downloads