Stage 10: Robot Soccer Cup
We code the mBot in mBlock 5. Keep this tab open all week. Open in a new tab — don’t use the buttons in this page to leave the course.
a soccer mBot that chases the ball and pushes it toward the goal as part of a team
how to pick a role on a team and code a robot for a job, not just a behavior
a robot ready for the end-of-camp Soccer Cup and a demo for your family
Before campers code, show the room:
- Run a striker bot: it finds the ball and pushes it toward the goal. Run a defender bot: it hangs back near home and clears the ball when it comes close.
- Put two on a team and let them play. Point out they aren't talking to each other — each just does its job, and together it looks like teamwork.
- Set the tone for the Cup: "This is a show for your families. Fair play, gentle bots, big cheers."
The big idea
This is the finale, and it is a real team game. Two or more mBots per side share one field and one ball, and try to push the ball into the other team's goal. Everything you built this week comes together — driving, sensing, deciding, priority — pointed at one job: soccer.
The new idea is roles. A whole team running the exact same "chase the ball" code is chaos — every robot piles onto the ball at once. Real teams split the work: a striker goes for the ball and pushes toward the goal; a defender stays home and clears the ball when it gets close. Same robot, same skills — a different job. You will pick a role and code your mBot for it.
striker: find ball → push toward goal
defender: stay home → clear ball when close
together: a team that covers the field
Tape goals at each end of a smooth floor. Use a light ball the robots can push — a foam or ping-pong-style ball works well. Each team gets one color of goal to defend.
- role
- the job a robot does on the team
- striker
- the robot that chases the ball and pushes it to the goal
- defender
- the robot that stays back and clears the ball from home
- teamwork
- robots covering different jobs so the team works together
- demo
- showing your robot to other people
Make sure you've finished Stage 9: Sumo Showdown — soccer reuses its find-and-push behavior. Pick a teammate and decide who will code a striker and who will code a defender.
Build it
Step 1 — Code a striker
A striker is your sumo bot, aimed at the ball: search until something is close ahead, then push it forward toward the goal.
Striker
when green flag clicked set led [all v] to color [#47c621] :: looks wait (3) seconds forever if <(ultrasonic distance (cm) :: sensing) < (25)> then mBot move [forward v] at speed (70) % :: motion else mBot turn [right v] at speed (35) % :: motion end end
Set the ball in front and let it go. The striker spins to find the ball, then drives into it, pushing it ahead. Aim the kickoff so "forward" points toward the other team's goal.
Step 2 — Code a defender
A defender does the opposite job: it waits near its own goal and only pushes when the ball comes close, then returns home. Keep its speed lower so it holds position.
Defender
when green flag clicked set led [all v] to color [#57fff4] :: looks wait (3) seconds forever if <(ultrasonic distance (cm) :: sensing) < (18)> then set led [all v] to color [#ffde59] :: looks mBot move [forward v] at speed (60) % :: motion wait (0.6) seconds mBot move [backward v] at speed (50) % :: motion wait (0.6) seconds else set led [all v] to color [#57fff4] :: looks mBot stop moving :: motion end end
The defender sits still (cyan) until the ball comes near, then lunges to clear it (yellow) and backs up to home. It guards the goal instead of roaming.
Step 3 — Wear your team color
Pick a team color so everyone can tell the teams apart on the field. Set it at the very start, before the kickoff countdown.
Team color
when green flag clicked set led [all v] to color [#ffde59] :: looks
One team yellow, one team cyan — like jerseys. Now the field reads clearly for players and for the families watching.
Pacing Lab
This lab is required before the Cup. The goal is a team that plays a real game, and a demo you are proud to show.
Part A — Team scrimmage and tune-up (25 minutes)
Play a short practice game with your teammate. On paper, plan and adjust your team:
My role: striker / defender
My push speed: ____ → new push speed: ____
One thing that worked: _______________________
One thing to fix: ___________________________
Tune together: if both robots chase the ball, one of you should be more of a defender. If the ball never reaches the goal, your striker may need a higher push speed or a straighter aim.
Part B — Demo rehearsal (10 minutes)
Practice showing your robot out loud, the way you will for your family. Plan three sentences:
1. "My robot's job on the team is ________________."
2. "The hardest part to get working was ___________."
3. "Watch it do this: ___________________________."
Say it to a partner while your robot runs. A demo is a skill — rehearsing it once makes the real thing easy.
Understand it
Soccer looks like the robots are cooperating, but no robot is talking to another. Each one just runs its own simple job — chase, or guard — and teamwork emerges from the jobs fitting together. This is a big robotics idea: a group of simple robots, each following its own rule, can do something that looks coordinated and smart. You saw a hint of it in the maze (simple rule, complex path); here it scales up to a whole team.
Stepping back: across ten stages you went from a box of parts to a robot that drives, lights up, sings, senses, decides, follows, obeys you, solves a maze, holds a ring, and plays on a team. None of the final stages needed many new blocks — they needed the right combination of skills you already had, in the right order, aimed at a goal. That is what it means to be a programmer. The robot was never the hard part. The thinking was, and you did it.
Try this
Try this
Three short experiments. Predict before you run, then test your guess.
If both teammates run the striker code, what happens to the ball? Predict before the scrimmage — then watch it happen and see why roles matter.
Play one game where your striker pushes at speed 70, and one at 90. Faster scores quicker but loses the ball more. Which speed actually wins more games for your team?
You finished the whole course. Which single skill — driving, lights, sound, distance, line, control, maze, sumo — was your favorite, and what would you build next with it?
Test your stage
- Your striker finds the ball and pushes it forward.
- Your defender holds near home and clears the ball when it comes close.
- Your team has two different roles, not two of the same.
- Your robot wears a clear team color.
- Demo check. You can explain your robot's job and show it working in three sentences, out loud.
If it breaks
- The robot pushes the ball the wrong way. "Forward" points wherever the robot is facing. Aim it at the right goal at kickoff, and keep the kickoff direction in mind when you place it.
- It loses the ball constantly. The ball is light and squirts away. Lower the push speed for more control, and use a ball the robot can actually catch against its front.
- Both teammates dogpile the ball. You both coded strikers. One of you switch to the defender role — that is the whole point of roles.
- The ultrasonic misses the ball. A small ball is hard to see. Use a bigger, taller ball, or push whatever comes close rather than aiming for the ball alone.
Run the Cup as the camp's closing event with families watching. Short matches (2–3 minutes), low speeds, and a referee keep it joyful instead of chaotic. Seed the brackets so every camper plays, and celebrate effort and clever code as loudly as goals.
Roles are the lesson — protect them. The instinct is for everyone to chase the ball; insist each team field at least one defender so kids feel why division of labor matters. The "both run striker = dogpile" prediction makes this land before the game even starts.
The demo rehearsal is not optional polish — it is the camper's chance to own what they built. Make sure every kid says their three sentences to a partner before the families arrive. For some, explaining their robot out loud is the proudest moment of the week.