A Clock Powered by Math: the Fibonacci LED Clock

by Guitarman9119 in Circuits > Raspberry Pi

289 Views, 4 Favorites, 0 Comments

A Clock Powered by Math: the Fibonacci LED Clock

Weixin Image_20251217191928_94_2.jpg

What if a clock didn’t use numbers at all—only math?

In this project, we’ll build a Fibonacci Clock, a unique timepiece that tells the time using the Fibonacci sequence instead of traditional digits. By lighting up different blocks whose sizes follow the Fibonacci numbers (1, 1, 2, 3, and 5), the clock visually represents the current time in a surprisingly intuitive way.

This version of the Fibonacci Clock is powered by a Raspberry Pi Pico W, addressable WS2812B LEDs, a custom PCB, and a 3D-printed enclosure.

This project is inspired by another Instructable, and I decided to create a small desktop version to keep the PCB under 10 × 10 cm, reducing manufacturing costs. I hope you have fun building this project yourself!

Supplies

To build this clock, you will need the following parts and equipment.

  1. Raspberry Pi Pico W (available from many vendors)
  2. Custom PCB (Link)
  3. 3D Printed enclosure ( Need multicolor 3D Printer )
  4. WS2812b LEDs
  5. Solder Hot Plate

How Does the Clock Work

Fusion360)numbers.png

1. Fibonacci Blocks

The clock is made up of five blocks, each representing a Fibonacci number:

Each block may be lit in a different color depending on how it contributes to the time.


2. Color Meanings

Each block uses color to indicate its purpose:

- **Red** → Hours

- **Blue** → Minutes

- **Green** → Both hours and minutes

- **White** → Not used


3. Reading the Hours

To calculate the hour:

1. Add the values of all **red** blocks.

2. Add the values of all **green** blocks.

**Hour = Red blocks + Green blocks**


4. Reading the Minutes

To calculate the minutes:

1. Add the values of all **blue** blocks.

2. Add the values of all **green** blocks.

3. Multiply the total by **5**.

**Minutes = (Blue blocks + Green blocks) × 5**

Example 1 - Reading Time

Demo 4.png

From the image we see that:

  1. Red block: 1
  2. Blue block: 2
  3. Green block: 5

Hour = Red blocks + Green blocks

Minutes = (Blue blocks + Green blocks) × 5

Then:

  1. Hours = 1 + 5 = 6
  2. Minutes = (2 + 5) × 5 = 35

➡️ The time is 6:35

Prototype

prototype.png

I previously created a prototype of this clock using an addressable LED controller with five LED strips, each containing a different number of WS2812B LEDs. However, this version uses a custom PCB with the LEDs soldered directly onto it.



Enclosure Design

fiv_enclosure_back.png
fiv_enclosure_main.png
outline_dxf.png

I designed the enclosure for the clock first. While this might sound unusual to do before designing the PCB, the reason is straightforward: by designing the enclosure first, I could define the five blocks that represent the Fibonacci sequence, then export the front face as a DXF file. This DXF was later used as a reference when designing the PCB, ensuring that the LEDs are positioned correctly behind each block.

The enclosure was designed using Fusion 360.

The enclosure consists of two parts.

The first part is the main body, which contains the five blocks used to display the time. These blocks were printed using white filament with a 0.4 mm layer height, allowing the LEDs to diffuse the light evenly. One of the main challenges during this stage was determining how far the LEDs should be positioned from the blocks to achieve good light diffusion without hotspots.

The second part is the back cover, which slots into the main enclosure and is held in place using M3 hex screws. This section also houses the electronics. The clock is powered via USB-C, making it easy to power from a wall adapter or power bank.

Schematic + PCB (EasyEDA)

Schematic_fib.png

For the final version of this Fibonacci Clock, I designed a custom PCB to keep the wiring clean, compact, and reliable. The PCB was designed using EasyEDA, which integrates well with JLCPCB and makes the ordering process straightforward.

Why a Custom PCB?

While the prototype used an LED strip and wiring, a custom PCB offers several advantages:

  1. Cleaner and more reliable connections
  2. Consistent LED spacing and layout
  3. Smaller overall footprint
  4. Lower assembly time
  5. Reduced cost when ordering multiple boards

To keep manufacturing costs low, the board size was intentionally kept under 10 × 10 cm.

LED Layout

The clock uses50 WS2812B LEDs, arranged to represent the Fibonacci sequence:

  1. 1
  2. 1
  3. 2
  4. 3
  5. 5

The LEDs corresponds to a “block” of the clock. In the final version, these LEDs will light up different colors to represent hours and minutes.

