Use mBot with App Inventor


A new version (V1.9) has been released! It’s easier to use, especially in environments with multiple robots. Take a look now.
MIT App Inventor is a drag-and-drop block-based editor which can make Android Apps. You can use App Inventor to control mBots through an extension.

Add the mBot extension to App Inventor

You need an App Inventor website that supports extensions. One example is Login and start a new project.
In the “Extension” group of the left panel, click “Import Extension” link, then select “URL”. Paste the following linke to the text box:
Then click “import”. 
In the next screen, click “OK”. Then You will find a new “mBot” component in the “Extension” group:
Screen Shot 2016-05-23 at 3.32.35 PM

Connect to your mBot through a ListPicker

Drag a ListPicker component to the canvas, and add a mBot component (it is a non-visible component, won’t shown up in the phone screen but will be at the bottom of the phone screen):
Write a program like the following picture using blocks from ListPicker and mBot. When run, this will create a list of paired mBot robots (you need to link the mBot with the Android system’s Bluetooth setting screen at first use), and allow users to select and connect to one of the robot.
Screen Shot 2016-05-23 at 3.26.48 PM

Write Programs with App Inventor

When connected, you can control mBot and read from its sensors with any of blocks provided by the mBot extension. The following program is an example:
Screen Shot 2016-05-23 at 3.26.58 PM
Here is a list of blocks you can use to write your program:
 Screen Shot 2016-05-23 at 3.37.55 PM Make the robot move forward at a certain speed (number of 0-255)
Screen Shot 2016-05-23 at 3.37.59 PM Make the robot move backward at a certain speed (number of 0-255)
Screen Shot 2016-05-23 at 3.38.02 PM Make the robot turn left at a certain speed (number of 0-255)
 Screen Shot 2016-05-23 at 3.38.05 PM Make the robot turn right at a certain speed (number of 0-255)
 Screen Shot 2016-05-23 at 3.38.08 PM set the speed of both motors (0-255) of the connected mBot. This is for advanced control
 Screen Shot 2016-05-23 at 3.38.19 PM Make the mBot stop moving
 Screen Shot 2016-05-23 at 3.38.12 PM light up the mBot’s on-board RGD LEDs with a certain color.

“whichLight” field accept a number: (0: both lights, 1: right light, 2- left light).

 Screen Shot 2016-05-23 at 3.38.16 PM Play a musical note using the internal buzzer of mBot.

duration is in milliseconds, and frequency is for the pitch.

 Screen Shot 2016-05-23 at 3.38.21 PM read the value of the lightness sensor.
 Screen Shot 2016-05-23 at 3.38.25 PM read the value of the ultrasonic sensor. Usually connected to port 3.
 Screen Shot 2016-06-22 at 6.30.50 PM read the value of the temperature sensor (in Celsius degrees).
 Screen Shot 2016-06-22 at 6.29.57 PM read the value of the humidity sensor (in percentage).
 Screen Shot 2016-05-23 at 3.38.32 PM get a list of available mBot robots. Used in Bluetooth connection
 Screen Shot 2016-05-23 at 3.38.35 PM connect to a mBot with the certain address,

usually an item from the “availableRobots” list.


Posted on