Sun Clock for ESP32-C3
A GPS-synchronized 24-hour LED clock that automatically displays sunrise and sunset times for your location. Built with ESP32 and WS2812B addressable LEDs.
Parts and sourceBefore you start
Check the exact Addressable LED strip configuration against the upstream wiring or parts list.
Upstream README
Sun Clock π
A GPS-synchronized 24-hour LED clock that automatically displays sunrise and sunset times for your location. Built with ESP32 and WS2812B addressable LEDs.
Erick's Sun Clock in action - GPS-synchronized LED display showing the 24-hour cycle
β¨ Features
- π°οΈ GPS Time Sync: Automatically sets time and timezone based on your GPS location
- π Sunrise/Sunset Display: Shows daily sunrise and sunset times as colored arcs
- π Location Aware: Works anywhere in the world - no hardcoded locations
- πΆ WiFi Fallback: Falls back to internet time sync when GPS unavailable
- π‘ 24-Hour LED Display: Each LED represents one hour of the day
- π Auto Brightness: Adjusts brightness based on time of day
- π Captive Portal: Easy WiFi setup through mobile device
- π OTA Updates: Update firmware wirelessly
π Shopping List
You'll need these components (total cost ~$25-35):
| Component | Quantity | Estimated Price | Notes |
|---|---|---|---|
| ESP32-C3 SuperMini | 1 | $3-5 | Main microcontroller |
| WS2812B LED Ring 24-pixel | 1 | $8-12 | Addressable RGB LEDs |
| NEO-6M GPS Module | 1 | $8-15 | GPS receiver |
| 220Ξ© Resistor | 1 | $1-2 | LED data line protection |
| Breadboard Jumper Wires | 1 set | $3-5 | For connections |
| Mini Breadboard | 1 (optional) | $2-3 | For cleaner wiring |
π Hardware Setup
ESP32-C3 SuperMini Pinout
USB-C
βββββββ
1 β 5V β GND 2
3 β G3 β G10 4
5 β G2 β G1 6
7 β G20 β G21 8
9 β G6 β G7 10
11 β G5 β G4 12
13 β G9 β G8 14
15 β G19 β G18 16
βββββββ
Wiring Diagram
LED Ring β ESP32:
- VCC (5V) β Pin 1 (5V)
- GND β Pin 2 (GND)
- DIN β 220Ξ© resistor β Pin 14 (GPIO8)
GPS Module β ESP32:
- VCC β Pin 1 (5V)
- GND β Pin 2 (GND)
- TX β Pin 7 (GPIO20) - ESP32 RX
- RX β Pin 8 (GPIO21) - ESP32 TX
π§ Assembly Steps
- Mount the LED ring on your project surface
- Connect power: Wire 5V and GND from ESP32 to both LED ring and GPS
- Connect LED data: LED ring DIN β 220Ξ© resistor β GPIO8
- Connect GPS serial: GPS TXβGPIO20, GPS RXβGPIO21
- Double-check connections before powering on
β οΈ Important: The 220Ξ© resistor protects the LED data line. Don't skip it!
πΎ Software Setup
Prerequisites
- Arduino IDE or Arduino CLI
- ESP32 board support package
1. Install Arduino IDE and ESP32 Support
- Download and install Arduino IDE
- Open Arduino IDE
- Go to File β Preferences
- Add this URL to "Additional Board Manager URLs":
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json - Go to Tools β Board β Boards Manager
- Search for "ESP32" and install "ESP32 by Espressif Systems"
2. Install Required Libraries
Go to Tools β Manage Libraries and install:
Adafruit NeoPixelby Adafruit
3. Download and Configure
- Download this project (Clone or download ZIP)
- Copy
.env.exampleto.env - Edit
.envwith your WiFi credentials:WIFI_SSID_1="YourWiFiName" WIFI_PASSWORD_1="YourPassword" - Update the Arduino sketch with your WiFi details (see Configuration section)
βοΈ Configuration
WiFi Setup
Edit the WiFi credentials in sun_clock.ino:
// Update these with your network credentials
WiFiNetwork networks[] = {
{"YOUR_WIFI_SSID_1", "YOUR_PASSWORD_1"},
{"YOUR_WIFI_SSID_2", "YOUR_PASSWORD_2"}, // Optional backup networks
{"YOUR_WIFI_SSID_3", "YOUR_PASSWORD_3"},
{"YOUR_WIFI_SSID_4", "YOUR_PASSWORD_4"}
};
Hardware Configuration
If you need to change pins, edit these constants:
#define LED_PIN 8 // GPIO pin for LED ring
#define BRIGHTNESS 100 // LED brightness (0-255)
π€ Upload Instructions
- Connect ESP32 to your computer via USB-C
- Select board: Tools β Board β ESP32C3 Dev Module
- Select port: Tools β Port β (your ESP32 port)
- Open
sun_clock.inoin Arduino IDE - Upload (Ctrl+U or Upload button)
Upload Settings
- Board: "ESP32C3 Dev Module"
- Flash Size: "4MB"
- Partition Scheme: "Default 4MB with spiffs"
π Usage
First Boot
- Power on - ESP32 will show a startup animation
- GPS search - Yellow spinning dots indicate GPS satellite search
- WiFi connection - Blue pattern during WiFi connection
- Time sync - Green flash when time is synchronized
Normal Operation
- Current hour: Bright white LED
- Sunrise arc: Orange/yellow LEDs before and during sunrise
- Daylight: Blue background LEDs during day
- Sunset arc: Orange/red LEDs before and during sunset
- Night: Dim blue/purple LEDs
LED Status Indicators
| Pattern | Meaning |
|---|---|
| Yellow spinning dots | GPS searching for satellites |
| Blue chase | Connecting to WiFi |
| Green flash | Time synchronized successfully |
| Red flash | Error (check serial monitor) |
| White LED | Current hour |
| Colored arcs | Sunrise/sunset times |
π§ Troubleshooting
GPS Issues
- Red flashing on GPS: Normal - searching for satellites
- No GPS fix: Try outdoors or near window, GPS needs clear sky view
- GPS takes long: First fix can take 5-15 minutes, subsequent fixes are faster
WiFi Issues
- Can't connect: Check SSID and password in code
- No internet: Check router connection
- Captive portal: If WiFi fails, ESP32 creates "SunClock-Setup" network
LED Issues
- No LEDs: Check 5V power connection and 220Ξ© resistor
- Wrong colors: Check LED ring wiring (DIN pin)
- Some LEDs work: Power supply may be insufficient
Programming Issues
- Upload failed: Check USB cable and ESP32 connection
- Board not found: Install ESP32 board package
- Compilation errors: Install Adafruit NeoPixel library
Serial Monitor Debug
Connect at 115200 baud to see debug output:
=== Sun Clock Starting ===
GPS initialized on Serial1 (GPIO20/21)
Searching for WiFi networks...
GPS: Searching for satellites...
π How It Works
- GPS Location: Gets your exact latitude/longitude from satellites
- Sunrise Calculation: Calculates sunrise/sunset times for your location and date
- Time Zones: Automatically determines timezone from GPS coordinates
- LED Mapping: Maps 24 hours to 24 LEDs, with current time as bright white
- Solar Display: Shows sunrise/sunset as colored arcs on the LED ring
π¨ Customization Ideas
- Change colors: Modify sunrise/sunset colors in the code
- Add seasons: Different color schemes for different times of year
- Weather integration: Add weather API for cloud cover
- Multiple timezones: Show time in different zones
- Alarm clock: Add buzzer for sunrise alarm
π‘ Technical Details
- Microcontroller: ESP32-C3 (WiFi + Bluetooth)
- GPS Protocol: NMEA (GPRMC sentences)
- LED Protocol: WS2812B addressable RGB
- Time Sync: GPS primary, NTP fallback
- Astronomy: Real sunrise/sunset calculations
- Memory: ~30% flash, ~15% RAM usage
π€ Contributing
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
- Adafruit for the excellent NeoPixel library
- ESP32 community for hardware support
- All the makers who will improve this project!
π Support
- Issues: Use GitHub Issues for bugs and feature requests
- Discussions: Use GitHub Discussions for questions
- Documentation: Check this README first
Made with β€οΈ for the maker community
Don't forget to star β this repo if you found it useful!