# Arduino Hourglass

I saw a nice digital hourglass on instagram Which i decided to build for myself.

## The 3 axis accelerometer The accelerometer gives a value for X, Y and Z (we don’t use Z), which I normalise

``````  x_adc_value = analogRead(x_out) - x_range_mid;

``````

and convert into an angle

``````  theta = round( atan2 (y_adc_value, x_adc_value) * 180/3.14159265 );
if(theta < 1) theta += 360;

``````

and assign an orientation of the device

``````  // these are reversed
if(theta < 22.5 or theta > 337.5) quadrant = D_NORTH;
else if(theta < 67.5)             quadrant = D_NW;
else if(theta < 112.5)            quadrant = D_WEST;
else if(theta < 157.5)            quadrant = D_SW;
else if(theta < 202.5)            quadrant = D_SOUTH;
else if(theta < 247.5)            quadrant = D_SE;
else if(theta < 292.5)            quadrant = D_EAST;
else                              quadrant = D_NE;
``````

## The finished product ## The code

https://github.com/SachaWheeler/hourglass

Written on September 22, 2018