It is possible to communicate serially with the mBot once a program has been updated to the board. Serial communication can be via USB, 2.4GHz or Bluetooth. To communicate serially, you need to select the “Communication” extension from the Extensions menu:
Once this is selected, you can go to the “Robots” scripts, scroll down to the bottom and you will find the communication blocks. You might need to click “Show Extension”:
The communication blocks look like this:
Communication between your robot and your computer happens in the window on the right hand side of the mBlock programming environment:
The current value of sensors can be displayed through this communication. To display the current value, use the “Write line” block:
Replace the input “hello” with the ultrasonic sensor value and put it in a forever loop:
When I run this file, I got the following output:
Your robot can also be controlled by reading from the input line. First check that data is available:
If it is, then read the line with this:
And compare it with this:
Finally, program your robot to behave according to your wishes. In this program, an input of “r” will turn the LEDs red, and “o” will turn them off:
Then, in the input area, I have turned the lights on red, off, and back on red again:
- Write a program that controls the motors with serial communication.
Construct Your Dreams!