Digital Maestro Publications

View Original

The mBot robot and basic motion

Basic math, science, and coding concepts

I like using the mBot in the classroom. It is useful when teaching math, science, and coding concepts. Once the robot is assembled we begin with the fundamentals. These fundamentals include coding the robot’s microcontroller to activate the motors so mBot begins to move around. Once the robot is moving we begin to learn about motion, velocity, and acceleration. This leads to lessons on Newton’s Laws of Motion.

Make sure the robot is not on a table where it can easily roll off and come crashing to the floor. I recommend placing the robot on the floor for the first few examples. You can also place the robot on a small paperback book so the wheels are free to spin.

The application to program the mBot is available online or as a download for your computer or device. Go to https://mblock.cc. Programming in the browser version of mBlock 5 requires an account. There is account integration with Google so students can easily create their accounts. This is useful if your school district uses Google account services.

Create a new project by clicking the new project button on the startup page. Provide a title for the project. Click the word Untitled next to the image of a diskette.

Name the project “Move forward and back”. Don’t include the quotation marks.

We need to load the robot into the development environment. Loading the robot loads the code library for the robot. This code library provides some specific code blocks for mBot.

Go to the Devices section under the Stage and click the Add button. The button is next to the Cody Device.

A Device selector window will open. Click the mBot device and click the OK button.

There are two devices in the Devices section. The mBot device is selected. A blue highlight appears around the selected device.

The codes panel updates with the categories and code blocks for the mBot. The first code block in the Action category is used to instruct the robot to move forward.

Using code blocks to build scripts is easy and intuitive. Click and drag the first code block onto the canvas area on the right. This code block has two number values. These values are inside small ovals.

The move forward code block is used to send instructions to the micro-controller on the mBot. The micro-controller sends instructions to all the components on the board. It also sends instructions to the components attached to the board.

The micro-controller interprets the instructions in the code block. The instructions in the current code block will send fifty-percent of the available energy to the motors. It will send this amount of energy for one second. That isn’t much time. We will change these values later.

STEM Integration

Let’s take a closer look. The code here relates to some basic concepts in science. The mBot has a battery pack. It uses four double-A batteries. Each battery is 1.5 volts. There are four of these batteries. That is a combined voltage of 6 volts. Volts are potential energy. Potential energy is a concept covered in physical science.

The code block instructs the micro-controller to send fifty-percent of this potential energy to the motors. The energy is released as current. Current is the flow of electrons from one end of a circuit to another. We can determine the current sent to the motors with a math formula. This formula is taken from

Ohm’s law. Ohm’s law is a formula used to calculate current, resistance, or voltage in a circuit. To determine the current sent through a circuit, we divide the voltage by the amount of resistance in a circuit.

We don’t need to know the exact amount of current sent to the motors. It is enough that we use this moment to apply classroom concepts to real-world applications. We must use the proper academic language.

Through the use of this model, we show students potential energy at work. They understand that the current is flowing through the motors to move the robot. They understand that one form of energy is being converted into another form.

There is another concept that we can teach with math and science. That concept is time. Using the code block, we send current to the motors for one second. We will change this value later to something more reasonable. It is important to note that the code does not have instructions for values that relate to miles per hour or even feet per minute. The values have nothing to do with the measurement of distance.

The values relate to energy and time. These two concepts are closely related to concepts taught in astronomy, physical science, and math. In space, distance is commonly measured in time. For example, the distance from the earth to the sun is 92.96 million miles or 146 million kilometers. Light takes 499 seconds to travel from the sun to the Earth. We call this One Astronomical unit. Light travels at 186,287 miles per second or 299,792 kilometers per second.

There are lots of numbers used to describe the distance from the Sun to the Earth. We can easily get confused when using miles or kilometers. How do we know the sun is that far away from the Earth? Did someone travel there to measure? Did we have a very long measuring tape? We used the constant speed of light to help find the distance. For the most part, light always travels at the same velocity. It is the same almost everywhere we measure. Light is constant. This makes the use of light a reliable measuring tool.

