Introduction
The Bit Board Tank can take advantage of the built-in sensors found on the micro:bit, and we can use microphone to "remotely control" the Tank so it moves when it detects sound.
You might also want to check out our Tank - Light Activated guide which lets you control your Tank with a flashlight.
Tools
Parts
Video Overview
-
-
For this guide you'll need a completed Tank Main Body.
-
You'll also need something to make sound! It could be your own voice, or a classroom full of clapping students.
-
You can also use a speaker playing a sound. (A Bluetooth speaker connected to a mobile phone or tablet works great.)
-
-
-
We're going to load the following code for our Tank Sound Detecting Simple program: https://makecode.microbit.org/_VbuMij5FX...
-
Note: This version of the code is a great starting point for this project. If you want to take it further examine the code for the Tank - Light Detecting Turner and consider using it for a starting point.
-
When you power on the Tank it will start moving while it runs a calibration routine to check for sound levels. (We'll cover the calibration in Step 3.)
-
Once the calibration is done the Tank will sit there waiting for the sound levels to go above the threshold that was set in the calibration routine...
-
-
-
We need to calibrate the sound levels in the room before the micro:bit can tell if there is a sound.
-
The sound level can be anywhere between 0 and 255. (0 is very quiet and 255 is very loud.)
-
Our code takes 10 readings (with a slight pause between each reading) adds them all together and the divides by the number of samples (10 in this case) to get our final value.
-
Calibration routines often use this sampling technique where a number of values are captured and then the average of them is used.
-
Once we've calculated our ambient sound level we pad the number a bit to prevent false triggering. We used 35 for our pad value in this example but you can experiment with lower (or higher) values.
-
-
-
Power on the Tank, and either set it down so it can roll, or hold it in your hand so the treads can move freely.
-
Do your best to be quiet and wait for the calibration to complete. Once the heart stops flashing on the micro:bit and you hear a second beep, the calibration should be done.
-
The Tank should be still when the room is quiet, so... Make some noise! Clap, yell, laugh... See if you can get the Tank moving.
-
You can make the Tank stop by being quiet. (Shhh!)
-
-
-
The code provided should serve as a starting point for your own ideas about how the Tank can react to sound.
-
You could program a sequence of movements and then try to control them by making sounds.
-