About: Learn electronics and Arduino with Tinkercad Circuits!

The following information is a single lesson in a larger project. Find more great projects here.

Project Overview:

In this project, you will build a clock that turns an LED on every ten minutes. The clock uses the Arduino Uno's built in timer. Reset the clock the same way you would reset an hourglass: by tilting it back and forth!

Step 1: Project Description

In this project you'll build a digital hourglass that turns on an LED every ten minutes. You will know how long you're working on your projects by using the Arduino's built-in timer. Reset the timer using a new component: the tilt sensor.

In the circuit diagram below, notice that the tilt sensor is hooked up to a digital pin. This is a binary switch: it is either tilted in one direction to turn it on, or tilted the other way to turn it off.

The LEDs are all connected to their own digital pin, in a bar graph arrangement. This should look familiar! You used a similar circuit layout in The Love-o-Meter.

  1. Continue to the next step.

Step 2: Bill of Materials

You will need the following electrical components for this project:

1 tilt sensor

6 LEDs

6 220 ohm resistors

1 10 k-ohm resistor ...and of course your Arduino Uno and a breadboard!

If you are using the Arduino kit, you might want to disconnect your project from the computer so it is easier to tilt! In that case, you will use a 9V battery and adapter as a power source.

  1. Can you match each component on the list to its location on the breadboard?

  2. Continue to the next step.

Step 3: Keeping Track of Time

Previously, when you’ve wanted something to happen at a specific time interval with the Arduino, you’ve used the delay() function. However, it causes a couple of problems for our current project:

When the Arduino calls delay(), it pauses the whole program for the time of the delay, preventing any new inputs and outputs from happening.

Delays are also not very helpful for keeping track of actually elapsed time.

The millis() function helps to solve these.

  1. millis() keeps track of the time your Arduino has been running in milliseconds. We call this the total elapsed time since the start of the project.
  2. Any input or output can be used while millis() is running!
  3. Continue to the next step.
  4. Stuck? HINT: You may have seen this before if you did the Light Theremin project.

Step 4: Large Numbers

So far you’ve been declaring variables with datatype int. An int (integer) is a 16-bit number, so it holds values between -32,768 and 32,767. Those may be some large numbers, but if the Arduino is counting 1000 milliseconds in one second, you’d run out of space in less than a minute! We need at least an hour.

Let's use the datatype long instead.

  1. The long datatype holds a 32-bit number instead (between -2,147,483,648 and 2,147,483,647).
  2. How does this relate to counting time in milliseconds? Since you can\u2019t run time backwards to get negative numbers, the variable to store millis() time is called an "unsigned long," meaning it only stores positive numbers. This allows you to count even higher! An unsigned long can count up to 4,294,967,295. That\u2019s enough space for milis() to store time for over 4 million seconds, or almost 50 days. That's clearly more than enough time for this project!
  3. Continue to the next step.
  4. Stuck? HINT: "Unsigned long" means that millis() does not store values with a negative sign! It stores numbers from 0 to 4,294,967,295 instead of from -2,147,483,648 to 2,147,483,647.

Step 5: Tilt Switch

When you turn your hourglass over, a tilt switch will change its state between HIGH and LOW, and that will set off another cycle of LEDs turning on.

The tilt switch works just like a regular switch, but it is an on/off sensor. What makes tilt switches unique is that they detect orientation.

  1. Typically they have a small cavity inside the housing that has a metal ball. When tilted in the proper way, the ball rolls to one side of the cavity and connects the two leads that are in your breadboard, closing the switch. You’ll use it in this project as a digital input.
  2. Find the tilt sensor in the Components + menu (All Components tab) for more information.
  3. Continue to the next lesson to learn how to set up the Digital Hourglass circuit!

Next Lesson:Setting Up the Circuit



    • Warm and Fuzzy Contest

      Warm and Fuzzy Contest
    • Epilog X Contest

      Epilog X Contest
    • Remix Contest

      Remix Contest