Light is measured in the amount of time it takes to travel from one place to another. The Sun is 499 light seconds from the Earth. The distance to the closest star system is 4.22 light-years. That is about 25 trillion miles or 40 trillion kilometers. A trillion is a number followed by 12 zeros. Time might be easier to understand.

We measure distance in time all the TIME! How long does it take to travel from your city or home town to another city? When children are fussing in the back seat they don’t ask, how many more kilometers ’til we get home? They as when are we getting there. They are already measuring distances in time.

Time is a central part of calculating velocity and acceleration. To determine velocity and acceleration we need a change in time and a change in position. The change in position is the distance traveled from one point to another. The calculation of force requires the calculation of acceleration. Acceleration is part of velocity.

We have strayed far away from the code for the robot. That is part of the point. We can extend and integrate a variety of concepts when using robots for STEM. Coding the robot is a means to an end.

Returning to the code

Let’s get back to the code block. This simple code instruction will help students learn and understand some principles of motion. Students will adjust the code parameters to learn and understand velocity and acceleration.

Update the code block so the mBot travels at half the potential energy for 3 seconds.

To upload the code we need to go through a few steps. Connect one end of the USB cable to the mBot. Connect the other end to the USB port on your computer. Turn the mBot ON. Make sure to hold the mBot. Sometimes the mBot wheels will begin to spin. My students often lay the mBot on its back. This leaves their hands free to work with the application and the upload process.

The mBot wheels will roll because it begins to process the instructions in any code uploaded to it from a previous session. The code is saved in the mCore memory. The code in this memory is executed each time the robot is turned on. This is common with devices that have Microcontrollers. The code is cleared out by new code uploaded or by updating the Firmware.

Click the Events category. The code blocks in this category are used to start our instructions. These are conditions that need to be met before the mBot will begin executing the instructions. Some of the conditions include the clicking of a green flag and the press of the space key. These conditions are often used with Scratch and the development of interactive stories and games. These conditions don’t work well with our robot.

The condition block we need is the first one. When mBot(more) starts up. This block is grey. This means the block cannot be selected. We cannot add it to the canvas while it is grey. How can we select it then?

We are currently in test mode. Test mode does not actively connect to the mBot. We need to exit Test mode.

Go to the bottom of the application and look for the Connect button. Above the button is an option for live or upload mode. Click the switch to change to upload mode.

The mBot condition block is now available. The condition blocks for the Scratch development environment are grey. This means they are not available for our robot.

Attach the mBot condition code block to the move code on the canvas.

We need to open a communication link to the mBot from the program. This will allow us to upload the code to the robot. Go to the bottom of the application and click the Connect button.

Uploading is when we send content from our computer to another. We download when we get content from another computer.

A connection configuration box will open. This configuration box is used to select the USB communication port connected to the robot. The port will be different on Windows and Mac computers. The image below shows the connection port on a Mac computer. The connection is being directed to one of the USB ports.

The connection port on Windows is usually Com3. It can also be Com1 or Com2. Com stands for Communication.

Click the port selector. The available communication ports will be listed. The communication port for the mBot on Mac has a special name. This port is /dev/tty.wchusbserial. The number after the name will depend on your Mac. The important part of the information is “wch”. This identifies the port that communicates with the mBot. Select this port.

Click the connect button.

A new button appears below the Test button. The connect button changes to Disconnect. Above the Disconnect button is a button to upload our code to the mBot. Click the button to begin the upload process. Make sure the robot will not roll off a table before doing this!

The mBlock software will compile our instructions. This means the program is checking our instructions for mistakes. It is also converting our instructions into instructions the mCore board understands. The compilation process is both a code checker and a translator.

The instructions are uploaded after the compilation process is complete. A progress bar will show the upload progress. The upload is usually quick. The mBot will run our instructions once the upload is complete.

Turn the robot off. Unplug the cable from the mBot. Leave the other end connected to the computer. We will be returning often to update the code. Each time we update the code it must be compiled and uploaded.

Set the robot on the floor and turn the power switch On. The robot will run the code again. It will do this every time we turn the mBot On.