In this project, we will show you how to control the LEGO® Technic Liebherr Crawler Crane (42146) with the Powered Up (Train) Remote.

This gives you precise control over each of the crane’s functions without having to use a phone or tablet. You can drive it around with the red and grey buttons, and use the green button to switch between controlling the base and the crane functions.

This crane has two hubs, so we’ll also show you how to connect them via Bluetooth.

Driving the LEGO® Technic Liebherr Crawler Crane (42146) with the Powered Up remote.
Driving the LEGO® Technic Liebherr Crawler Crane (42146) with the Powered Up remote.

Requirements

To follow this project, you will need the following:

See this overview for all compatible models.

Understanding the code

This project has two programs, one for each hub. The hub in the base connects to the Powered Up remote and drives the vehicle. It also calculates the required speeds of the crane functions based on your input, and broadcasts these to the other hub in the crane.

The crane hub receives these messages and controls the crane functions accordingly. While the order of installation doesn’t matter, it’s practical to download and run the crane program first. Because it simply starts and stops the crane functions based on the incoming signals, you can customize all the actions in the program for the hub in the base instead.

When sending numbers, communication works best if you send small numbers. So we just send the speed values as percentages, and multiply them by a factor in the crane program to get the desired speed.

The program for the hub in the crane receives three values and sets the crane motor speed functions accordingly.
The program for the hub in the crane receives three values and sets the crane motor speed functions accordingly.
The program for the hub in the base receives the Powered Up remote input, drives and turns the base, and broadcasts the required speeds for the crane functions to the other hub. Switch to crane mode with the green button.
The program for the hub in the base receives the Powered Up remote input, drives and turns the base, and broadcasts the required speeds for the crane functions to the other hub. Switch to crane mode with the green button.

Running the Pybricks program

This project uses Pybricks on your LEGO hub. Pybricks makes your creations come alive and helps you unlock the full potential of your LEGO Technic, City, MINDSTORMS, BOOST, or Spike sets.

If you haven’t already, install Pybricks on your hub as shown below, or check out our getting started guide for more details. You can go back to the LEGO firmware and apps at any time.

Install the Pybricks firmware.
settings
install

Now import the program you downloaded earlier, as shown below. Click to connect your hub and ▶ to start!

Import a Pybricks Code project.
files
import
open
connect
run

You can run imported block programs even if you’re not signed up. This is a great way to try out Pybricks and see how it works.

In this project, you have two hubs. Installation works the same for both. During installation, you can give each hub a unique name such as Base or Crane, which makes it easier to tell them apart when you connect later.

The crane in action

When you’re ready, you can operate the crane as shown below!

Communication between the two hubs works best if you disconnect them from your computer.

Running it as a Python program

You can also run this project as a Python (MicroPython) program. The following code was generated from the block program above. To run it, create a new empty Python program in Pybricks and copy the code into it.

from pybricks.hubs import TechnicHub
from pybricks.parameters import Axis, Direction, Port, Stop
from pybricks.pupdevices import Motor
from pybricks.tools import wait

# Set up all devices.
hub = TechnicHub(top_side=Axis.Z, front_side=Axis.X, broadcast_channel=0, observe_channels=[5])
boom = Motor(Port.A, Direction.CLOCKWISE)
jib = Motor(Port.D, Direction.CLOCKWISE)
hoist = Motor(Port.B, Direction.CLOCKWISE)

# Initialize variables.
boom_speed = 0
jib_speed = 0
hoist_speed = 0


# The main program starts here.
while True:
    # Get and unpack data sent from the hub in the base.
    # This unpack block sets the variables to 0 if there is no data.
    boom_speed, jib_speed, hoist_speed = hub.ble.observe(5) or [0] * 3
    # Operate the boom.
    if boom_speed:
        boom.run(boom_speed * 8)
    else:
        boom.stop()
    # Operate the jib.
    if jib_speed:
        jib.run(jib_speed * 8)
    else:
        jib.stop()
    # Operate the hoist.
    if hoist_speed:
        hoist.run(hoist_speed * 10)
    else:
        hoist.stop()
    wait(50)
Program for the crane hub.
from pybricks.hubs import TechnicHub
from pybricks.parameters import Axis, Button, Color, Direction, Port, Stop
from pybricks.pupdevices import Motor, Remote
from pybricks.tools import wait

# Set up all devices.
hub = TechnicHub(top_side=Axis.Z, front_side=Axis.X, broadcast_channel=5)
left = Motor(Port.C, Direction.CLOCKWISE)
right = Motor(Port.D, Direction.COUNTERCLOCKWISE)
turntable = Motor(Port.B, Direction.CLOCKWISE)
remote = Remote(timeout=None)

# Initialize variables.
boom_speed = 0
jib_speed = 0
hoist_speed = 0

def drive_using_the_buttons():
    # Use the left/right red buttons for the turntable motor.
    if Button.LEFT in remote.buttons.pressed():
        turntable.run(1000)
    elif Button.RIGHT in remote.buttons.pressed():
        turntable.run(-1000)
    else:
        turntable.stop()
    # Use the left +/- for the left track.
    if Button.LEFT_PLUS in remote.buttons.pressed():
        left.run(1000)
    elif Button.LEFT_MINUS in remote.buttons.pressed():
        left.run(-1000)
    else:
        left.stop()
    # Use the right +/- for the left track.
    if Button.RIGHT_PLUS in remote.buttons.pressed():
        right.run(1000)
    elif Button.RIGHT_MINUS in remote.buttons.pressed():
        right.run(-1000)
    else:
        right.stop()


# The main program starts here.
left.control.limits(acceleration=2500)
right.control.limits(acceleration=2500)
while True:
    # First, we are in drive mode, where we operate the base
    # using the buttons, until you press the center button to
    # change the mode.
    remote.light.on(Color.RED)
    while Button.CENTER in remote.buttons.pressed():
        wait(1)
    while not Button.CENTER in remote.buttons.pressed():
        drive_using_the_buttons()
        wait(50)
    # Now we are in crane operation mode. Here we stop driving and
    # broadcast the button values to the other hub, so it can operate
    # the crane functions based on your input. Until you press the
    # center button again.
    remote.light.on(Color.GREEN)
    right.stop()
    left.stop()
    turntable.stop()
    while Button.CENTER in remote.buttons.pressed():
        wait(1)
    while not Button.CENTER in remote.buttons.pressed():
        boom_speed = 100 if Button.LEFT_PLUS in remote.buttons.pressed() else (-100 if Button.LEFT_MINUS in remote.buttons.pressed() else 0)
        jib_speed = 100 if Button.RIGHT_PLUS in remote.buttons.pressed() else (-100 if Button.RIGHT_MINUS in remote.buttons.pressed() else 0)
        hoist_speed = 100 if Button.RIGHT in remote.buttons.pressed() else (-100 if Button.LEFT in remote.buttons.pressed() else 0)
        hub.ble.broadcast([boom_speed, jib_speed, hoist_speed])
        wait(50)
Program for the base hub.