Skip to content

Search the documentation

Kit
Firmware

Smart Car

The Smart Car is a wheeled robot. It drives on two motors. It can follow a dark line, measure how far away things are, tell colours apart and know which way it is facing. In Python you reach every part of it through one object, called robot.

Chip ESP32
Motor driver DRV8833. The first Smart Cars use an L298N, see Early Smart Cars
Battery sensor Yes. The early L298N board has none
Link to your phone Bluetooth, to the MoBot app
In code robot
Current firmware 3.0.2
Pins Smart Car pins

The website lists these parts in the box: the MoBoard Robotics board, two 6 V DC motors, an ultrasonic sensor, a 5-channel infrared sensor, an RGB colour sensor, a compass and a holder for 6 AA batteries (the batteries are not included). Servo motors and joysticks are add-ons that are not in the base kit.

Every part is an attribute of robot. Click the class name to open its reference page.

Part In code Reference What it does
Bluetooth link robot.bluetooth BLEController The robot’s Bluetooth link to the MoBot app on your phone.
Game Pad robot.gamepad Gamepad The Game Pad in the MoBot app on your phone, received over Bluetooth.
LED 1 robot.led1 Led One of the robot’s lights (led1 or led2); brightness is in percent, 0 to 100.
LED 2 robot.led2 Led One of the robot’s lights (led1 or led2); brightness is in percent, 0 to 100.
Buzzer robot.buzzer Buzzer The robot’s buzzer: it plays songs in the background while your program goes on.
Left motor robot.left_motor Motor One drive motor of the robot (left_motor or right_motor); speeds are in percent.
Right motor robot.right_motor Motor One drive motor of the robot (left_motor or right_motor); speeds are in percent.
Servo 1 robot.servo1 Servo A servo motor on one of the robot’s servo plugs; angles are in degrees, 0 to 180.
Servo 2 robot.servo2 Servo A servo motor on one of the robot’s servo plugs; angles are in degrees, 0 to 180.
Servo 3 robot.servo3 Servo A servo motor on one of the robot’s servo plugs; angles are in degrees, 0 to 180.
Servo 4 robot.servo4 Servo A servo motor on one of the robot’s servo plugs; angles are in degrees, 0 to 180.
The four servos robot.servos Servo The four servos as a list, in order: servo1 to servo4.
Line sensor (five eyes) robot.line_sensor LineSensor Sees a dark line on a light floor. Each eye shines infrared light at the ground and measures how much bounces back: dark surfaces send back less.
Distance sensor robot.distance_sensor DistanceSensor Measures how far away something is. It sends out a short burst of ultrasound, a sound too high for us to hear, and times how long the echo takes to come back, like a bat.
Colour sensor robot.color_sensor ColorSensor Measures how much red, green and blue light comes back from a surface. A small white lamp lights the surface, and filters in front of the sensor sort the colours.
Compass robot.compass Compass Tells which way the robot is facing, in degrees. It feels the Earth’s magnetic field, like a compass needle.
Battery sensor robot.battery Battery Measures the battery’s voltage, which drops as the battery empties.
Joystick 1 robot.joystick1 Joystick Reads how far the stick is pushed, left to right (x()) and forward to back (y()).
Joystick 2 robot.joystick2 Joystick Reads how far the stick is pushed, left to right (x()) and forward to back (y()).

Other things on robot:

In code What it does
robot.name The robot’s Bluetooth name, as the MoBot app shows it.
robot.mode The robot’s mode number: 255 is Programmable (your program), the others are the app’s modes.
robot.set_name(name) Gives the robot a new Bluetooth name (text, not empty); it is kept after power-off.
robot.enable_servos() Switches on the four servo plugs, robot.servo1 to robot.servo4 (also the list robot.servos).
robot.enable_joysticks() Switches on the two joysticks, robot.joystick1 and robot.joystick2 (they share pins with the line sensor).

The mobot module has two helpers: from mobot import map_range, sleep_ms. The built-in songs are in SONGS: from indicators import SONGS. They are on the Smart Car reference page.

  • The servos and the joysticks are off until you call robot.enable_servos() or robot.enable_joysticks(). Until then robot.servo1 to robot.servo4, robot.servos, robot.joystick1 and robot.joystick2 are None.
  • Servos and joysticks use pins that the line sensor also uses. Use one or the other. See Shared pins.
  • A part that did not start is None. The robot prints a line such as Left motor init error: and carries on. Check for None before you use a part that matters.

