Automatic Hourglass – Arduino

Probably many of us have a small gadget in the house like hourglass. Unfortunately, it usually serves at most as an ornament because nobody wants to rotate it. I received this type of toy a long time ago and it layed on the shelf for a long time until I automated its rotation with just a few electronic components.

 

Components required for the construction:
 
1x board to chop (I used a cardboard from old anti-frame)
1x atmega 328P-PU
1x servo (I used MG90S)
1x 9V battery
1x battery basket 9v
1x LM7805 voltage regulator
2x 22nf capacitor
1x 470uF capacitor
1x 16 MHz quartz resonator
1x universal plate
Some cables
 

At the beginning, we measure our hourglass and cut out pieces of the box from our piece of wood. In addition, we cut two plates. One larger than our box on which the servo will be placed and the second plate of size that would fit the electronic scheme on it, we glue it together with a decent wood glue. For me it looked like this:

box size

box size

The most interesting part is electronic schematic. This scheme looks as follows:

servo schematic

The basis of the project is standalone Atmega 328P-PU microcontroller, which you can read about connecting at this address https://www.arduino.cc/ en / Main / Standalone To rotate our hourglass, we need servo. My servo can make turns from 0 to 180 degrees. Its connection is easy it has three cables 5V, GND and data. The pin for data can be arbitrary in our case it is pin 15. Project must be connected to power supply. Personally, I used the 9V battery. All components are working on 5V and becouse of that I had to use the LM7805 voltage regulator. The regulator has 3 feet. The first pin on the left (from the side where there is no plate) is the input (9V) the second pin is ground and the third pin is the output (5V). At the output, a capacitor of 470uF is added in parallel. When starting the servo it takes a lot of power which can lead to a sudden unplanned servo movement. Thanks to the capacitor, it does not happen.
 
After soldering it looks like on the pictures below:

soldering servo

soldering servo2

soldering servo3

soldering servo4

soldering servo5

In the meantime, we can paint wooden constructions. Finally, we need to upload the appropriate program to our microcontroller:
 

#include <SoftwareServo.h>

SoftwareServo myservo;
#define pinServo A0
boolean refresh = true;

void setup()
{
  myservo.attach(9);
}

void loop()
{

  for (int pos = 0; pos <= 180; pos += 1) {
    myservo.write(pos);
    delay(15);
    if (refresh) SoftwareServo::refresh();
  }

  delay(50000);


  for (int pos = 180; pos > 0; pos -= 1) {
    myservo.write(pos);
    delay(15);
    if (refresh) SoftwareServo::refresh();
  }

  delay(50000);
}

The code itself is not a heavy one, we use the SoftwareServo.h library to initialize the input 9 to which our servo is connected. Each for loop turns our servo one step. After 180 degrees, we wait 50 seconds for the hourglass content to fall down.
 
The whole project looks like on a movie:
 

 
If we have a little time, we can think of some interesting design such as:

design1

design2

design3

Source code:
servo

2 thoughts on “Automatic Hourglass – Arduino

Leave a Comment

WordPress Video Lightbox Plugin