Student's Companion: LEGO SPIKE Prime
A student-first, self-paced companion for LEGO SPIKE Prime. This tool lets students follow the same 14-week robotics journey used in class, but written directly for them. Each week explains the goal in simple language, gives a numbered checklist, links to official LEGO SPIKE resources, and includes ready-to-type Python code plus 'if things go wrong' tips.
You can learn LEGO robotics on your own.
This page is written directly for students. You don't need a robotics teacher next to you. Each week gives you four things:
1. What you are trying to do
A short story for the week and what your robot should be able to do at the end.
2. Step-by-step checklist
Numbered steps you can follow in order: read a step, do it with your robot, tick it off, then move on.
3. Python code
Ready-to-type Python examples. You copy them into the LEGO SPIKE App and then tweak them for your own ideas.
4. If things go wrong
Common mistakes and quick fixes for when the robot doesn't behave how you expect.
Official LEGO SPIKE resources
Keep these tabs open while you work:
- LEGO Education SPIKE hub (projects and help): SPIKE Prime product & resources
- LEGO Education SPIKE software (where you type code): Download the SPIKE App
How to use the "Teacher Script" boxes
This student guide reuses explanations from the teacher version. Whenever you see a yellow box labelled "Teacher Script", just read it to yourself and treat it as instructions for you. In this guide, you are your own teacher.
When you are ready, start at Week 1 and move forward in order. Aim for one week per lesson, but it's okay to go faster or slower.
Wake the Robot Brain
At a glance
Big idea: Your yellow Hub is a brain that is currently "asleep". You will wake it up with a tiny Python program.
- Robotics experience needed: None. You just follow this page step by step.
- Python experience needed: None. You will type a few short lines and read the explanations underneath.
- Main outcomes: Battery inserted, Hub connected over Bluetooth, and your first program runs successfully on the Hub display.
Before you start
- A LEGO SPIKE Prime kit with a Hub, battery, charging cable, and at least two motors in the box.
- A laptop or tablet with the LEGO SPIKE App installed (Python mode available).
- A USB cable or working Bluetooth on your device.
- Optional but helpful: open the LEGO Education SPIKE Prime resources page in a separate tab.
Story to understand before you code (10β15 mins)
Read this slowly. If you have teammates, you can read it out loud as if you are the teacher.
- The story: "This yellow brick is a $300 brain. Right now, it is in a coma. Today you will perform brain surgery to wake it up using a language called Python."
- Libraries:
Write (or just look at) this line:
from hub import light_matrix. Think of Python as an empty toolbox. You import the tools you need. Today you import the Hub's tiny light display. - Goal: Your mission is to make the Hub count down 5-4-3-2-1 and then show a happy face. That tells you the brain is awake and listening.
Phase 1 β Get your kit ready (10β15 mins)
Before opening the laptop, get control of the LEGO pieces so they do not explode across the room or table.
"I am the Floor Shark. Any LEGO piece that touches the floor belongs to me. To get it back, you have to answer a Python question. Keep your pieces on the table!"
As a student, you can still use this rule with your team. Decide what happens when a piece falls on the floor.
- Sort pieces roughly into the main tray sections (it does not need to be perfect).
- Check that the Hub, battery, and motors are in the kit and easy to find.
- Remember: organized kits = more building and coding time later.
Phase 2 β Your first script (30β40 mins)
Now you will create your first Python program. Follow these steps slowlyβdon't rush the typing.
- Connect the Hub: Insert the battery into the Hub, turn it on, and connect via Bluetooth or USB inside the SPIKE app (follow the onβscreen prompts).
- Create a Python project: In the SPIKE app, create a new project and choose the Python option (not word blocks).
- Type the code: Look at the code example below. Type each line carefully. If you get stuck, read the explanation under the code.
- Run the program: Press the Run button in the SPIKE app. Check that the numbers and happy face appear on the Hub.
- Extension (if you have time): Change the message, speed, or picture and see what happens.
The First Script: Waking the Robot
from hub import light_matrix
import runloop
async def main():
# Countdown
await light_matrix.write("54321")
await runloop.sleep_ms(1000)
# Show Life
await light_matrix.show_image(light_matrix.IMAGE_HAPPY)
runloop.run(main())
What each part does
- Lines 1β2:
Import the tools you need: the Hub display (
light_matrix) and the timing tool (runloop). -
async def main():creates a mission calledmain. Everything indented underneath is part of that mission. - Countdown:
await light_matrix.write("54321")writes the numbers on the Hub. Theawaitkeyword means "finish this before moving on". - Pause:
await runloop.sleep_ms(1000)waits for 1 second (1000 milliseconds) so you can see the countdown. - Happy face:
await light_matrix.show_image(light_matrix.IMAGE_HAPPY)shows a builtβin happy face on the Hub screen. - Launch:
runloop.run(main())actually starts the mission. Without this line, nothing happens.
If things go wrong
- Hub won't connect: Turn the Hub off and back on, then try the Bluetooth connection again in the SPIKE app. Move other devices a little farther away if there is interference.
- Code won't run:
Check that all lines start at the left edge except the lines under
async def main():. Those indented lines must line up under each other. Python is very strict about spaces. - Typing feels slow: Read the code out loud while you type, or take turns if you are in a pair. You can copy from this page exactly.
The Handshake (Teaching the Robot Its Legs)
At a glance
Big idea: You build the first driving base and teach the brain (Hub) to recognize its legs (motors) so it can drive in a straight line.
- Robotics experience needed: None. You follow the build instructions and a simple script.
- Python experience needed: Very little. You will copy one short program.
- Main outcomes: Drive Base 1 is built, motors are paired with the Hub, and the robot completes a simple drag race (forward, pause, backward).
Before you start building
- Open the SPIKE app and find the build for Drive Base 1 ("Competition Ready β Training Camp 1: Driving Around").
- Optional: on the LEGO Education SPIKE Prime page you can explore other builds and lessons.
- Check that your kit has two motors and a Hub with enough battery.
- Choose a flat place to run your drag race (a 1 metre strip on the floor or a long table).
Understand the handshake story (10β15 mins)
Read this explanation before you write code. Imagine explaining it to a friend who just joined your team.
"The Hub is smart, but it is blind. It doesn't know it has legs. If we tell it to 'Drive', it will say 'With what?'. We have to introduce the Brain to the Wheels. We call this The Handshake."
-
In your code (or on paper), look at this line:
motor_pair.pair(motor_pair.PAIR_1, port.C, port.D)and noticeCandD. You are telling the brain which ports are the wheels. - Draw a quick sketch of the Hub and label ports C and D. On your real robot, trace the cables and make sure C is left and D is right.
- Remember: once the handshake is done, you can say "Drive!" and both wheels move together like a threeβlegged race team.
Phase 1 β Build the robot (40β60 mins)
Follow the official instructions to build Drive Base 1.
"Welcome, Pit Crews. Today isn't about coding; it's about building a machine that can survive a drag race. A loose wheel means disaster on the track. Go!"
- If you are working in a team, give one person the job of finding pieces and one the job of building.
- Swap jobs every 15 minutes so everyone gets handsβon time.
- Press on each wheel and check that it is firmly attached and that cables are not tangled.
Phase 2 β The drag race code (30β40 mins)
Now that the robot has legs, you will give it a simple mission: drive forward 50cm, pause, then drive back.
- Confirm motors are plugged into ports C (left) and D (right).
- Create a new Python project in the SPIKE app.
- Type the code below, one line at a time, checking spelling and indentation carefully.
- Place the robot at the start of your taped drag strip and run the program.
from hub import port
import motor_pair, runloop
async def main():
# Setup
motor_pair.pair(motor_pair.PAIR_1, port.C, port.D)
# Drive forward 50cm
await motor_pair.move_for_amount(motor_pair.PAIR_1, 50, motor_pair.UNIT_CM, 0, velocity=360)
# Pause for 1 second
await runloop.sleep_ms(1000)
# Drive backward 50cm
await motor_pair.move_for_amount(motor_pair.PAIR_1, 50, motor_pair.UNIT_CM, 0, velocity=-360)
runloop.run(main())
What each part does
- Imports:
from hub import portandimport motor_pair, runloopbring in the tools for wheel control and timing. - Handshake:
motor_pair.pair(...)tells the Hub which ports are the left and right wheels (C and D). - Forward / backward:
move_for_amount(..., 50, motor_pair.UNIT_CM, 0, velocity=...)drives a distance in centimeters with steering0(straight). Positive velocity is forward; negative is backward. - Pause:
runloop.sleep_ms(1000)waits 1 second so you can see the robot stop before reversing. - Launch:
runloop.run(main())starts the mission. Without it, nothing happens.
If things go wrong ("Spin of Doom")
- Robot spins in a circle: One motor cable is in the wrong port. Trace each wire from motor to Hub and fix either the code letters or the ports so they match (C with C, D with D).
- Robot doesn't move:
Make sure
motor_pair.pair(...)is above the movement lines and that the Hub is turned on. - Error "NameError: motor_pair is not defined":
Add
import motor_pairat the top of the file.
Navigation (Driving in a Square)
At a glance
Big idea: Instead of writing the same movement over and over, you use a loop to make the robot drive in a square.
- Robotics experience needed: You already have Drive Base 1 from Week 2.
- Python experience needed: You know basic movement; this week introduces the
forloop. - Main outcomes: You write a loop to drive four equal sides and adjust the turning amount (around 176 degrees) so your robot makes clean 90Β° corners.
Before you start
- Make sure your robot is still built as Drive Base 1 with motors on ports C and D.
- Clear a square area on the floor or table for testing. Optional: tape a large square route.
- Have a ruler or measuring tape so you can estimate 20cm segments.
Understand the loop story (10β15 mins)
"I want you to clap your hands 4 times. Did I say 'Clap, Clap, Clap, Clap'? No. That's exhausting. I said 'Clap times 4'. In Python, if you write the same code twice, you are working too hard. We use a Loop."
- Sketch a square path with four equal sides. Label each side "Forward" and each corner "Turn".
-
Write this mini-loop:
for i in range(4):and remember it means "repeat the next steps 4 times". - Notice that turning the wheel 90 degrees does not turn the robot 90 degrees. You must experiment to find the magic number (around 176).
Phase 1 β The turning mystery (20β30 mins)
Goal: Feel the difference between wheel degrees and robot degrees.
- Guess: if you turn the wheel 90 degrees, will the robot turn 90 degrees?
- Test different turning amounts (for example 90, 140, 176 degrees) and watch how far the robot turns.
- Write down which number gets you closest to a clean corner (usually around 176Β°).
Phase 2 β The square challenge (40β50 mins)
Mission: Drive in a perfect square: forward, turn right, repeat 4 times.
- Sketch the square path and label each side 20cm.
- Plan that the loop will run 4 times: drive forward, then turn, then repeat.
- Type the full program below, then tweak the turning amount until the robot ends where it started.
from hub import port
import motor_pair, runloop
async def main():
motor_pair.pair(motor_pair.PAIR_1, port.C, port.D)
for i in range(4):
# Forward 20cm
await motor_pair.move_for_amount(motor_pair.PAIR_1, 20, motor_pair.UNIT_CM, 0, velocity=360)
# Turn (tune this value, e.g., 176 degrees)
await motor_pair.move_for_amount(motor_pair.PAIR_1, 176, motor_pair.UNIT_DEGREES, 100, velocity=360)
runloop.run(main())
What each part does
- Loop header:
for i in range(4):means "repeat the indented steps 4 times" (one for each side of the square). - Forward motion:
move_for_amount(..., 20, motor_pair.UNIT_CM,...)drives about 20cm for each side. - Turn:
move_for_amount(..., 176, motor_pair.UNIT_DEGREES, 100,...)spins the wheels so the robot turns roughly 90Β°. You adjust 176 until the square closes cleanly. - Steering = 100: This is a "spot turn" where the wheels spin in opposite directions so the robot pivots.
If things go wrong
- Square doesn't close: Adjust the turning amount (try 170, 176, 182) until the robot ends close to the starting point.
- Robot turns the wrong way:
Change the steering from
100to-100(right vs. left turn). - Robot only moves once:
Check that the forward and turn lines are indented under the
forloop.
Steering (The Slalom)
At a glance
Big idea: Steering is not just left or right. It is a dial that controls how sharply the robot turns.
- Robotics experience needed: You already have a working Drive Base from Weeks 2β3.
- Python experience needed:
You can already move forward and turn. This week you adjust the
steeringparameter to drive in curves. - Main outcomes: You understand steering values (0, 20, 50, 100) and program a slalom path weaving between cups without touching them.
Before you start this mission
- Check your robot is still Drive Base 1 with motors on ports C and D.
- Prepare at least 3 cups or small objects to act as slalom cones.
- Mark a straight lane with tape and place the cups in a line with enough space to weave between them.
Steering story (10β15 mins)
Use this explanation to think about steering like a volume knob. Read it out loud if you are working with a partner.
"We know Steering=0 is straight. We know Steering=100 is a sharp spin. But what happens if we pick 50? Or 20? Today we aren't turning corners; we are driving in arcs."
Think of this cheat sheet:
The "Steering Knob" Cheat Sheet
Phase 1 β Steering practice (20β30 mins)
Goal: See how different steering values change the path.
- Drive the robot straight with steering
0for a short distance. -
Repeat with steering
20, then50, then100, and describe each path (gentle curve vs. pivot vs. spin).
Phase 2 β The slalom challenge (40β50 mins)
Mission: Program the robot to weave around the cups in an S-shape without knocking them over.
- Place three cups in a straight line along the lane.
- Use two curves: curve right (positive steering) then curve left (negative steering).
- Adjust the distance and steering until the robot passes between the cups cleanly.
from hub import port
import motor_pair, runloop
async def main():
motor_pair.pair(motor_pair.PAIR_1, port.C, port.D)
# Curve right
await motor_pair.move_for_amount(motor_pair.PAIR_1, 500, motor_pair.UNIT_DEGREES, 50, velocity=360)
# Curve left
await motor_pair.move_for_amount(motor_pair.PAIR_1, 500, motor_pair.UNIT_DEGREES, -50, velocity=360)
runloop.run(main())
What each part does
- Steering:
The third argument (
50or-50) controls how sharply you turn and in which direction. - Distance:
500withUNIT_DEGREEScontrols how long the curve lasts; you can change this to make longer or shorter arcs. - Velocity:
velocity=360sets the speed. Slower speeds make it easier to pass between the cups.
If things go wrong
- Robot hits the cups:
Reduce the steering (for example from
50to30) or the distance (for example from500to350). - Robot turns too late or too early: Adjust the first curve distance or add a short straight drive before curving.
- Robot spins instead of curving:
Check that steering is not
100. Values near 100 create spot turns, not arcs.
Force Sensor (Touch)
At a glance
Big idea: Your robot needs a sense of touch. With a Force Sensor and a while loop, it can bump into a wall, stop, beep, and back up.
- Robotics experience needed: You upgrade to Drive Base 2 with a Force Sensor mounted on the front.
- Python experience needed:
You already know movement; this week you use a
whileloop for "wait until" logic. - Main outcomes: Your robot drives forward, waits for a collision, then stops, beeps, and reverses safely.
Before you start
- Upgrade your robot to Drive Base 2 using the official LEGO instructions.
- Mount the Force Sensor on the front and plug it into Port E.
- Set up a solid wall or box for the robot to bump into (never a person).
Concept story (10β15 mins)
"Close your eyes. Walk forward slowly. How do you know when to stop? You feel the wall. Right now, our robot is numb. We need to give it a central nervous system."
- Look at the Force Sensor and press it with your finger. This is the robot's fingertip.
-
Write (or read) the line
while not force_sensor.is_pressed(port.E):and remember it means: "keep waiting until the button is pressed".
Phase 1 β Bumper car mission (40β50 mins)
Mission: Drive forward until the robot hits the wall, then stop, beep, and reverse.
- Place the robot a safe distance from the wall with the Force Sensor pointing forward.
- Type the full program below and predict what will happen when the robot touches the wall.
- Run the program and watch for the exact moment the sensor is pressed.
from hub import port, sound
import motor_pair, force_sensor, runloop
async def main():
motor_pair.pair(motor_pair.PAIR_1, port.C, port.D)
# Start moving forward
motor_pair.move(motor_pair.PAIR_1, 0, velocity=360)
# Wait for impact
while not force_sensor.is_pressed(port.E):
await runloop.sleep_ms(10)
# On collision: stop, beep, and back up
motor_pair.stop(motor_pair.PAIR_1)
await sound.beep()
await motor_pair.move_for_amount(motor_pair.PAIR_1, 10, motor_pair.UNIT_CM, 0, velocity=-360)
runloop.run(main())
What each part does
- Continuous driving:
motor_pair.move(...)starts the robot and keeps it moving until you tell it to stop. - Wait loop:
while not force_sensor.is_pressed(port.E):means "keep looping while the button is not pressed". - Pause between checks:
await runloop.sleep_ms(10)checks the sensor every 10 milliseconds so the program stays responsive. - Recovery: after the crash, the robot stops, beeps, and reverses 10cm away from the wall.
If things go wrong
- Robot never stops:
Check that the Force Sensor is really on Port E and pushed in firmly. Make sure the
whileline usesport.E, not another letter. - Robot stops immediately: The sensor might already be pressed against the wall or a LEGO piece. Pull the robot back a little and try again.
- Error about
force_sensor: Check thatimport force_sensoris at the top of the file.
Distance Sensor (Bat Vision)
At a glance
Big idea: The robot can "see" how far away walls are using sound, like a bat. You teach it a safety rule: if distance < 10cm, stop.
- Robotics experience needed: Drive Base 2 with Distance Sensor attached to the front (usually Port F).
- Python experience needed:
You know
whileloops from Week 5; this week adds a comparison (<) and the special value-1for "no object". - Main outcomes: Your robot drives toward a wall and stops itself at about 10cm before crashing.
Before you start
- Upgrade your robot to Drive Base 2 and mount the Distance Sensor on the front (Port F).
- Set up a solid wall or box as the target. Avoid soft surfaces like pillows or clothing.
- Have a ruler or tape measure ready so you can see what 10cm looks like.
Physics story (10β15 mins)
Topic: Echolocation & thresholds.
"Bats don't need to touch a wall to know it's there. They use sound. Our robot has ultrasonic eyes. We need to teach it: 'If distance is LESS THAN 10cm, STOP.'"
Common failure: The Sweater
If someone stands in front of the robot wearing a wool sweater, the robot might crash. Soft clothes absorb sound, so the echo never comes back. Use a hard book or box as the obstacle.
Phase 1 β Measuring distance (15β20 mins)
Let yourself see the numbers from the Distance Sensor.
- Notice how the sensor returns numbers in centimeters and
-1when it sees "infinity" (nothing). - Move the robot closer and farther from the wall and call out the distances.
Phase 2 β Don't crash (40β50 mins)
Mission: Drive toward the wall and stop at around 10cm.
- Place the robot facing the wall with at least 50β80cm of space.
- Type the full program below.
- Test and adjust the 10cm threshold if needed for your surface.
from hub import port
import motor_pair, distance_sensor, runloop
async def main():
motor_pair.pair(motor_pair.PAIR_1, port.C, port.D)
# Drive forward until it's too close
motor_pair.move(motor_pair.PAIR_1, 0, velocity=360)
while True:
dist = distance_sensor.get_distance_cm(port.F)
if dist != -1 and dist < 10:
# Too close! Stop and break out of the loop
motor_pair.stop(motor_pair.PAIR_1)
break
await runloop.sleep_ms(10)
runloop.run(main())
What each part does
- Distance reading:
distance_sensor.get_distance_cm(port.F)returns the distance in centimeters, or-1if nothing is detected. - Threshold:
dist < 10defines the "danger zone" near the wall. - Error check:
dist != -1makes sure you ignore the "infinity" value. - Loop:
while Truekeeps checking until the robot is too close, then breaks out.
If things go wrong
- Robot doesn't stop: Check that the sensor is plugged into Port F and pointed at a hard surface. Try increasing the threshold to 15cm if the floor is very shiny.
- Distance always -1: The sensor may be angled away from the wall or looking at something too soft to reflect sound.
- Error about
distance_sensor: Make sureimport distance_sensoris at the top of the file.
Color Sensor (Traffic Decisions)
At a glance
Big idea: The robot reads colors and uses if / elif decisions to follow simple traffic rules.
- Robotics experience needed: Same drive base; add a Color Sensor pointing at the floor (usually Port A).
- Python experience needed:
You know loops; this week you combine a
while Trueloop withif / elifdecisions. - Main outcomes: Your robot drives over green and red patches, speeding up on green and stopping on red.
Before you start
- Attach the Color Sensor pointing down and plug it into Port A.
- Tape pieces of green and red paper to the floor or table where the robot will drive.
Logic story (10β15 mins)
"We are teaching the robot to follow laws. Green means Turbo Boost. Red means Stop. This is called an IF / ELSE statement."
- Draw a simple tree: "Is it GREEN?" β Go Fast. "Else, is it RED?" β Stop.
- Remember: the robot checks one condition at a time, in order.
Phase 1 β Traffic school activity (40β50 mins)
Mission: Drive slowly until the robot sees green or red.
- Place green and red patches along the robot's path.
- Type the program below and test whether the robot speeds up on green and stops on red.
from hub import port
import motor_pair, color_sensor, runloop
async def main():
motor_pair.pair(motor_pair.PAIR_1, port.C, port.D)
while True:
color = color_sensor.get_color(port.A)
if color == color_sensor.GREEN:
# Turbo boost on green
motor_pair.move(motor_pair.PAIR_1, 0, velocity=500)
elif color == color_sensor.RED:
# Full stop on red
motor_pair.stop(motor_pair.PAIR_1)
await runloop.sleep_ms(50)
runloop.run(main())
What each part does
- Color reading:
get_color(port.A)returns a constant likecolor_sensor.REDorcolor_sensor.GREEN. - Decision:
if ... elif ...checks for green first, then red. - Loop:
while Truekeeps checking colors for as long as the robot is running.
If things go wrong
- Robot ignores colors: Check that the sensor is close enough to the floor and pointing at the paper, and that you are using Port A in the code.
- Robot always goes fast: The sensor may be reading green all the time. Move the patches farther apart or slow down the robot.
Line Following (The Wiggle)
At a glance
Big idea: Line following is a "holy grail" robotics skill. The robot cannot actually see a line; it only measures brightness and constantly nudges left/right to stay on the edge.
- Robotics experience needed: Same drive base and Color Sensor as Week 7.
- Python experience needed:
You are comfortable with loops and
if. This week you tune thresholds. - Main outcomes: Your robot follows a curvy black tape line by "wiggling" around its edge.
Before you start
- Lay a long, curved strip of black electrical tape on a light-coloured floor or board.
- Position the Color Sensor so it watches the tape from a few millimetres above the surface.
The hardest concept of the term
You might think the robot sees a line. It doesn't. It only sees the floor as "Bright" or "Dark".
You do not drive on the line. You drive along the edge between light and dark.
The Wiggle Algorithm:
- Am I on White (Bright)? β I'm falling off the left! Turn Right.
- Am I on Black (Dark)? β I'm falling off the right! Turn Left.
- Result: The robot wiggles back and forth along the edge.
Optional math helpers
If you like seeing the math behind distance and turning, you can explore these tools while working on line following:
- Wheel Distance Explorer β shows how wheel size and wheel turns relate to distance travelled.
- Move + Turn Trainer β lets you practice simple drives and turns before you add sensors.
Phase 1 β Wiggle demo (15β20 mins)
- Walk along a tape line and act out the algorithm: "Too bright β turn right. Too dark β turn left." Say it out loud as you move.
- Remember: the robot repeats this check many times per second.
Phase 2 β Line following mission (40β50 mins)
Mission: Follow a curvy tape line from start to finish without leaving it.
- Place the robot so the Color Sensor sits over the edge of the black tape.
- Type the full line-following program below.
- Test, then tweak the threshold value (starting at 50) if your surface is lighter or darker.
from hub import port
import motor_pair, color_sensor, runloop
async def main():
motor_pair.pair(motor_pair.PAIR_1, port.C, port.D)
while True:
light = color_sensor.get_reflection(port.A)
# 50 is usually the midpoint between white (100) and black (0)
if light < 50:
# See dark β turn toward white
motor_pair.move(motor_pair.PAIR_1, 0, velocity=150, steering=50)
else:
# See bright β turn toward black
motor_pair.move(motor_pair.PAIR_1, 0, velocity=150, steering=-50)
await runloop.sleep_ms(10)
runloop.run(main())
What each part does
- Reflection value:
get_reflection()returns a brightness number from 0 (black) to 100 (white). - Threshold:
50is a starting guess for the "edge" between floor and tape. You can change it to 40 or 60 if needed. - Steering:
50and-50gently steer toward one side or the other instead of making sharp turns.
If things go wrong
- Robot leaves the line:
Lower the speed (for example
velocity=120) or increase the steering values slightly. - Robot oscillates too much:
Reduce steering (for example from
50to30) to make smoother corrections. - Sensor doesn't see the tape: Make sure the tape is really black and the floor is lighter, and that the sensor is close enough to the surface.
The Mechanical Build
At a glance
Big idea: Your robot transforms into an advanced drive base with gears and an arm (Drive Base 3).
- Robotics experience needed: You are familiar with Drive Base 1β2 builds.
- Python experience needed: None new this week. Focus is on careful building.
- Main outcomes: Drive Base 3 is fully built with good cable management and working gears.
Before you start
- Open the LEGO instructions for Drive Base 3 (Competition Ready β Training Camp 4).
- Check that your kit has all beams, gears, and the extra motor required for the arm.
- Plan enough time: this is a long build (up to 90 minutes).
Story & expectations (10 mins)
"We are no longer just observers. We are engineers. Today we disassemble our scout and build a machine that can move the world. This build is complex. Patience is key."
- Todayβs success is a strong, reliable build, not new code.
- Slow down and double-check each step in the instructions.
Phase 1 β The big build (60β90 mins)
- Carefully dismantle your old drive base and sort useful parts.
- While you build, count the teeth on key gears and guess what changing gear ratios might do to speed or strength.
- Check that cables are neat and not wrapped tightly around moving parts.
The Claw (Single Motors)
At a glance
Big idea: The arm is not a pair of wheels. It is a single motor you control directly using degrees.
- Robotics experience needed: Drive Base 3 from Week 9, with an arm on Port E.
- Python experience needed:
You learn to use
motor.run_for_degrees()and combine motion with the claw. - Main outcomes: Your robot can raise/lower the arm to grab and place an object.
Before you start
- Confirm the arm motor is plugged into Port E.
- Prepare a small brick and a raised surface (like a book) to act as the drop-off spot.
Concept story (10β15 mins)
"The Arm is not a wheel. We don't pair it. We talk to it directly. We also don't use 'seconds' or 'cm'. We use Degrees. Like an elbow, it has a limit. If you force it too far, it breaks."
-
Think of
await motor.run_for_degrees(port.E, 90, velocity=300)as bending an elbow 90 degrees.
Phase 1 β Forklift mission (40β50 mins)
Mission: Start with the arm up, drive to a brick, lower the arm to grab it, lift it, drive forward, and place it gently on a book.
- Place a brick in front of the robot and a book a short distance away.
- Type the full program below, then fine-tune degrees to match your specific arm build.
from hub import port
import motor_pair, motor, runloop
async def main():
# Pair the drive motors
motor_pair.pair(motor_pair.PAIR_1, port.C, port.D)
# Lower arm to grab (tune degrees for your build)
await motor.run_for_degrees(port.E, -90, velocity=300)
# Drive forward to the drop-off
await motor_pair.move_for_amount(motor_pair.PAIR_1, 20, motor_pair.UNIT_CM, 0, velocity=360)
# Lift arm to place
await motor.run_for_degrees(port.E, 90, velocity=300)
runloop.run(main())
What each part does
- Single motor control:
motor.run_for_degrees(port.E,...)moves only the arm, not the wheels. - Degrees: Positive values raise the arm; negative values lower it (depending on how it was built).
- Drive and arm together: You are now combining drive code with arm code in a single mission.
If things go wrong
- Arm hits the robot or table: Reduce the degrees (for example 60 instead of 90) and re-test.
- Arm moves backwards from what you expect: Swap the sign (+/-) on the degrees.
- Error about
motor: Make sureimport motoris at the top of the file.
Functions (The Lazy Coder)
At a glance
Big idea: Instead of repeating the same arm code over and over, you give it a name and call it as a function.
- Robotics experience needed: Same robot as Week 10.
- Python experience needed: You create and use your first custom function.
- Main outcomes:
Your program has a
grab_thing()function that you call from the main code.
Before you start
- No special build changes; use the robot from Week 10.
-
Think of a simple non-robot example of a function, like:
def morning(): wake_up(), eat(), brush().
Concept story (10β15 mins)
"I am lazy. I don't want to write the code to 'Open the Claw' 50 times. I want to write it once, give it a name, and just call the name. This is a Function."
-
First imagine a function in English (for example
morning()β wake up, eat, brush). -
Then look at the Python version:
async def grab_thing():and notice that everything indented under it belongs to that function.
Phase 1 β Build the function (25β30 mins)
Mission:
Create a grab_thing() function that opens and closes the claw.
- Type the function definition
async def grab_thing():and put the arm code inside it. - At first, just test the function by calling it once; make sure it moves the arm correctly.
Phase 2 β Use the function in a mission (25β30 mins)
Mission:
Drive to a brick, use grab_thing() to pick it up, and then return.
- Add calls to
grab_thing()in your main code at the right time. - Run the program and adjust arm degrees as needed.
from hub import port
import motor_pair, motor, runloop
async def grab_thing():
# Close and open the claw
await motor.run_for_degrees(port.E, 90, velocity=300)
await runloop.sleep_ms(500)
await motor.run_for_degrees(port.E, -90, velocity=300)
async def main():
motor_pair.pair(motor_pair.PAIR_1, port.C, port.D)
# Drive forward to the object
await motor_pair.move_for_amount(motor_pair.PAIR_1, 20, motor_pair.UNIT_CM, 0, velocity=360)
# Use the custom function
await grab_thing()
runloop.run(main())
What each part does
- Function definition:
async def grab_thing():teaches Python a new command. - Reuse:
Whenever you write
await grab_thing(), Python runs all the steps inside the function. - Organization: Functions make long programs easier to read and change.
If things go wrong
- Function never runs:
Check that you have
await grab_thing()insidemain(). - Indentation errors:
Make sure the lines inside
grab_thing()are indented one level, and the lines inmain()are indented under it.
Strategy & Logic
At a glance
Big idea: Plan your final competition mission on paper before you touch the robot.
- Robotics experience needed: You know how to drive, use sensors, and move the arm.
- Python experience needed: Today you mostly use "pseudo-code" (plain English steps) instead of real code.
- Main outcomes: Your team has a clear written plan for how your robot will complete the mission.
Before you start
-
Set up a simple competition field with:
- Zone A: Base
- Zone B: Sample/brick area
- Zone C: Drop-off zone
- Prepare large paper and pencils or markers for your team.
No Robots Today
Today is for paper and pencil. Map out your path for the final competition, measure distances, and write "pseudo-code" (fake code) on paper.
Optional planning helper
To estimate how far your robot travels for a given time and speed while you plan, you can use Move-for-Time Path Forecaster . It helps you connect seconds, speed, and distance while you plan.
Test, Fail, Fix
At a glance
Big idea: Failure is expected. You learn to debug robots systematically.
- Main outcomes: You run your planned mission, find problems, and improve your code or build.
Engineering mindset (10 mins)
"Your robot will fail today. That is good. If it works the first time, you are lucky, not smart. Find the bug. Fix the bug. Try again."
The Class Cup
π The Rules
- 2.5 minutes per run.
- Robot starts in Base.
- Autonomous Only: If you touch it outside of base, penalty!
- Points for: Leaving Base, Following Line, Delivering Brick.
Error Help
Click the error message that matches what you see in the SPIKE App.
Expand your expertise
Recommended deep dives and guides matched to Student's Companion: LEGO SPIKE Prime.