Firmware 3.0 renamed some of these. A robot that still runs 2.x needs the old names.

Firmware 3.0 Firmware 2.x
robot.bluetooth mobotROBOTICS.ble
robot.gamepad.x, robot.gamepad.y mobotROBOTICS.ble.x, mobotROBOTICS.ble.y
robot.gamepad.is_pressed(name) mobotROBOTICS.ble.isPressed[name]
robot.line_sensor mobotROBOTICS.irs
robot.distance_sensor mobotROBOTICS.ultrasonic
robot.battery mobotROBOTICS.battery_sensor
robot.name mobotROBOTICS.ble.mobot_name
robot.set_name(name) mobotROBOTICS.ble.changeName(name)
robot.mode mobotROBOTICS.ble.control_mode
robot.enable_servos() mobotROBOTICS.init_servo()
robot.enable_joysticks() mobotROBOTICS.init_joysticks()

Every other part has the same name on both: led1, led2, buzzer, left_motor, right_motor, servo1 to servo4, servos, color_sensor, compass, joystick1 and joystick2. The calls on each part were renamed too. See Names from 2.x to 3.0.

The MoBot app can put the Smart Car in a mode. Each mode has a number, and robot.mode tells you which one is running. The Name column gives the name the firmware uses, and the name on the app’s tile where it differs.

Number Name What it does
0 Manual (the app calls it Manual driving) You drive with the Game Pad in the MoBot app. The robot stops if the app is quiet for half a second, or if the phone disconnects.
1 Line follower The robot follows a line, using the line sensor.
2 Obstacle avoidance The robot avoids obstacles, using the distance sensor.
3 Colour detection The robot stays still and reads colours. Its LEDs show the colour it sees. The motors are never driven.
5 Stay in the Ring The robot drives forward inside a ring and turns back when the line sensor sees the border. It does not look for an opponent.
32 Team building Works like Manual, for group exercises. It has no automatic stop when the link is lost.
255 Programmable Your program runs.

There is no mode 4 on the Smart Car. The number is kept free on purpose.

  • Drive. robot.left_motor.forward(speed) and backward(speed) turn a wheel at a speed from 0 to 100 percent. drive(speed) takes a speed from -100 to 100, and a negative speed means backward. stop() lets the wheel roll to a stop, and brake() stops it at once. If a wheel turns the wrong way, set robot.left_motor.inverted = True.
  • Make light and sound. robot.led1.on() and robot.led1.set_brightness(percent) control a light. robot.buzzer.play_song(song) starts a song and returns at once, so your program carries on while it plays.
  • Follow a line. robot.line_sensor.read() gives a list of five 0 and 1 values, one per eye, from left to right.
  • Measure distance. robot.distance_sensor.distance_cm() gives centimetres. A clear space in front of the sensor reads 200 centimetres. A reading of -1 means the driver reported an error, which is rare. sees_object(within_cm) answers yes or no.
  • Tell colours apart. robot.color_sensor.read() gives (red, green, blue, clear) as raw counts from 0 to 65535.
  • Find your way. robot.compass.heading() gives degrees from 0 to 360, after calibrate(). robot.compass.turn_to(heading) turns the robot on the spot until it faces that heading.
  • Check the battery. robot.battery.voltage() gives volts. The early L298N board has no battery sensor, and there robot.battery is None.
  • Listen to your phone. The Game Pad in the MoBot app reaches your program as robot.gamepad.x, robot.gamepad.y and robot.gamepad.is_pressed("a"). robot.bluetooth.is_connected() tells you whether a phone is connected.
  • Name your robot. robot.set_name("Rocket") changes the Bluetooth name the app shows. It is kept after power-off.
  • Use the add-ons. After robot.enable_servos(), robot.servo1.set_angle(degrees) turns a servo to an angle from 0 to 180. After robot.enable_joysticks(), robot.joystick1.x() and y() read the stick from 0 to 1023.

Each of these has a full reference page. Start from the table above.