All LEDs are connected in series, meaning:

  1. DIN → DOUT from one LED to the next
  2. A single data line from the Raspberry Pi Pico W controls all LEDs

Schematic Design

In EasyEDA, I first created the schematic:

  1. Raspberry Pi Pico W connected to:
  2. WS2812B data line
  3. 5V power rail
  4. Common ground

Once the schematic was complete, I converted it to a PCB layout.

PCB Layout

When routing the board, I focused on:

  1. Keeping data lines as short as possible
  2. Using wide traces for 5V and GND
  3. Placing LEDs in positions that align with the clock face
  4. Adding mounting holes for the 3D-printed enclosure

Silkscreen labels were added to make assembly and debugging easier.

Final Checks

Before exporting the Gerber files, I:

  1. Ran EasyEDA’s Design Rule Check (DRC)
  2. Verified LED orientation
  3. Double-checked power and ground connections

Once everything checked out, the Gerber files were exported and prepared for manufacturing.

Ordering the Custom PCB (JLCPCB)

PCB_fib.png
pcb_fib.jpg

Ordering the Custom PCB (JLCPCB)

Once the PCB design was finalized in EasyEDA, the next step was to have the board manufactured. I chose JLCPCB because of their low cost, good quality, and seamless integration with EasyEDA.

Exporting the Gerber Files

From EasyEDA, I exported the Gerber files, which contain all the information needed to manufacture the PCB. EasyEDA can export these files directly in a format that is compatible with JLCPCB, making the process quick and straightforward.

Before uploading the files, I double-checked:

  1. Board dimensions (kept under 10 × 10 cm)
  2. LED orientation
  3. Power and ground connections
  4. Mounting hole placement

Uploading to JLCPCB

After exporting the Gerber files, I uploaded them to the JLCPCB website. The board preview tool was used to visually confirm that everything looked correct.

PCB Specifications

For this project, I used the following settings:

  1. PCB Layers: 2
  2. PCB Thickness: 1.6 mm
  3. Copper Weight: 1 oz
  4. Surface Finish: HASL (Lead-Free)
  5. Solder Mask Color: (choose your preferred color)

These are standard settings and work well for most small electronics projects.

Ordering and Delivery

Once the settings were confirmed, I placed the order. Manufacturing usually takes only a few days, and shipping time depends on the selected delivery option.

When the PCBs arrived, I inspected them for:

  1. Correct dimensions
  2. Clean solder mask
  3. Properly drilled holes
  4. Accurate silkscreen

Everything looked good and was ready for assembly.

In the next step, we’ll move on to assembling the PCB and soldering the components.

Hot Plate Soldering the LEDs

solder-ezgif.com-video-to-gif-converter.gif

To solder the WS2812B LEDs onto the PCB, I used a hot plate instead of a traditional soldering iron. This method is especially useful for surface-mount components, as it allows all pads to be soldered evenly at the same time.

What You’ll Need

  1. Custom PCB
  2. WS2812B LEDs
  3. Solder paste
  4. Tweezers
  5. Hot plate (or reflow hot plate)

Applying the Solder Paste

First, I applied a small amount of solder paste to each LED pad on the PCB. Be careful not to use too much paste, as this can cause solder bridges. A toothpick or fine syringe works well for this step.

Placing the LEDs

Using tweezers, I carefully placed each LED onto its footprint, making sure the orientation was correct. WS2812B LEDs are polarity-sensitive, so double-check the data input (DIN) direction and alignment with the silkscreen before heating.

Reflowing on the Hot Plate

Once all LEDs were in place, I positioned the PCB on the hot plate and slowly increased the temperature. As the board heated up, the solder paste began to melt and reflow, pulling the LEDs neatly into position.

When all the solder joints had flowed and looked shiny, I turned off the heat and allowed the PCB to cool naturally. Avoid moving the board while the solder is still molten.

Inspection and Cleanup

After the PCB cooled down, I inspected all solder joints to ensure:

  1. No solder bridges
  2. All pads were properly soldered
  3. LEDs were sitting flat on the PCB

At this point, the LEDs were securely soldered and the PCB was ready for the next assembly steps.

Soldering the Pico Headers and Power Connections

header-ezgif.com-video-to-gif-converter.gif

The next step is to solder the header pins for the Raspberry Pi Pico. Once the headers are soldered, snap the USB-C adapter into the 3D-printed enclosure. After it is securely in place, solder the two power wires (5V and GND) from the USB-C adapter to the corresponding pads on the PCB.

Programming the Pico W and Connecting It to the PCB

