Arduino is the main processor board on many many hobby, experimental, robotics and IoT devices. It is also the one that powers our little mBot robots.
- Understand the difference between software that runs on a screen and software that controls the real world
- Understand the Arduino hardware and software architecture, the basic event loop and the libraries
- Install arduino necessary software and learn how to write some simple programs
- Demonstrate profficiency by writing and demoing a fun example
- Download Arduino IDE for Windows/Linux/MacOS, and follow the installation instructions in Getting Started. * Notice that Linux requires an extra step of setting serial port permission at the end.
- Set up arduino libraries for mBots. See Background section below.
- Learn examples in File->Examples->MakeBloackDrive for e.g. motors, sensors, buzzers, etc
- Connect mBot with your device by USB cable, turn on your mBot, choose your mBot in Tools->Port. Notice it is not the bluetooth one.
- Upload your own program or test on the examples.
Background - arduino language and libraries
The basic Arduino programming language reference(structure, variables and functions), check Language Reference.
The following are the useful libraries you might want to include in the heading of your code to help you with your mBot programming.
Built-in Arduino Libraries
- Arduino (built-in)
- insert code:
- Wire (built-in)
- insert code:
- or go: Sketch->Include Library->Wire
- reference: https://www.arduino.cc/en/Reference/Wire
- SoftwareSerial (built-in)
- insert code:
- or go: Sketch->Include Library->SoftwareSerial
- reference: https://www.arduino.cc/en/Reference/SoftwareSerial
MeMCore (MUST INSTALL)
This is the official library from MakeBlock, include most useful functions that enable interacting with mBot, such as its motor, sensors, LED, etc.
Download the ZIP file here:
Next follow ‘How to Use’ on the front page for library setup.
* see more instructions for Arduino library management
After adding library to your Arduino application successfully, you should see ‘MakeBlockDrive’ option in Files->Examples and Sketch->Include Library.
Now you can use functions in the library by first including the library in your headings as:
An example is provided in Sketch->Include Library->MakeBlockDrive for every function in the library. Check the examples if you have questions about its features, and run the example script if you have questions with what the function does to the mBot.
For example we use MeDCMotor class to control mBot motors:
- Check out Sketch->Include Library->MakeBlockDrive->Me_DCMotor->DCMotorDriverTest
- In this example, to see how to declare this object, its function list, and subsequently, which to use to make the motor ‘run’, ’stop’, etc.
Ultrasonic (MUST INSTALL)
The ultrasonic-HC-SR04 Library for Arduino. This library enables you to interact with the two HC-SR04 sensors on the left and right hand side of your mBot. Notice that these are separate from your front Makeblock sensor.
download the Zip file at:
- Add downloaded library to your Arduino application.
After successfully added to application, you should see option ‘Ultrasonic’ in Files ->Examples and Sketch->Include Library.
Include the library in your headings before using as :
- When declaring the Ultrasonic object, be sure to first check the pin (trigger / echo) of the HC sensor is connecting with which analog/digital pin respectively on the mBot board.