Python & Scratch Programming

MINDSTORMS Programming

Master Python and Scratch programming with LEGO MINDSTORMS Robot Inventor. Build intelligent robots with sensors and motors.

51515-1
Set Number
949
Pieces
10+
Ages
5
Robots to Build

Python Tutorials

Learn to program your MINDSTORMS hub with Python

Beginner

Hello World

Your first MINDSTORMS program. Display text on the LED matrix and play sounds.

from mindstorms import MSHub
hub = MSHub()
hub.light_matrix.write("HI")
Python 10 min
Beginner

Motor Control Basics

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)
Python 20 min
Intermediate

Sensor Integration

Read color sensor and distance sensor values to make robot decisions.

color = color_sensor.get_color()
if color == 'red':
  motor.stop()
Python 30 min
Intermediate

Line Following Robot

Build a robot that follows a black line using proportional control (PID basics).

error = brightness - target
steering = KP * error
drive(steering)
Python 45 min
Advanced

Gyro-Based Navigation

Use the built-in gyroscope for precise turns and straight-line driving.

yaw = hub.motion_sensor.get_yaw_angle()
turn_to_angle(90)
Python 60 min
Advanced

Pybricks Firmware

Upgrade to Pybricks for 2-3x performance and professional-grade motor control.

from pybricks.pupdevices import Motor
motor.run_target(200, 360)
Pybricks 90 min
📚

Official Resources

💬

Community & Support

🤖

Ready to Start Programming?

Get MINDSTORMS Robot Inventor and build intelligent robots

Shop MINDSTORMS