Assignment 4: More Arduino

Objective: create a digital hourglass with LEDs instead of sand.
Time: 1,5 hour
  • Arduino Genuino Uno
  • Other electrical parts:  
    10 kilohm resistor
    six 220 ohm resistors
    six LEDs
    tilt switch(wires, bread board, push buttons, etc.)
  • Software: Arduino IDE
  • Recommended: Arduino Starter Kit

I decided to play around more with Arduino by doing an interesting project from Arduino Starter Kit: Project 8 Digital Hourglass. Like a real hourglass the digital hourglass would notice when it was being tilted and, after that, slowly turn on each of its 6 LEDs to represent the sand that would shift.


In order to make this work we had to know when the hourglass was being tilted. That is why for the first time I had to use a tilt sensor. This sensor notices when you move the Arduino. It is like a simple, inexpensive version of an accelerometer with a small metal ball inside that you hear when you tilt the Arduino up and down.

The circuit that we built looked like this (source: here).

Circuit with 6 LEDs connected to the power and ground


In the code I also learned how to deal with time. This could be done with the millis() function that keeps track of the time that the Arduino has been running in milliseconds. The book explained that, to hold the data of the millis() function, I needed the long data type instead of an int or double. With the latter types I would risk that we could not hold any more numbers and that after a short time, the function would stop counting.
Also, I had to change the interval of the hourglass in the code. In the original code the hourglass would last for up to 1 hour and would thus turn on a LED (every 10 minutes (600.000 milliseconds). I did not have time for this and thus changed the variable interval to 1 minute (60.000 milliseconds).
The full code including comments could be found here.


I could not add any video here, so this documentation will have to do with the following picture:


Final result

Publié dans Uncategorized