How to build a Mechanical 7-Segment Display Clock Using ESP32
How to Build a Mechanical 7-Segment Display Clock Using ESP32: My Journey into Electromechanical Timekeeping
Mechanical displays have always fascinated me because they transform abstract data into physical motion. Unlike conventional digital clocks that silently update pixels on a screen, a mechanical display makes time visible through movement. Every minute change is something you can actually see and hear, which makes the experience far more engaging.
This project documents my journey of building a mechanical 7-segment display clock using an ESP32 microcontroller, PCA9685 PWM driver boards, multiple servo motors, and a Real-Time Clock (RTC) module. Each digit is constructed from seven servo-driven flaps that physically rotate to form numbers, resulting in a striking electromechanical time display.
The biggest challenge in this build was coordinating 28 servo motors simultaneously while maintaining accurate timekeeping and stable power delivery. By offloading PWM generation to dedicated hardware drivers and isolating timekeeping with an RTC module, the system achieves reliable operation and clean scalability. In this guide, I’ll walk you through the hardware design choices, wiring strategy, and control logic that brought this mechanical clock to life.
🔧 The Hardware: What’s Under the Hood
Building a large-scale mechanical display is as much a power-engineering challenge as it is a programming one. With dozens of servo motors physically moving flaps, careful hardware selection was essential to ensure smooth motion, electrical stability, and long-term reliability.
Unlike small servo projects that attempt to power everything directly from a microcontroller, this build uses a dedicated high-current power system and hardware PWM driver boards. This approach prevents timing jitter, voltage drops, and unpredictable behavior when multiple segments move simultaneously.
| Component | Specification | My Design Choice & Experience |
|---|---|---|
| Microcontroller | ESP32 Dev Board | Chosen for its higher processing power, native I²C support, and future expandability such as Wi-Fi or NTP-based time synchronization. |
| PWM Driver | PCA9685 (16-Channel, I²C) ×2 | Absolutely essential for stable servo control. Offloads PWM generation from the ESP32 and allows clean scaling to multiple digits. |
| RTC Module | DS3231 / DS1307 | Provides accurate, battery-backed timekeeping even when the system is powered off. |
| Servo Motors | MG996 Servo Motors (28 Units) | Selected for their high torque, which is critical for reliably flipping mechanical segments under load. |
| Power System | 5V, 36A DC Power Supply | Ensures that simultaneous servo movement does not cause voltage drops or system instability. |
| Capacitors | 4700 µF Electrolytic (Per PCA Board) | Helps absorb current spikes during servo actuation and reduces electrical noise. |
| Mechanical Structure | Custom 7-Segment Frame & Flaps | Designed to hold servos securely while allowing smooth flap movement without mechanical binding. |
Why This Hardware Configuration Matters
The combination of an ESP32 with PCA9685 PWM drivers ensures that servo control remains precise and jitter-free, even when many segments move at the same time. Using an independent RTC module separates timekeeping from the microcontroller’s execution cycle, significantly improving accuracy and reliability.
Most importantly, the external high-current power supply eliminates one of the most common problems in servo-heavy projects: unstable behavior caused by insufficient current. By separating logic power from servo power while maintaining a common ground, the system delivers consistent and predictable performance.
This hardware architecture forms a robust foundation for a mechanical clock that is not only functional, but also scalable for future enhancements.
🔌 My Setup: A Clean and Precise Connection Map Is Essential
When controlling dozens of servo motors, a clean and well-planned wiring layout becomes absolutely critical. While this project does not rely on fast interrupt-driven loops, it depends heavily on reliable I²C communication, stable power distribution, and clear channel mapping.
By using hardware PWM driver boards and an RTC module, the ESP32 is relieved from time-critical PWM generation and can focus entirely on high-level control logic. This makes a precise pin map the backbone of a stable and scalable system.
ESP32 ↔ Peripheral Connections
| Component | Signal | ESP32 Pin | Function |
|---|---|---|---|
| PCA9685 (Board 1) | SDA | GPIO 21 | I²C data line for PWM control |
| PCA9685 (Board 1) | SCL | GPIO 22 | I²C clock line |
| PCA9685 (Board 2) | SDA | GPIO 21 | Shared I²C data line |
| PCA9685 (Board 2) | SCL | GPIO 22 | Shared I²C clock line |
| RTC Module | SDA / SCL | GPIO 21 / 22 | Time data and synchronization |
All I²C devices share the same SDA and SCL lines, with each PCA9685 board configured using a unique I²C address.
Servo Channel Mapping (Conceptual)
| Digit | PCA Board | Channels Used |
|---|---|---|
| Hour Tens | PCA #1 (0x40) | Channels 0–6 |
| Hour Units | PCA #1 (0x40) | Channels 7–13 |
| Minute Tens | PCA #2 (0x41) | Channels 0–6 |
| Minute Units | PCA #2 (0x41) | Channels 7–13 |
🛠 Motion Calibration and Timing Optimization
Achieving clean and consistent motion was one of the most critical aspects of this build. Since the display relies on physical movement rather than electronic pixels, even small positioning errors become immediately noticeable.
Each servo was individually calibrated to define safe and repeatable ON and OFF positions for its segment. Differences in mechanical orientation were handled entirely in software, keeping the mechanical structure simple while ensuring uniform behavior across all digits.
To reduce unnecessary movement and mechanical wear, the system updates the display only when the time changes. This optimization, combined with stable power delivery and correct PWM configuration, results in smooth operation and long-term reliability.
💻 The Final Firmware (Source Code)
The firmware represents the final integration of all system components, combining RTC-based timekeeping, I²C communication, and servo control through PCA9685 hardware PWM drivers. After extensive testing and calibration, the code reliably translates real-time clock data into coordinated mechanical motion.
The program initializes the ESP32, RTC module, and both PCA9685 boards, then continuously reads the current time and updates the mechanical display only when required. This minimizes unnecessary servo movement, reduces mechanical wear, and ensures stable long-term operation.
Within the source code, you will find clear implementations of:
- RTC initialization and accurate time retrieval
- Digit extraction and 7-segment mapping logic
- Servo control functions using PCA9685 hardware PWM
- Calibration handling for segment orientation and limits
A Final Note
This project demonstrates how combining solid hardware architecture with thoughtful software design can transform a simple concept into a reliable electromechanical system. With its modular design, this mechanical clock can be easily expanded with additional digits, animations, or even network-based time synchronization in the future.