At this stage, the Pico W can be connected to the PCB and powered on through the USB port before assembling the enclosure. Doing this allows the code to be uploaded, tested, and debugged while everything is still easily accessible.

All the code for the project can be downloaded here.

Configuration File (config.json)

API.png

The config.json file stores all user-specific settings separately from the main program. This makes it easy to update Wi-Fi credentials, time zone, or API keys without modifying the main code.


Setting Up the Time API (ipgeolocation.io)

To automatically set the correct time, this project uses the ipgeolocation.io Time Zone API. The Pico W connects to the internet, retrieves the current date and time, and updates its internal RTC (Real Time Clock).

1️⃣ Create a Free Account

  1. Go to the ipgeolocation.io website
  2. Create a free account
  3. After signing in, generate an API key

The free tier is sufficient for this project since the time is only fetched during startup.

2️⃣ Add the API Key to config.json

Open the config.json file on the Pico W and add your API key:


"date_time_api": "YOUR_API_KEY_HERE"

Also make sure the correct time zone is set:


"time_zone": "Asia/Shanghai"

Replace this with your local time zone if needed.

3️⃣ How the Code Uses the API

On startup, the Pico W:

  1. Connects to Wi-Fi
  2. Sends a request to the ipgeolocation API
  3. Receives the current date and time
  4. Updates the Pico W’s RTC

If the time sync is successful, the LEDs briefly turn green.

If Wi-Fi fails, the LEDs turn yellow, and the clock continues running using the last known time.

4️⃣ Why an Online Time API Is Used

The Raspberry Pi Pico W does not have a built-in battery-backed real-time clock. Using an online time API ensures:

  1. Accurate time after power loss
  2. No manual time setting required
  3. Correct handling of time zones

Once the time is set, the clock continues running locally.

Understanding the Main Code

1️⃣ Boot Delay (Important for External Power)


utime.sleep(5)

A short delay is added at startup to ensure the Pico W boots reliably when powered from an external USB power supply instead of a computer.

2️⃣ LED Setup and Fibonacci Blocks


NUM_LEDS = 50
BLOCKS = [1, 1, 6, 12, 30]

The clock uses 50 WS2812B LEDs, divided into five blocks that represent the Fibonacci sequence (1, 1, 2, 3, 5).

Each block contains a proportional number of LEDs to create a visually balanced display.

3️⃣ Color Definitions

The code defines bright and dim versions of each color:

  1. Red → hours
  2. Blue → minutes
  3. Green → hours + minutes
  4. White → inactive blocks

The first two LEDs are intentionally brighter to help balance brightness across differently sized blocks.

4️⃣ Wi-Fi Connection and Time Synchronization


connect_wifi()
sync_time(rtc)

On startup, the Pico W:

  1. Connects to Wi-Fi
  2. Fetches the current time using an online API
  3. Sets the onboard RTC (Real Time Clock)

Different colors indicate system status:

  1. Purple → boot
  2. Cyan → Wi-Fi connected
  3. Lime → time synced
  4. Yellow → Wi-Fi error

5️⃣ Fibonacci Time Calculation

fib_time(hours, minutes)

This function converts the current time into a Fibonacci representation:

  1. Hours are mapped using Fibonacci values
  2. Minutes are rounded to the nearest 5 minutes
  3. Each block can represent:
  4. Hours
  5. Minutes
  6. Both

The result is a state array that determines which blocks light up and which color to use.

6️⃣ Main Loop (Clock Update)


while True:

The main loop:

  1. Reads the current time from the RTC
  2. Calculates the Fibonacci state
  3. Updates the LED blocks
  4. Refreshes the display every second

This keeps the clock accurate and responsive without flickering.

Final Assembly

Weixin Image_20251217192301_96_2.jpg

With the PCB fully assembled and the code tested, the final step is to put everything together inside the enclosure.

Installing the PCB

Carefully place the PCB into the main enclosure, making sure that:

  1. The LEDs align correctly behind the five Fibonacci blocks
  2. The USB-C connector is accessible through the opening in the enclosure

Closing the Enclosure

Once you’re satisfied that the clock is working:

  1. Align the back cover with the main body
  2. Slide it into place
  3. Secure it using M3 hex screws


YouTube Video

This Clock Tells Time Using Fibonacci Numbers (Raspberry Pi Pico)

I’ve also documented this entire build process in a YouTube video, where I go into more detail about the design decisions, PCB layout, enclosure design, and final assembly.

If you’d like to see the project in action—or prefer a visual walkthrough—you can watch the full build video on my NerdCave YouTube channel. The video shows the clock running, explains how the Fibonacci time display works, and covers a few things that are easier to demonstrate on camera.