Speed ramp — Smart Car
One block does both jobs this time: Set Motor … to … with speed … % picks the direction and the speed in a single step. The wheels climb 20 → 40 → 60 → 80 → 100 %, stop, and start again.
This is one project for both firmware versions: when MoBot opens it, the blocks write the code for the firmware of your Smart Car.
The program
Section titled “The program”Read the program as text
- MoBot Start
- Print to serial
"Lift the robot up! Speed ramp starting." - wait 2 seconds
- repeat forever
- Print to serial
"Speed 20 %" - set Motor 1 to Direction 1 with speed 20 %
- set Motor 2 to Direction 1 with speed 20 %
- wait 2 seconds
- Print to serial
"Speed 40 %" - set Motor 1 to Direction 1 with speed 40 %
- set Motor 2 to Direction 1 with speed 40 %
- wait 2 seconds
- Print to serial
"Speed 60 %" - set Motor 1 to Direction 1 with speed 60 %
- set Motor 2 to Direction 1 with speed 60 %
- wait 2 seconds
- Print to serial
"Speed 80 %" - set Motor 1 to Direction 1 with speed 80 %
- set Motor 2 to Direction 1 with speed 80 %
- wait 2 seconds
- Print to serial
"Speed 100 %" - set Motor 1 to Direction 1 with speed 100 %
- set Motor 2 to Direction 1 with speed 100 %
- wait 2 seconds
- Print to serial
"Speed 0 %" - set Motor 1 to Direction 1 with speed 0 %
- set Motor 2 to Direction 1 with speed 0 %
- wait 2 seconds
- wait 1 seconds
- Print to serial
What you need
Section titled “What you need”- A Smart Car with both wheels fitted.
- A USB cable.
- Something to stand the robot on so the wheels are in the air. This one never stops on its own.
How to run it
Section titled “How to run it”- Stand the robot up on a book, wheels free.
- Open 03-speed-ramp.mobot, plug in, press Send to Device.
- Listen. Do not just watch — the motor sound is the easiest way to hear the steps.
What you should see and hear
Section titled “What you should see and hear”- The serial monitor counts:
Speed 20 %,Speed 40 %, …Speed 100 %,Speed 0 %, then starts again. - Each step lasts 2 seconds.
- The motor whine gets higher and louder at each step.
- At
Speed 0 %both wheels stop dead for 3 seconds, then the ramp restarts. - It never ends. Press Stop, or send another program, to stop it.
The test passes if every rung sounds different from the one before it and if the wheels really do stop at 0. On a standard Smart Car the lowest rung or two may not turn at all — see the next section before you call that a failure.
An honest warning about the low end — and it depends on your robot
Section titled “An honest warning about the low end — and it depends on your robot”Smart Cars come with one of two motor chips, and they do completely different things with a low speed number, so the bottom of the ramp will not look the same on both. The standard Smart Car has the DRV8833 chip; only the early ones have the L298N. Check which one you have before you write anything down.
On a standard Smart Car (DRV8833): there is no stretching. 20 % really is 20 % of full power, and these motors often will not start at all that low — the bottom one or two rungs may just buzz without turning. That is the robot behaving correctly, not a broken motor driver. If it happens, write down the lowest speed that actually moves your wheels — that number is genuinely useful to the people who write the robot’s insides, and it differs from robot to robot.
On an early Smart Car (L298N): 20 % does not sound like one fifth of 100 %. Speeds 1-100 are stretched onto the range the motors actually need to start turning — about half power upwards — so 20 % is roughly two thirds as fast as 100 %, not one fifth. Only 0 is a real stop. Every rung of the ramp will move the wheels. Children notice this; it is worth explaining rather than pretending.
So: on a standard Smart Car, three or four moving speeds and a buzz at the bottom. On an early Smart Car, five moving speeds. Both are a pass.
The blocks
Section titled “The blocks”| block | what it does |
|---|---|
mobot_motordirspeed |
direction and speed together, one block per wheel. |
repeat_forever |
runs the whole ramp again and again. |
wait, mobot_print |
pacing, and a running commentary. |
The Python code
Section titled “The Python code”The same blocks write different Python for each firmware, and MoBot picks the one that fits the robot you use. The 2.x tab is for reference. This is a reading copy: editing it changes nothing, so change the blocks instead. The name map lists the names that changed.
# Speed ramp — robotics (firmware 3.0)## This is what MoBot puts on a robot running firmware 3.0 as main.py when you open# 03-speed-ramp.mobot and press Send to Device. It is GENERATED from the blocks;# editing this file changes nothing. Edit the blocks instead.# The firmware 2.x version is 03-speed-ramp.main.py.
from machine import Pinimport time
print("[MOBOT]", 'Lift the robot up! Speed ramp starting.')time.sleep(2)while True: print("[MOBOT]", 'Speed 20 %') robot.left_motor.backward(20) robot.right_motor.backward(20) time.sleep(2) print("[MOBOT]", 'Speed 40 %') robot.left_motor.backward(40) robot.right_motor.backward(40) time.sleep(2) print("[MOBOT]", 'Speed 60 %') robot.left_motor.backward(60) robot.right_motor.backward(60) time.sleep(2) print("[MOBOT]", 'Speed 80 %') robot.left_motor.backward(80) robot.right_motor.backward(80) time.sleep(2) print("[MOBOT]", 'Speed 100 %') robot.left_motor.backward(100) robot.right_motor.backward(100) time.sleep(2) print("[MOBOT]", 'Speed 0 %') robot.left_motor.backward(0) robot.right_motor.backward(0) time.sleep(2) time.sleep(1)# Speed ramp — robotics## This is what MoBot puts on the board as main.py when you open# 03-speed-ramp.mobot and press Send to Device. It is GENERATED from the blocks;# editing this file changes nothing. Edit the blocks instead.
from machine import Pinimport time
print("[MOBOT]", 'Lift the robot up! Speed ramp starting.')time.sleep(2)while True: print("[MOBOT]", 'Speed 20 %') mobotROBOTICS.left_motor.setDirectionAndSpeed(0, 20) mobotROBOTICS.right_motor.setDirectionAndSpeed(0, 20) time.sleep(2) print("[MOBOT]", 'Speed 40 %') mobotROBOTICS.left_motor.setDirectionAndSpeed(0, 40) mobotROBOTICS.right_motor.setDirectionAndSpeed(0, 40) time.sleep(2) print("[MOBOT]", 'Speed 60 %') mobotROBOTICS.left_motor.setDirectionAndSpeed(0, 60) mobotROBOTICS.right_motor.setDirectionAndSpeed(0, 60) time.sleep(2) print("[MOBOT]", 'Speed 80 %') mobotROBOTICS.left_motor.setDirectionAndSpeed(0, 80) mobotROBOTICS.right_motor.setDirectionAndSpeed(0, 80) time.sleep(2) print("[MOBOT]", 'Speed 100 %') mobotROBOTICS.left_motor.setDirectionAndSpeed(0, 100) mobotROBOTICS.right_motor.setDirectionAndSpeed(0, 100) time.sleep(2) print("[MOBOT]", 'Speed 0 %') mobotROBOTICS.left_motor.setDirectionAndSpeed(0, 0) mobotROBOTICS.right_motor.setDirectionAndSpeed(0, 0) time.sleep(2) time.sleep(1)Try changing it
Section titled “Try changing it”- Change one wheel to Direction 2 and put the robot on the floor: it now spins faster and faster instead of driving.
- Delete the
Speed 0 %group and see how much harder it is to tell where one cycle ends and the next begins. The pause is what makes the pattern readable.