LED HOURGLASS USING ARDUINO
by EDISON SCIENCE CORNER in Circuits > Arduino
531 Views, 16 Favorites, 0 Comments
LED HOURGLASS USING ARDUINO
In ancient times, people relied on an hourglass as a simple yet effective tool to measure the passage of time. The hourglass is made up of two glass bulbs connected by a narrow neck, through which sand flows steadily from the upper bulb to the lower one. The duration of the sand flow was usually fixed—often about an hour—which is why it came to be known as the hourglass. This timeless device symbolises the continuous flow of time, and even today it is admired for its simplicity and elegance. Inspired by this traditional concept, in this tutorial, we will recreate the same idea in a modern way by building a digital hourglass using Arduino, where electronic components will replace sand and glass to simulate the passage of time in a creative and interactive form.
Supplies
- Arduino (Uno / Nano / Pro Mini) — 1
- ADXL335 breakout board — 1
- 8×8 LED matrix + MAX7219 module — 2
- 3.7V Li-ion battery — 1
- Charger+Booster Module — 1
- button switch - 1
- Wires
- 3D printed frame parts
Arduino (the brain)
The Arduino is the central controller for the digital hourglass: it reads the accelerometer, runs the “sand” animation, and talks to the LED drivers. I chose Arduino because it provides plenty of digital I/O, easy-to-use libraries, simple power and USB programming, and a huge community — perfect for a beginner-to-intermediate build. You can use an Uno, Nano, or a Pro Mini .
ADXL335 3-axis analog accelerometer (orientation sensor)
The ADXL335 gives you raw X, Y and Z analog voltages that correspond to the sensor’s orientation. For a digital hourglass, we just need to know which side is “up,” so the ADXL335 is a simple, low-cost choice that’s easy to read with analogRead() (No I²C required). It’s also tolerant of hobby-level wiring and works well mounted directly to the frame.
Two 8×8 LED matrices driven by MAX7219 (the sand displays)
To represent sand visually, we’ll use two 8×8 LED matrices — one representing the top bulb and one for the bottom. Each matrix is driven by a MAX7219 IC, so we only need three control pins (DIN, CLK, CS/LOAD) to control each module and can also daisy-chain them (data out of the first into the second). The MAX7219 handles multiplexing and brightness control for you, so you get crisp animations without manually time-multiplexing rows. You can animate falling grains by lighting pixels, moving them downward over time, and using the MAX7219 intensity register to tweak the visual “weight” of the sand.
3.7V Li-ion battery charger + 5V booster
A single-cell 3.7V Li-ion battery charger+ booster is a compact choice. Because the Arduino + MAX7219s usually want 5V. So we charge the battery and boost the voltage to 5v with the same module, such this way we can decrease the size
How the Parts Work Together (conceptual)
- The ADXL335 senses which bulb is currently “up.”
- The Arduino reads the accelerometer, decides which matrix is the top and which is the bottom, and starts the sand animation accordingly.
- The MAX7219s receive frame data from the Arduino and show falling pixels. When you flip the hourglass, the Arduino detects the orientation change and reverses the animation, simulating sand moving from the new top matrix into the bottom matrix until one empties and the other fills
CIRCUIT DIAGRAM
Arduino → MAX7219 (first LED Matrix)
- DIN → D5
- CLK → D4
- CS/LOAD → D6
- VCC → 5V
- GND → GND
MAX7219 (first Matrix) → MAX7219 (second Matrix)
- DOUT → DIN of second matrix
- CLK → CLK
- CS/LOAD → CS/LOAD
- VCC → VCC
- GND → GND
ADXL335 → Arduino
- X → A1
- Y → A2
- VCC → 5V
- GND → GND
You can download the circuit diagram from here
SOLDERING
I soldered the X and Y output pins of the ADXL335 accelerometer to the A1 and A2 analog pins of the Arduino Nano, while the VCC and GND pins of the sensor were connected to the 5V and GND pins of the Nano. The two 8×8 LED matrices with MAX7219 drivers were daisy-chained together, and I soldered their DIN, CLK, and CS pins to the Nano’s D5, D4, and D6 digital pins, respectively, along with their VCC and GND lines to 5V and GND. For the power supply, I connected a 3.7V Li-Po battery to the IP5306 base booster and charging module, and from there soldered the 5V and GND output pins of the module to the Arduino Nano to power the entire circuit.
3D Printed Encloure
I designed the enclosure using tinkercad and printed the files using my BambuLab A1 printer with PLA. You can download the files from here
Arduino Programming
here i am explaig how the code works. by the way you can download complete code from here .
Included Libraries
Matrix Indexes
You have two MAX7219 matrices.
They are addressed as 0 and 1, named here for convenience.
Accelerometer thresholds
These values decide which direction the hourglass is tilted
(using analog readings from the accelerometer).
Pin assignments
Pins for matrix, accelerometer, and buzzer.
Other settings
Global variables
- delayHours, delayMinutes – when a particle should fall
- gravity – current device orientation
- lc – LED matrix controller
- d – timing controller for particle drop
- alarmWentOff – prevents alarm from repeating
Drop timing
Returns the time (in seconds) between falling "sand" particles.
Debug Matrix Printer
Only used when DEBUG_OUTPUT == 1
Prints the full LED matrix contents on serial monitor in a grid format.
Helper coordinate functions
These convert (x,y) to adjacent positions:
Used for particle movement simulation.
Movement Permission Logic
These check whether a particle can move:
Conditions include:
- Boundary check (edges)
- Whether the target LED is empty
- Whether sideways paths are clear
Movement functions
Actually move the particle by clearing old LED and lighting the new one:
Counting particles
Counts lit LEDs on a matrix (top or bottom).
Useful to check when the top matrix becomes empty → trigger alarm.
Main particle simulation
- Checks if LED (pixel) exists
- Randomly decides to move left or right if both possible
- Falls downward if possible
- Returns true if moved, otherwise false
This is the core sand movement physics.
Filling the hourglass
Fills the matrix in a diagonal (hourglass shape) pattern with a fixed number of pixels.
Gravity Detection
Reads accelerometer:
- 0° → upright
- 90° → left tilt
- 180° → upside down
- 270° → right tilt
Used to rotate matrices so the "sand" always falls correctly.
Direction-based matrix selection:
Decides which matrix is "top" based on tilt.
Reset hourglass
- Clears both matrices
- Fills the top matrix with 60 particles
- Resets the drop timer
Update matrix (physics engine)
Runs the particle movement algorithm:
- Sweeps through all pixels diagonally
- Attempts movement on both matrices
- Randomizes left/right sweep direction
- Returns true if any particle moved
Drop particle between matrices
When the timer expires:
- Drops one pixel from the top to bottom
- Makes beep when particle drops
- Handles two orientations: 0° & 180°
- Returns true if a pixel was transferred
Alarm
When the top matrix becomes empty:
- Plays 5 beep sounds, 1 second apart
Setup
Main loop
ASSEMBLY
After uploading the code, I placed the circuit inside the 3D enclosure and finished the project
Final Look
Video Tutorial