Skip to content

Search the documentation

Kit
Firmware

Blink the LED — Smart Car

The “hello world” of MoBot. LED 1 on the Smart Car turns on for half a second, off for half a second, and keeps going until you switch the robot off.

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 blocks of this example, from top to bottom.
Click the picture to view it larger.Open full sizeThe same program written as Python is further down this page, in The Python code.
Read the program as text
  • MoBot Start
  • Print to serial "Blink!"
  • repeat forever
    • Set LED 1 ON
    • wait 0.5 seconds
    • Set LED 1 OFF
    • wait 0.5 seconds
  • A Smart Car, charged and switched on.
  • A USB cable.
  1. Open 01-blink.mobot in MoBot (double-click it, or use Open in the IDE).
  2. Plug the robot in and pick its port.
  3. Press Send to Device. MoBot sends the program to the robot and starts it.
  4. Watch LED 1.
  • [MOBOT] Blink! appears once in the serial monitor, right after the program starts.
  • LED 1 blinks steadily: on half a second, off half a second.
  • It never stops. Press Stop, or send a different program, to end it.

If the LED does not blink but the serial line appeared, the program is running and the LED is the problem — check that you are looking at LED 1 and not LED 2. If nothing appears at all, the program did not reach the robot.

block what it does
program_start Every MoBot program starts here.
mobot_print Sends a line to the serial monitor, so you can tell the program really started.
repeat_forever Everything inside runs over and over.
mobot_ledon Turns LED 1 on (ON) or off (OFF).
wait Pauses. Change the 0.5 to 2 and the blink gets slow and lazy.

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.

01-blink.firmware-3.main.py
# Blink the LED — robotics (firmware 3.0)
#
# This is what MoBot puts on a robot running firmware 3.0 as main.py when you open
# 01-blink.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 01-blink.main.py.
from machine import Pin
import time
print("[MOBOT]", 'Blink!')
while True:
robot.led1.set(1)
time.sleep(0.5)
robot.led1.set(0)
time.sleep(0.5)
  • Make the wait 0.1 — the LED flickers.
  • Set the second Set LED block to LED 2 instead of LED 1, and watch the two LEDs take turns.