Arduino Robotics with the mBot
4.2 (159 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
1,428 students enrolled

Arduino Robotics with the mBot

An introduction to robotics with the world's friendliest learning robot
4.2 (159 ratings)
Course Ratings are calculated from individual students’ ratings and a variety of other signals, like age of rating and reliability, to ensure that they reflect course quality fairly and accurately.
1,428 students enrolled
Last updated 10/2019
Current price: $69.99 Original price: $99.99 Discount: 30% off
5 hours left at this price!
30-Day Money-Back Guarantee
This course includes
  • 5 hours on-demand video
  • 1 article
  • 6 downloadable resources
  • Full lifetime access
  • Access on mobile and TV
  • Assignments
  • Certificate of Completion
Training 5 or more people?

Get your team access to 4,000+ top Udemy courses anytime, anywhere.

Try Udemy for Business
What you'll learn
  • Program the mBot on the tablet device
  • Program the mBot on the PC
  • Use the mBot sensors and actuators
  • Program the mBot using the Scratch language
  • Come up with your own fun experiments for the mBot
  • Absolutely nothing. We'll start at the beginning.
  • Purchase an mBot kit
  • Download the free programming interface for Windows/Mac OS
  • Download the free programming interface for tablets

This course will introduce you to the mBot, the world's friendliest educational robotics platform. The mBot is an Arduino-based, two-wheel robot that comes with build-in sensors and actuators, and that you can program using Scratch, a graphical programming language. 

The mBot is also extensible, with a lot of components available that you can use to build your own robotic creations.

In this course, I will show you how to assemble the mBot, discuss the additional hardware options, and demonstrate how to program it on your tablet and your Windows or Mac OS computer.

The main project of the course involves programming the mBot to follow an arbitrary black line on the floor. In this project we must combine our robot’s sensors and actuators efficiently to enable it to stay on the line while it travels on it as quickly as possible.

At first glance, you may think that getting a robot to follow a line is easy. That’s not true for a robot.

As the programmer, you must “teach the robot” to do something that to a human is intuitive. You need to extract the intuitive understanding of how to follow a line and convert it into code.

The required hardware is the mBot itself, and a computer (Windows or Mac OS). You can purchase an mBot direct from its manufacturer, Makeblock, or from your local reseller. You can download the software from free from the Makeblock website.

Who this course is for:
  • School students and homeschoolers interested in robotics projects
  • Teachers, interested to learn skills for a STEM class
  • Electronics hobbyists looking for a gentle introduction to robotics
  • Parents looking for a fun educational activities to take with their children
Course content
Expand all 39 lectures 04:49:03
+ About this course
3 lectures 10:27

I've designed this course to help you take a first steps in the exciting world of robotics. Granted, the robots you will be playing with in this course is very much unlike R2-D2, but all robots share common design elements. In this course, I will introduce you to some of them. Let's have a look at what this course is about.

Preview 03:36

Let's have a look at the hardware and software that you need in order to successfully complete this course. In this course, things are fairly simple. As far as the hardware is concerned, you will need the mBot kit that contains all the bit and pieces, the parts that you need in order to assemble your own mBot. You can get this from Makeblock or you can look up one of the distributors in your country.

Preview 02:32

In this lecture I'll explain the structure of the course and how to make the most from it. I've designed the course for people who have never played with a robot before and may even have never used an Arduino. It is a course for the absolute beginner. This doesn't mean that you won't get in-depth skills, it means that the learning curve is gentle. I've arranged the lectures in the course in two parts.

Preview 04:19
+ Meet the mBot
8 lectures 01:00:11

In this section, I'll walk you through the Mbots components as they come in the box and show you how to assemble your Mbot. The Mbot is not just a collection of parts that come in a box though, it is a platform that allows you to build robotic contraptions using various kinds of mechanical and electronic parts. The Mbot is a bit like Lego but for robotics. In this section, I spend a bit of time to show you the various of available options that allow you to extend your Mbot. I will also spend a bit of time to list and introduce the software applications that you can use to program your Mbot.


In this lecture, I'll show you how to assemble your new mBot. The mBot doesn't come assembled. It doesn't come like this in this form of course. It comes in a box like this with all the parts inside. 

Parts in the box

For the assembly process I recommended that you put aside about 15, have to be 20 minutes. This is said earlier, small kids, say, seven years and older should be able to complete this process with a bit of supervision. There are a few small pieces that the supervisor needs to be mindful of. It need a bit of accurate manipulation.

Assembly: Chassis, motors, wheels, sensors

I'm going to put the chassis of the mbod aside and work with the makeBlock, the microcontroller module.

Assembly: mCore tour, Bluetooth module

In this assembly, I'm not going to make use of this little box here. This little box is used in case if you'd like to use a lithium-ion battery in like this but in this assembly, I'm not going to worry about this. I'm going to continue without the lithium-ion battery option and just use the AA battery pack instead. This way you don't have to worry about expensive charges or even expensive batteries. With battery pack, you have your AA batteries onto the battery pack.

Assembly: Wiring, batteries, controller

I'm going to plug in the power supply as well. The barrel connector will go to the six volts. And turn it on. Right, good power. Now, just to check that the mBot is operating, I'm going to unpack my remote control. It doesn't come with a battery, so I need to get a battery for this. I don't believe that a battery is supplied. No. Let's get the batteries in. I've got a fresh CR2025 Lithium battery, so plug it in the holder and insert it into the remote control, like that.

Assembly: testing

Now that you have your mBot assembled and before going on to show you the various programming options that are available, I'd like to take a few minutes to show you the various hardware options that you have available. Things that you can plug into the mBot to give it additional capabilities.

Additional hardware

When it comes to programming the mbot, there are several options available and in this lecture, I would like to introduce them to you. The first one is the M-block application that runs on a PC that is Windows or Macintosh computer and M-block is actually the program that we will be using throughout this course to do the bulk of our programming.

Software options
End of section quiz
5 questions
+ Programming the mBot using a tablet
4 lectures 37:39

Now that you've assembled your mBot, it's time to play with it. In this section, I'll show you how to use three tablet apps that allow you to program you mBot graphically. They are Makeblock, mBlockley, and mBlock. I'll explain the differences and similarities of each and give you a demonstration. Remember that, in this course, our objective is to build a line following robot. Unfortunately, it's not possible to achieve this objective using these tablets apps because they do not produce code that is fast enough to guide the mBot on the line.

To build a line following application, we'll use the PC version of the mBot software. This is something that I will show you later in this course. But these are great apps for getting started and playing, and that's what we got to do next.


In this lecture, I would like to show you the three applications that you can run on a tablet computer. In this case, using your IPad to control your mBot. These three applications are mBlock, mBlockly and Makeblock. Each one of those applications emphasizes a certain aspect, a certain way of programming and controlling the mBot. I'd like to demonstrate what each one does so you can get an idea of how you can use them.

Demonstration of MakeBlock

Makeblock has discontinued mBlockly and removed it from the App Store. They recommend that people use mBlock instead. 

I will keep this lecture for "historical" reason, but please beware that you will not be able to download it.

Demonstration of mBlockly
Demonstration of mBlock
End of section quiz
1 question
+ Programming the mBot on the PC using mBlock
6 lectures 01:00:01

It's time to get serious now. In this section, I'll introduce you to mBlock; the PC version of the software that we use to program the mBot. mBlock is available for Windows and Mac OS. I'll be going through demonstrations that follow on the Windows version. If you are using Mac OS, remember that everything I show you works exactly the same way for you, whether you're using the Mac or the Windows version. We'll start by installing mBlock on your computer and taking a lengthily look at Scratch; the graphical programming language. We'll upload our first program to the mBot and learn how to control the motors.


Before we continue with downloading mBlocks and starting with their programming component of this course, I just want to take up-let me just talk about the mBot.

The mBot that you get out of the box once you assemble it is going to look like this. It will have two motors and then inside the plastic package, you've got a customized version of the Arduino Uno that contains the ports that you can see here that you connect to external peripherals

Install mBlock on your computer

Once you have your mBlock application installed on your computer, just started by double clicking on the mBlock icon. Here's the application. I'd like to talk a little bit about the Scratch programming language itself and how that relates to the way that would program the mBot. 

A quick look at Scratch, the graphical programming language

I think we can move on to doing some actual playing around with the mBot now using mBlock. I know we didn't spend much time with scratch but I'm thinking we've got a whole robot here. Why just play with his pride? [chuckles] Have a look at scripts again, look down at the right bottom corner of the scripts menu. You see that there's a robot section. Under robots, once you select it, there's an mBot section which contains all of the different programming blocks that we can use with the mBot.

Create and upload your first program

We got the two LEDs to display two different colors and hopefully in the meantime, you experimented a little bit with the LEDs and you used the color wheel to come up with different colors. In this part of the crash course, I would like to show you how to use the two motors. Each mBot comes with two motors, left and right depending on how you look at it.

Motor control

Now, we've got an mBot that moves forwards for five seconds at speed 125 and then it stops. How about give it the ability to turn as well either left or right and also move backwards. How do we do that? I'm going to continue building on the same program that we started earlier. Let's say that we'd like to get the robot to move forwards maybe for one second and then turn

Moving left, right, backwards
End of section quiz
5 questions
+ Getting more out of the mBot: programming structures, more sensors
6 lectures 47:17

In the previous section you set up mBlock and learn the basics of scratch. Uploading a program to the import and controlling the motors. In this section I'll show you how to use the two basic programming control structures using scratch. The loop and the if else structures. I would also show you how to use a proximity sensor for detecting obstacles and the buzzer for making noises


Now we can use variables. Now the next thing that I’d like to show you is how to use a loop. A loop allows us to group together a bunch of functions, a bunch of instructions or blocks that we would like to repeat several times. Very useful control structure. To demonstrate how this works what I'll do is I'm going to create a new sketch that will make the two RGB LEDs to blink alternating.

The Loop

With the two LEDs blissfully blinking away forever, the next thing that I would like to show you is how to use the proximity sensor. The proximity sensor allows us to measure the distance between the sensor and an object in front of it. The sensor works well in reasonable distance, it may be up to 30 or 40 centimeters. Of course, the further away you go from the target, the larger the target has to be in order for the sensor to pick up the distance correctly. The smaller the target is then the harder it's going to be for it to detect the distance of

The distance/proximity sensor

The next thing that I'd like to do now is to use our knowledge of the way that the ultrasonic sensor works to control the blinking rate of the two LEDs in the program that we created earlier. Let me save this progress so that we don't lose it, before I load the previous program. This is going to be-- let's make it seven. This is introduction to the distance sensor and you load the sixth program there forever loop alternating LEDs with variable. What I like to do is to get the sensor to take continuous readings of the distance between itself and a target, and then use those readings to change the frequency of the LED switching.

More experimentation with the distance sensor

Now we've got an mBoard that links its LED's blue and red depending on how far from a target the ultrasonic distant sensor is. That has given us and you I hope a good understanding of how the sensor and the LED's the attribute LED's work plus the forever loop. Now, the next thing that I'd like to show you and explain is how we can get the mBoard to make decisions depending on sensor readings like the ultrasonic distance sensor. Towards that goal, we're going to build a new program that again uses the LED's and the distance sensor but now this time it turns the LED's into a particular color depending on the distance between a sensor and the target.

The "If" and "If...else" control structure

Before actually moving to the next section, I'd like to take this opportunity to show you one more device that comes with the mBot and that is the buzzer. It's a way to make noise. If you have a look at the robots section there is a block here that allows you to control the buzzer.

Introducing the buzzer
End of section quiz
6 questions
+ Create the line follower program
7 lectures 01:00:36

We're now at the home stretch and completing the line following program is within our grasp. In this section, I'll show you how to use the line sensor. We'll start putting together everything we learned up to now in order to construct step-by-step the line following program. We'll also introduce that button and show you how to create custom scratch blocks, which is the equivalent of a programming function or subroutine. Using custom blocks is a good practice for when your programs become large.

By the end of this section, you'll have an import that can follow a line, detect the end of a line, and do a U-turn. You can construct your own line on the floor by downloading a PDF document that contains one segment per page. Print as many as you like and assemble them in your own elaborate configurations to test out your import with. You'll find this file as a downloadable resource for this lecture.


I know that we've covered a lot of details, but the phone is actually now starting. We are going to play around with the line-follower sensor. This is the last component that we need to start implementing the line-following capability and final program for the mBot. The line-following sensor is a module that we've attached at the bottom of the mBot, and it contains two, actually, sensors. Although it behaves as one single unit on it, we've got two sensors. These two sensors detect just light intensity, darkness or lightness of a color right in front of them

Introducing the line sensor

It's about time to get those motors moving. I'm going to work on the same problem that we created before the break and just modify it slightly. Actually, the modifications are smaller than you might think. Think about what is the similarity between an LED and a motor. You might say that they're both output devices. They both modify the world in some way. They are actuators. The motor produces motion and the LED produces light. Essentially, the structure of the program as I have it here is ready to go. Since all I have to do is to place the LED statements with motor statements or with motor blocks. Let's start thinking about the modifications now. When the line sensor reports a zero which is what is happening right now, it looks like the inboard is within the track, fully within the track and all it's going to do really is just to move forwards.

Adding the motors to the line follower program

At the moment, we've got an mBot that can follow a line. It gets a bit confused when it reaches the end of the line, it doesn't quite know what it does. Its programming is telling it to just reverse. And, hopefully, because of the difference in traction between the two wheels. At some point, it might turn around far enough to be able to go back where it started. Obviously, that's not an optimal solution to this problem, there's too much chance. I'd like to make a small recommendation, a small improvement. I would like to set a marker for the robot to be able to detect so that once it reaches that marker, it knows it needs to be a little bit more radical with its behavior. And instead of simply reversing, to perhaps turn by a certain amount of degrees or at a particular speed and then try to re-establish contact within line like that.

Stopping at the end of the line with the proximity sensor

Great we are getting closer to having an mBOT that is capable of tracking a line and dealing with the end of line problem. We saw how in the current iteration the robot will just stop as soon as it reaches the end of the line. What I'd like to do next is to get it to reverse or to turn enough so that he can re-establish contact with the line and then continue moving in the opposite direction. Again, there's always multiple ways to achieve the same result but I think that one simple way that we can try out first is you just get the robot to do a turn either left or right; so it can turn perhaps like this a certain number of degrees or the other way like that. It doesn't really matter how we try this out as long as we get the robot to turn one way or another. The only modification that we need to make here is at the part of the program where we have detected that we've hit an obstacle and we want to deal with that situation there. 

Implement a U-turn at the end of the line

For the next iteration of the program, I would like to introduce the button. Here on the right side of the input, there's a little push button. You can actually read its state from your program and then you can get your program to do something in reaction to pressing the button. What I like to do is for when the robot is powered up, to get its wheels to not spin until the user presses on the push button.

Using a button to start and stop

At this point in this mBot programming crash course, we've implemented all the functionality that I was aiming for on the mBot itself. The problem is that we've ended up with quite a lot of code here. It's quite a large sketch or program. I'd like to show you how to simplify things a little bit by turning certain blocks or groups of blocks into external functions that then the mBot program can call by name. This is a common technique in the world of programming where we compartmentalize functionality and then this functionality can be easily referred to from within our program. I'm going to demonstrate what I mean by this, just to try and keep things simple.

Creating custom block (functions)
End of section quiz
5 questions
+ Other things you should know
3 lectures 09:15

Some of my students often become confused when they try to use their mBot with their Ipod or an a tablet after they've programmed it on their computer. They also become frustrated because after programming the mBot on their computer they can't take it back to it's factory settings so that they use the incorrect remote controller or run any of the default programs. In this last section of this course I'll show you how to restore the functionalities


At this point, we spent quite a bit of time programming the mBot using mBlock. As an example, I’ve got a little sketch running here that just changes the color of the built-in LEDs. But imagine that at some point, you'd like to play with your mBot using your iPad in one of the three applications that I showed you at the beginning of the course. To do that you will need to reset the mBot to it's original firmware. In this lecture I'll show you how to do that.

Restoring the firmware (so that you can control the mbot from the iPad)

Let's see if my remote control works now. 

If it doesn't, what can you do to make it work?
Restoring the default program (so that you can control the mbot with the remote
End of section quiz
2 questions
+ Mini project
0 lectures 00:00
In this project, you will create a program that makes your mBot to move inside a circle of a box, without even crossing the line.
Project: Do not cross the line!
2 questions
+ Conclusion
2 lectures 03:16

Congratulations for completing this course. You are now on your way through learning and looked more about robotics with your new mBot.

Let's take a minute to recap. What did you learn in this course? Quite a lot, I might say. You've learned how to assemble your mBot and how to program it using scratch on your tablet or computer. You learned about the line following sensor, a proximity sensor, a might sensor and motors, the RGB LEDs and the pattern. All these components come in the box with the mBot. You learned how to construct a fairly large scratch program, and get your mBot to follow a black line. This was an iterate process, we started small, tested every change we made, and then edit features with every iteration. Use this process to do anything from a robot toy to a robotic Mars explorer.

"What's next?", you might ask. There's a lot of appropriate capacities to this question but what I recommend is that you try first in variation of the line following robot. One idea is to create a black circle on break panel to flow and get your mBot to move anywhere within the space to find like this line, without ever crossing it. Let's call this the "Do not cross a line project."

Next, consider adding additional modules in your mBot and programming it to do something in response to an event. For example, get an LED strip and a microphone and program the mBot to light up the strip in red when you clock aheads. Or get an accelerometer module and program it so that when the mBot is upside down, it creates a high pitch sound on the buzzer.

Later, you can also experiment being such as the grip-up and the server extension, and get your robot to pick up things up and move them around.

With so many options, it's probably never mBot again. As always, I invite you to share your projects with me and other students in this course. Please, post a description of your project with a photo here and I'll be happy to check it out.

Happy making!

What's next?
Other courses by Peter Dalmaris