Move Hub

class MoveHub


Using the hub status light


Turns on the light at the specified color.


color (Color) – Color of the light.

Turns off the light.

Blinks the light at a given color by turning it on and off for given durations.

The light keeps blinking indefinitely while the rest of your program keeps running.

This method provides a simple way to make basic but useful patterns. For more generic and multi-color patterns, use animate() instead.

  • color (Color) – Color of the light.

  • durations (list) – Sequence of time values of the form [on_1, off_1, on_2, off_2, ...].

light.animate(colors, interval)

Animates the light with a sequence of colors, shown one by one for the given interval.

The animation runs in the background while the rest of your program keeps running. When the animation completes, it repeats.

  • colors (list) – Sequence of Color values.

  • interval (Number, ms) – Time between color updates.

Using the IMU

imu.up() Side

Checks which side of the hub currently faces upward.


Side.TOP, Side.BOTTOM, Side.LEFT, Side.RIGHT, Side.FRONT or Side.BACK.

imu.acceleration() Tuple[int, int, int]: mm/s²

Gets the acceleration of the device.


Acceleration along all three axes.

Changed in version 3.2: Changed acceleration units from m/s² to mm/s².

Using the battery

battery.voltage() int: mV

Gets the voltage of the battery.


Battery voltage.

battery.current() int: mA

Gets the current supplied by the battery.


Battery current.

Button and system control

button.pressed() Collection[Button]

Checks which buttons are currently pressed.


Set of pressed buttons.


Sets the button or button combination that stops a running script.

Normally, the center button is used to stop a running script. You can change or disable this behavior in order to use the button for other purposes.


button (Button) – A button such as Button.CENTER, or a tuple of multiple buttons. Choose None to disable the stop button altogether. str

Gets the hub name. This is the name you see when connecting via Bluetooth.


The hub name., offset, write=), offset, read=) bytes

Reads or writes binary data to persistent storage.

This lets you store data that can be used the next time you run the program.

The data will be saved to flash memory when you turn the hub off normally. It will not be saved if the batteries are removed while the hub is still running.

Once saved, the data will remain available even after you remove the batteries.

  • offset (int) – The offset from the start of the user storage memory, in bytes.

  • read (int) – The number of bytes to read. Omit this argument when writing.

  • write (bytes) – The bytes to write. Omit this argument when reading.


The bytes read if reading, otherwise None.


ValueError – If you try to read or write data outside of the allowed range.

You can store up to 128 bytes of data on this hub. The data is cleared when you update the Pybricks firmware or if you restore the original firmware.


Stops your program and shuts the hub down.

system.reset_reason() int

Finds out how and why the hub (re)booted. This can be useful to diagnose some problems.


  • 0 if the hub was previously powered off normally.

  • 1 if the hub rebooted automatically, like after a firmware update.

  • 2 if the hub previously crashed due to a watchdog timeout, which indicates a firmware issue.

Status light examples

Turning the light on and off

from pybricks.hubs import MoveHub
from pybricks.parameters import Color
from import wait

# Initialize the hub.
hub = MoveHub()

# Turn the light on and off 5 times.
for i in range(5):


IMU examples

Testing which way is up

from pybricks.hubs import MoveHub
from pybricks.parameters import Color, Side
from import wait

# Initialize the hub.
hub = MoveHub()

# Define colors for each side in a dictionary.
    Side.TOP: Color.RED,
    Side.BOTTOM: Color.BLUE,
    Side.LEFT: Color.GREEN,
    Side.RIGHT: Color.YELLOW,
    Side.FRONT: Color.MAGENTA,
    Side.BACK: Color.BLACK,

# Keep updating the color based on detected up side.
while True:

    # Check which side of the hub is up.
    up_side = hub.imu.up()

    # Change the color based on the side.

    # Also print the result.

Reading acceleration

from pybricks.hubs import MoveHub
from import wait

# Initialize the hub.
hub = MoveHub()

# Get the acceleration tuple.

while True:
    # Get individual acceleration values.
    x, y, z = hub.imu.acceleration()
    print(x, y, z)

    # Wait so we can see what we printed.

Button and system examples

Using the stop button during your program

from pybricks.hubs import MoveHub
from pybricks.parameters import Color, Button
from import wait, StopWatch

# Initialize the hub.
hub = MoveHub()

# Disable the stop button.

# Check the button for 5 seconds.
watch = StopWatch()
while watch.time() < 5000:

    # Set light to green if pressed, else red.
    if hub.button.pressed():

# Enable the stop button again.

# Now you can press the stop button as usual.

Turning the hub off

from pybricks.hubs import MoveHub
from import wait

# Initialize the hub.
hub = MoveHub()

# Say goodbye and give some time to send it.

# Shut the hub down.

Making random numbers

The Move Hub does not include the urandom module. If you need random numbers in your application, you can try a variation of the following example.

To make it work better, change the initial value of _rand to something that is truly random in your application. You could use the IMU acceleration or a sensor value, for example.

from pybricks.hubs import MoveHub

# Initialize the hub.
hub = MoveHub()

# Initialize "random" seed.
_rand = hub.battery.voltage() + hub.battery.current()

# Return a random integer N such that a <= N <= b.
def randint(a, b):
    global _rand
    _rand = 75 * _rand % 65537  # Lehmer
    return _rand * (b - a + 1) // 65537 + a

# Generate a few example numbers.
for i in range(5):
    print(randint(0, 1000))