Master Python and Scratch programming with LEGO MINDSTORMS Robot Inventor. Build intelligent robots with sensors and motors.
Learn to program your MINDSTORMS hub with Python
Your first MINDSTORMS program. Display text on the LED matrix and play sounds.
from mindstorms import MSHub
hub = MSHub()
hub.light_matrix.write("HI")
Learn to control motors with run_for_degrees, run_for_seconds, and speed control.
from mindstorms import Motor
motor = Motor('A')
motor.run_for_degrees(360)
Read color sensor and distance sensor values to make robot decisions.
color = color_sensor.get_color()
if color == 'red':
motor.stop()
Build a robot that follows a black line using proportional control (PID basics).
error = brightness - target
steering = KP * error
drive(steering)
Use the built-in gyroscope for precise turns and straight-line driving.
yaw = hub.motion_sensor.get_yaw_angle()
turn_to_angle(90)
Install Pybricks firmware to run the same Python on Robot Inventor and SPIKE Prime hubs.
from pybricks.pupdevices import Motor
from pybricks.parameters import Port
motor = Motor(Port.A)
motor.run_target(200, 360)
Build these robots to practise the techniques from the tutorials above.
Skills: Line following, gyro steering, lap timing, speed optimization
Build a race car that navigates a track on its own. Use color sensors for line detection and the gyro for smooth cornering, then track lap times and tune for speed.
Skills: Color detection, decision logic, automation, state machines
Create a factory-style sorter that detects LEGO brick colors and drops them into bins, coordinating a conveyor belt with several sensors.
Skills: Maze navigation, object detection, gripper control, autonomous decision making
Program a robot to navigate a maze, find objects, and carry them to a goal zone. Good preparation for WRO and FIRST LEGO League challenges.
Skills: Web Bluetooth API, JavaScript, real-time control, custom UIs
Drive your MINDSTORMS robot from a custom web page with a joystick, sliders, and buttons that talk to the hub over Bluetooth.
Official Python API documentation
Alternative firmware with advanced features
Free curriculum and lesson plans
Active Reddit community
Community code snippets
Team robotics competition, ages 4-16
International robotics competition, ages 8-19
Get instant programming help
Get MINDSTORMS Robot Inventor and build intelligent robots
Shop MINDSTORMS