LED Hour Glass

3,512

60

15

Introduction: LED Hour Glass

In this article I describe how we made an hour glass with leds as the sand. We were always interested in making something that visually flows like sand and decided to use an hour glass to start. The movement is not completely fluid given the resolution of the amount of pixels, but it does resemble sand falling down and reacts to tilting and orientation changes. Keep reading and watch the video to find out how we did it!

Supplies:

  1. ws2812b led strip - https://amzn.to/38W7uPt
  2. 5v power supply - https://amzn.to/38TTplk
  3. MMA8451 accelerometer - https://amzn.to/39JJVsb
  4. arduino (I recommend the esp8266 but I used a mega) - https://amzn.to/2XQtnsP

Step 1: Make What Will Be the Frame of the Hour Glass

We used some leftover scrap wood to make the frame for the hour glass. The ends of both the top and bottom pieces of the frame were cut at 37.5 degrees each and the other 4 pieces that made the left and right sides were cut at 37.5 degrees on one end and 15 degrees at the other. The end that was 37.5 degrees was joined with the piece that made up the top/bottom of the frame. This made a 75 degree angle that formed the inside of each corner of the hour glass (37.5 + 37.5 = 75). This meant that we were 15 degrees from 90 on each end, which is why we cut the other end of the 4 side pieces to 15 degrees. This made the seem that connected each half of the hour glass completely flat. After we glued up the frame we used it as a template to cut the backerboard which will hold the leds.

Step 2: Add the Leds to the Backerboard

In this step we added horizontal strips of leds to the backerboard. The highest row had 8 leds while each row lower was 1 less in value up to 3 leds. Then we had a center led that was a single led before going to 3 leds for the start of the row in the other half of the hour glass. We connected each row in a snaking pattern to maintain the data path of the ws2812b led pins. We used hot glue to secure each connection, and made sure to test the connections out before securing with hot glue to ensure we didn't have to rip it out and try again.

Step 3: Make the Circuit

The next step is to make the circuit. Following the circuit diagram connect the 5v power supply to the arduino and led strips. Make sure to also connect the accelerometer to the sda/scl pins of the arduino. This is important to note: The starting orientation of your accelerometer matters. If you hook yours up in a different orientation than we do, then you'll need to modify the code to ensure you are using the correct boundary numbers when rotating the hour glass.

Step 4: Finish Up the Structure of the Hour Glass

Now that the electronics are hooked up, go ahead and finish gluing/sanding/applying finish to the structure that is your hour glass. If we were to make this over again, we would definitely make the border thicker. We used some leftover strips of purple heart wood as the border but we would definitely use a thicker border that can hold the power supply and the other heavy electronic components upright when just standing there.

Step 5: Apply the Code

Repository: https://github.com/tmckay1/led_hour_glass/tree/mai...

Not to go into too much detail of the code, we'll outline the basic design of the hour glass. We have a cycle that occurs in code which is the completion of 1 frame of an animation. So a cycle in our case is the grain of sand dropping and piling up on the bottom while losing a grain from the top. Each cycle has 6 frames of animation. The first frame is the top piece of the hour glass dropping off and filling the center of the hour glass. The second to fifth frames are the sand dropping from each row there after, and the last frame (sixth frame) we add an led to the bottom of the hour glass to increase the count.

Now on each iteration of the arduino loop, we read the current coordinates of the accelerometer and determine the y-direction of the hour glass (if we are up, down, or horizontal), and the tilt direction (tilted left, right, or completely upright with no tilt). Based on the orientation from reading values in the accelerometer, we will either animate the sand dropping down or not. When tilted we draw the sand tilted to the side, otherwise we draw it dropping upright. To determine how to draw the leds based on the tilt, we have 4 different structure arrays that dictate how the shape will look based on the number of leds each half has.

There are 4 structure arrays and there can be no more on an arduino Mega due to memory issues. If you use a esp8266 you could add even more structures. The structures are: dropping sand from the top and animating the pile losing an led, accumulating sand on the bottom upright, accumulating sand on the bottom tilted right, and accumulating sand on the bottom tilted left. You can try and be clever and make even more structures by computing the coordinates on the tilted side, but you will run into overflow issues and the animation will be garbled. I recommend just using an esp8266 if you'd like a better fps animation.

Step 6: That's It!

The code assumes you start out in a straight upright position, so after uploading the code, enjoy!

Be the First to Share

    Recommendations

    • Pi Day Speed Challenge

      Pi Day Speed Challenge
    • Trash to Treasure Contest

      Trash to Treasure Contest
    • Microcontroller Contest

      Microcontroller Contest

    15 Comments

    0
    JeffS340
    JeffS340

    Tip 5 weeks ago

    Really slick little project. If I make this, I will absolutely be making one slight modification - adding battery power and a wireless charger, something like a pair of 18650's with a voltage regulating circuit to provide the +5V for the Arduino and LED's. I just think this would be the so cool to have sitting on my mantle resting on (the hidden wireless charger) and when it is picked up, it would still have ample charge for some fun.

    0
    tmckay1.jackson
    tmckay1.jackson

    Reply 4 weeks ago

    Yeah that would be really cool, we opted for a beefy 5v power supply because it's what we had on hand and wanted to prototype it but if you did it yourself you only need those

    0
    jonahlait
    jonahlait

    Question 5 weeks ago

    Could you drill holes through a board and have single ws2812b leds shining through the holes so you don’t see the connector strip?
    This would mean a lot more leds closer together so it becomes more fluid.
    Would there be room in the memory of the mega to add lots more?
    Would adding more leds affect the coding? (Say bottom row of 14 counting down)
    Good idea though!!

    0
    tmckay1.jackson
    tmckay1.jackson

    Answer 4 weeks ago

    I think you probably could hide the wires with adding another layer of backerboard and holes but would have to be careful of not breaking the connections depending on how you adhere them. If you wanted one layer with holes and the leds on the back of that, probably but it would be very annoying to setup lol. You really don't have much more room on the mega for more leds, I would suggest the esp32 or esp8266 for that, the coding would be minimally affected you'd only have to change the indexes of the leds in the top half and bottom glass to match your use case. The code should work from there on. Thanks :)

    0
    JohnW51
    JohnW51

    5 weeks ago on Step 6

    Really, really cool, guys!! Congratulations on a unique (as far as I know) and very innovative design. Y'all rock!

    0
    tmckay1.jackson
    tmckay1.jackson

    Reply 4 weeks ago

    Thank you!

    0
    ap0ught
    ap0ught

    5 weeks ago

    Could you fit animations in memory by only animating half of the hourglass and playing the animation backwards on the other half?

    0
    tmckay1.jackson
    tmckay1.jackson

    Reply 4 weeks ago

    We actually tried that and we were running so tight on memory with the 4 structs (top dropping middle, top left and right dropping, bottom middle accumulating, bottom left and right accumulating) that used 93% of available memory, that when we tried to calculate the inverse positions of the structs we actually filled all memory in the microcontroller and started overwriting the values of variables stored in memory. So it didn't work

    0
    gmlowton
    gmlowton

    6 weeks ago on Step 1

    Bloody good stuff.

    0
    gmlowton
    gmlowton

    Reply 5 weeks ago

    Do they, the Gods of the site, write this puerile "be nice children with your'e comments about other's?" constantly?

    16116538724603735302745109664919.jpg
    0
    SparkBark
    SparkBark

    6 weeks ago

    Wow, that is really cool!