Welcome Your IET account
Microbit dead reckoner on arm of Neil Downie

Lockdown Challenge: Where’s the buried treasure?

Image credit: Neil Downie

Lost in a town centre or shopping mall with no GPS signal? Searching for buried treasure on a desert island? “ARRRH Jim Lad, no problem”, as Long John Silver might have said, “just count steps and look at your compass”. Neil Downie’s project this week is to always be able to know your position – dead reckoning – using a Microbit.

Lockdown Challenge #37: The Dead Reckoning Microbit

Ever since humans have got lost at sea or lost their buried treasure, there have been dead-reckoning methods. You count your steps or measure how fast your boat went and for how long. But to know where you are, you don’t just need how far, but in what direction too: it’s not just step-counting, it’s vector step-counting!

At each step, instead of simply adding one to a counter, you add sin(bearing) to the X-counter and cos(bearing) to the Y-counter. At bearing 0°, then each step adds 0 to the X-counter and 1 to the Y-counter. At 45° then each step adds 0.707 to the X-counter and 0.707 to the Y-counter. And at 90° then each step adds 1 to the X-counter and 0 to the Y-counter. Each step potentially has a different sin and cos factor, making it tough mental arithmetic!

But you can do it easily with a Microbit, credit-card sized computer. These bristle with sensors, are simple to program, and have a built-in display. There is a drag-and-drop program editor for them called MakeCode which produces code like a flow diagram, making it easier to figure out how a program works. Schools had a million of them, and Microbits are easy to buy for about £12. You also need a double AAA battery pack with a plug-in lead and a USB-USBmicro lead to connect to a PC.

It’s worth starting by making a step-counter out of the Microbit, so you can tune up that bit of code. There are several step-counter designs from microbit.org and elsewhere, but here is one we tried:

Screenshot of the microbit process

Image credit: Neil Downie

You could just press a button at each step, or put a microswitch in your shoe or something. But probably better is to use the accelerometer built into the Microbit to automatically detect steps.

If you walk along with the Microbit held horizontal in front of you can detect a step is done by a peak of z-acceleration (up-and-down) of more than, say, 180milli-g. But the Microbit might not be horizontal, so it is better to use the acceleration magnitude rather than z-acceleration. And you must subtract gravity g, 1000 milli-g, from the magnitude. The other little trick is that you want to count steps, nothing faster: the 400ms pause controls that.

Microbit dead reckoner on Neil Downie's arm, close up

Close-up of the microbit on Neil Downie's arm.

Image credit: Neil Downie

Step Counter working? Now move on to the Vector Step Counter…

The simple bits first: when you switch on the ‘on start’ code runs: mostly setting things to zero. You also need to zero things when you start each leg of your navigation: that’s on ’button A’. Then you need ‘button B’ to read out where you have got to in X and Y direction. And ‘button A+B’ can read out other things, like how far you got.

Now some maths. The sin and cos function use radians, mathematicians’ favourite angle measurement, not the ancient Babylonian 0-360 degrees used in compass bearings. Multiply degrees by 0.01745 (2π/360) to get radians. Sin and cos are not immediately available on the Makecode editor: put ‘sin’ or ‘cos’ into the Search box above the usual functions and they pop up. Finally, the LED graph on your steps tells you the program is working.

The compass built into the Microbit needs calibrating. The ‘calibrate compass’ command does that. It puts on the screen instructions to tilt the Microbit in different directions. Once you have done that you can start marching around and see how well your Dead Reckoner works.

Can you find your way to the same spot via different routes and get the same x and y? When you go back to where you started, does everything go back to about zero? What about making your Dead Reckoner give the position in metres and speed? And finally, you could record data onto a PC or phone and plot your course – wiggles and all – onto a chart.

Screenshot of the microbit process 2

Image credit: Neil Downie

If you liked this, you will find lots more fun science stuff in Neil Downie’s books, like ‘The Ultimate Book of Saturday Science’ from Princeton University, and for lots of other things (and a free copy of the ‘Exploding Disk Cannons’ book), visit www.saturdayscience.org

There is also the back catalogue of Lockdown Challenges from 2020 to choose from if you are looking for more options. The IET also has a host of resources that adults can use to engage children with the world of STEM.

Sign up to the E&T News e-mail to get great stories like this delivered to your inbox every day.

Recent articles

Info Message

We use cookies to give you the best online experience. Please let us know if you agree to all of these cookies.

Learn more about IET cookies and how to control them