App Inventor + Iot: Flying Bees With BBC Micro:Bit Magnetometer Sensor
App Inventor + Iot: Flying Bees With BBC Micro:Bit Magnetometer Sensor
Level: advanced
This tutorial will help you get started with App Inventor + IoT and
the magnetometer sensor on a BBC micro:bit controller. By
shaking or put a small magnet around the micro:bit, you will see
the bee icon on your app is flying.
source .aia
Hardware
You only need one BBC micro:bit to get started with this project.
The remaining steps all build off of the starter code for Basic
Connection tutorial and its .aia source code.
Designer
First, we need to add the necessary extension.
● In the Palette window, click on Extension at the
bottom and then on "Import extension" and click on
"URL".
○ Paste micro:bit extension URL:
http://iot.appinventor.mit.edu/assets/com.bbc.mi
cro:bit.profile.aix
● Add a Microbit_Magnetometer extension to
your app by dragging it onto the Viewer, set its
BluetoothDevice to "BluetoothLE1"(Don’t
forget!).
Let’s add more components to our app to read the magnetometer
status.
● From the Drawing and animation drawer in the
Palette, drag in a Canvas and an ImageSprite.
Set Canvas’s height to 320 pixels, width to fill
parent (or any size you like).
• Set ImageSprite’s Picture to some cute
image (no bigger than the canvas).
● Add four Label to show Magnetometer’s X, Y, Z
axis and bearing value.
After some adjusting, your designer should look similar to this. It
doesn’t have to be exactly the same. Feel free to modify the
component’s background color, position and text size.
Blocks
We would like to control ImageSprite’s heading by the Z-axis
movement of magnetometer on micro:bit controller. Let’s begin:
(From https://makecode.microbit.org )
Tips
Your app should now be working! Make sure you have paired the
Bluetooth on your Android device to your micro:bit. Then test it out
by connecting your micro:bit device using the MIT AI2 Companion
(if you haven't already) or installing it by .apk. Try to shake or flip
around your micro:bit or have a small magnet (not too strong or it
may influence your device!) point toward it, you should see the App
Inventor logo turning and turning!
Brainstorming
1. Try to add more cute movement into your app, for example,
you can use X and Y axis values to make ImageSprite move
left and right and show something when it bumps the edge of
the Canvas. (Refer to our Micro:bit button tutorial).
2. Add some sound effects when the magneto sensor value
have exceeded certain level.