Part 3 – Some Maths

Or should that be “Some Math”? But I am from the UK!

As explained on the BBC Micro:bit MicroPython pages, overall acceleration can be calculated using Pythagoras’ rule here (under Advanced Functions).

To recap, if you just had accelerations along two dimensions (the x and y axis say),

the overall acceleration can be found using the equation:

Similarly, if the acceleration is in the three dimensions, (x, y and z axis), the overall acceleration can be found using the equation:

In python, the code looks like this:

If we subtract 1000 from the z-value (to remove the effect of gravity) and use the python function round( ) to round the number down (and remove the decimal places *)

we now find that the overall output (“sum:”) is consistently between -1 and 7 when the device is left resting on the table. If you hit the table, the acceleration will change. If I move the device up and down, then I can see the numbers change on the screen, and they go upto 800.

It is hard to see the exact link between how fast you start to move the micro:bit and the numbers on the sceen, especially with a short connecting lead as I have. Finding a way of displaying this information will be looked at next time.

* strictly speaking rounding numbers down might be a small inaccurracy, but we can ignore this at the moment

Micro:bit to the Moon is Storm Educational’s contribution to helping children be interested in coding/STEM. Code can be freely downloaded, adapted and used. But if a school could mention our software for primary/elementary students we would be very grateful (with free online demos at

Leave a comment

Your email address will not be published. Required fields are marked *