With a spirit level, for example, you can determine whether a picture or a shelf is hanging straight. When laying tiles on a terrace, an inclination must be taken into account so that rainwater can drain off properly. The Calliope mini with its position sensor can be programmed as a sensitive spirit level.


The program sets the variable for the value of the inclination around the x-axis. The rotation around the vertical axis is measured. If the Calliope mini is applied horizontally, the value is 0. If you tilt it to one side, you get positive values, if you tilt it to the other side, you get negative values.

If the value for the inclination is less than -20°, e.g. -25° or higher than 20°, then the inclination is too big and the LED turns red. Otherwise, it will be green. To make the decision based on a comparison, the absolute value is calculated from the angle of inclination. The absolute value is always positive for both negative and positive numbers. So -20 becomes 20.

Block get angle compass sensor: If y is selected instead of x, the position sensor determines the value of rotation around the other axis.


Task 1: Determine the numerical values when the Calliope mini is on its back and rotated just a little out of the horizontal panel.

Task 2: Change the program shown above so that the LED changes color as it rotates around one axis.

Task 3: Combine the two programs so that the LED only lights green if there are no deviations of 20° in both the x and y axes.

Pro Task: 20° are very coarse for a spirit level. Introduce a new variable "sensitivity", which is assigned the value 2, for example, and is included in the comparison commands. The spirit level should turn red if the deviation from the horizontal level is much smaller.

This text is published under a CC BY-SA 3.0 DE license. It was originally published in German by Karsten Beuche and translated into English by the Calliope team.