Master Python and Scratch programming with LEGO MINDSTORMS Robot Inventor. Build intelligent robots with sensors and motors.
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)
Upgrade to Pybricks for 2-3x performance and professional-grade motor control.
from pybricks.pupdevices import Motor
motor.run_target(200, 360)
Official Python API documentation
Alternative firmware with advanced features
Free curriculum and lesson plans
Active Reddit community
Community code snippets
Get instant programming help
Get MINDSTORMS Robot Inventor and build intelligent robots
Shop MINDSTORMS