We are going to explore our environment by using the temperature sensor, light sensor and compass on the micro:bit.
How to: - Use the shake function.
- Display a number on the LED matrix.
- Use the temperature sensor.
- Use the button function.
- Use the if/else conditions.
- Use comparison operators.
- Display patterns on the LED matrix.
- Clear the LED matrix.
- Use the compass.
- Use the light sensor.
- Within your favourite browser (we recommend Google Chrome) go to python.microbit.org and press Enter . This will load the Python coding editor.
- Delete the text on lines 6, 7 and 8 .
- From line 6 type the following code:
We can now sense the temperature of the room you are in by shaking the micro:bit.
- From line 8 type the following code. Make sure your cursor is positioned under the if on line 6 .
We can now use the micro:bit to detect if it’s light or dark within a room by pressing the A button on the micro:bit.
- From line 14 type the following code making sure your cursor is under the if of line 8 .
We can now see what the compass baring of the direction the micro:bit is facing by pressing the B button on the micro:bit.
We are now ready to download the code to our micro:bit so we can go out and sense our environment.
- Take the micro USB cable and connect the micro:bit to the computer.
- Click on Connect . Click on your micro:bit and click Connect again.
- Click Download .
Now that you have downloaded the code to your micro:bit attach a battery pack to your micro:bit and go and sense your environment.