PIPER MAKE

EDUCATOR GUIDES


YOU ARE HERE

Base expedition

Mission 4 of 13

Base expedition: Mission 4 of 14

Traffic Light


Intermediate

60 mins

Grades 3 - 8

MISSION OBJECTIVE

Learn to build and code a working traffic light.

Piperbot and Pip are dealing with an intergalactic traffic jam! In this mission, students will build a series of LEDs and program them to light up in specified ways, introducing hardware inputs and outputs and coded elements like time delays, sequential triggers, and code loops.

View student interface at make.playpiper.com
MISSION CHARACTERS

Piperbot

Pip
MISSION MATERIALS

Computer with USB port and Chrome or Edge browser
Piper Make Base Station or Starter Kit

MISSION RESOURCES

Learning Goals

  1. Students will create programs that use variables to store and modify data.
  2. Students will test and debug (identify and fix errors) a program or algorithm to ensure it runs as intended.
  3. Students will build knowledge by actively exploring real-world issues and problems, developing ideas and theories, and pursuing answers and solutions.
I WILL BE ABLE TO...
  • Build a sequence of 3 LEDs
  • Code my own traffic light

Learning Activities

Extension: Traffic Light PCBA Challenge In this challenge, students will understand how to take a prototype (their traffic light) and turn it into a product that can be used in the real world. In this challenge students will learn about Printed Circuit Board Assembly or PCBA. Instructions are in the make.playpiper.com tutorial that may be accessed on the final step of the Mission Traffic Light or by clicking the SHOW ALL button on the Expedition Teleport Menu then selecting the TRAFFIC LIGHT PCBA Mission.

ELA Extension: Martian Traffic News Article

  • Pair students together or allow them to work independently based on grade level and writing proficiency. Each student (or pair) will write a fictional news article set on Mars, using cause-and-effect reasoning and past-tense narration.
  • Set the scene by choosing a location (e.g., Mars Blvd & Rover Lane) and characters (e.g., Pip, Piperbot, alien travelers, delivery drones). Ask students to describe a traffic incident that was either caused or prevented by a traffic light system.
  • Have them outline the sequence of events and the outcome of the situation. Encourage use of cause-and-effect language, such as:
    • “Because the light turned green too early, the rover sped through the intersection.”
    • “Thanks to the looped condition, traffic was safely stopped.”
  • Students then write their article using a headline, byline, and a lead paragraph to hook the reader. Encourage use of a journalistic tone and include direct quotes from characters if appropriate. Students must use at least three of the following coding vocabulary words: input, condition, loop, output
  • Ask students to peer review each other’s writing for clarity, vocabulary usage, and accurate sequence.
    (Optional) Invite students to create a front-page layout or draw a visual of the Martian traffic scene.
  • Bonus points for using all four vocabulary words and making readers feel like they’re reading a real news story from outer space!

ELD Extension: Martian Traffic Skits
  • Pair students so that each English Learner (EL) is working with a fluent English speaker or a higher-level EL.
  • Each pair will write and perform a short dramatic skit about a traffic scenario on Mars using academic vocabulary, sequencing language, and cause-and-effect statements.
  • Begin by brainstorming imaginative traffic scenes with your partner, such as Piperbot directing hovercars, alien tourists crossing the road, or a delivery rover on a tight schedule.
  • Plan the skit to include at least one problem and solution related to traffic signals.
  • Incorporate academic vocabulary such as: signal, command, traffic, wait, respond, control, malfunction, accident, condition
  • Encourage use of sentence starters like:
    • "Due to the signal malfunction, ___."
    • "As a result, the rover had to ___."
    • "When the light turned red, the alien ___."
    • "If the signal had worked, ___ would not have happened."
  • Write the skit using a script format. Students should use past tense, direct dialogue, and include at least one cause-and-effect statement and one conditional sentence.
  • Rehearse the skit using hand motions, visuals, or props to support clarity and expression.
  • Each pair will perform their skit for the class. Afterward, the audience will reflect on:
    • What was the traffic issue?
    • What was the outcome?
    • Which key vocabulary and sentence structures did they hear?
  • Finally, extend the activity by inviting students to add a “news report” scene where one character explains the incident and how the traffic system could be improved.

Math Extension: Traffic Light Timing
  • Pair students together or allow them to choose their partners.
    Each pair will observe or simulate a traffic light cycle and analyze the timing of red, green, and yellow lights using pattern recognition, time intervals, and conditional reasoning.
  • Start by having students observe or simulate a basic traffic light pattern: red, green, yellow.
    Ask students to record how many seconds each light stays on. Example: Red – 5s, Green – 4s, Yellow – 2s.
  • Have students build a visual timeline or number sequence that represents one full cycle.
    Ask: How long is one complete cycle? What would two full cycles look like?
  • Introduce conditional thinking by asking: “If the shuttle arrives during the yellow light, should it stop or go?”
    Have students write or explain what should happen in each condition and why, using logical reasoning.
  • Challenge students to redesign the timing to improve traffic safety or speed.
    Ask them to present their optimized light cycle (e.g., 6s red, 3s green, 1s yellow) as a pattern and justify their decisions using math vocabulary such as interval, sequence, duration, or probability.
  • Encourage students to compare their designs and discuss which sequence is the most efficient or fair.

Career Connections

Construction Manager: Salary $101,480/yr

Hardware Diagram




Code Diagram




Tutorial Steps

Traffic Light

Help Piperbot and Pip direct intergalactic space traffic with your own traffic light!

Okay, red for stop, yellow for slow, green for go! I can figure out how to build a traffic light with my Pico and some LEDs!
Microcontrollers can control traffic lights using a system that changes the lights on a timer, watches for pedestrians, and adjusts their timing according to the traffic load. These lights ensure traffic flows smoothly in all directions.
Did you know that some traffic lights are called "Puffin" crossings in the UK? Isn't that funny?
Why do you think our UK friends call them puffin crossings?
People in a rush are huffin' and puffin'!
The black and white crossing looks like that bird called a Puffin.
Our UK friends like silly names for things.
It stands for pedestrian-operated user friendly intelligent crossings.

Puffin crossings are pedestrian-operated, user-friendly intelligent crossings that replaced the earlier pelican crossing, which stood for pedestrian light controller crossing.
Click NEXT.

Okay, let's grab the parts I'll need. Hmm, that's hard to see. Hit that icon in the top right corner of the picture to expand it.
Once you've gathered your parts, click NEXT.

Psst, I used this great tool called the Digital View when I was building my LED last time. You should try it!
Click the DIGITAL VIEW tab to see the GPIO pin numbers and where the GROUND (G) pins are.
Ready? Click NEXT.

Okay, let's start with our red LED. I'll need to put a Resistor somewhere in this circuit, right? Why is that again?
When I built that blinking light, I learned it was to keep the current in the circuit from getting too high!
Using your parts, build the circuit shown in the image below:
Remember from the Blink tutorial that LEDs only work when installed correctly.

The long lead of the LED is the anode where the current flows in and should go into the side connected to GP15.

Click NEXT.

Hold on! What's the difference between those GPIO pins and the 3.3V and 5V pins? They all give power, right?
Hmm, good question! I think those 5V and 3.3V pins are "always on." Using code, we can use the GPIO pins to turn the power on and off.
Remember, a basic circuit is a continuous flow of charge from a POWER source to GROUND.

All circuits also have to be connected to GROUND to be complete. In this circuit, we'll create a GROUND rail by connecting a GROUND pin to the (-) blue column on the edge of the Breadboard, as shown in the picture below:
Click NEXT.

Okay, let me check my wiring. If I were a little electron in this circuit, where would I be going?
The animation below shows the path that the electrical current will follow.
If my light isn't working, what are the possible issues?
I plugged the wire into a row different from the LED.
I didn't push the leads of the wires, Resistor, or LED hard enough to touch the Breadboard rails.
All of these answers
The cathode and anode of the LED might be flipped.

Any of the issues listed here could stop the current from flowing in that complete circuit you see above!
Click NEXT.

Cool, you got the red light for stop, but I'm more excited about green for go! Oh, and that slow-down light, too. Can you build those?
Expand the image below to see how to connect the rest of your wires, LEDs, and Resistors.
The yellow LED should be connected to GP14, and the green LED should be connected to GP13. Remember that LEDs only work when connected in the right direction.

When you have finished building your circuits, click NEXT.
Where can we find the anode of the LED?
The short lead of the LED
The long lead of the LED
The rail of the Breadboard where the LED leads are connected
The body of the LED that lights up

The long lead of the LED is the anode. Anodes are where currents flow in, and cathodes are where currents flow out. That's why the long end of the LED is plugged into the side closer to the pin and the short end closer to GROUND.

Now, what do I want each of these LEDs to do? The RED light should turn on, stay on for a while, and then turn off, right?
Let's drag the following blocks from the Chip menu and connect them. Now, make sure turn pin 13 is ON, mess with the values in the wait block, and then turn pin 13 OFF. Hit START to test it out!
Did it work? Click NEXT.

The green and yellow LEDs can be controlled in the same way as the red LED. Let's copy the code and change the pins based on the ones that are connected to the LEDs.
Piperbot, you don't have to drag out new code blocks to copy! Just right-click and hit duplicate.
After we have made copies of the blocks, change the pin numbers to light up the green and yellow LEDs:

GP13 = Green
GP14 = Yellow
GP15 = Red

Then, click NEXT.

Hmm, although with this code, my traffic light will stop after one red, yellow, and green cycle. I want it to repeat!
To make the code repeat, use a repeat block.

Drag the first turn pin block away from the start block.

Drag out a repeat while true block from the Loops menu and connect it below the start block.

Drag the blocks we disconnected before to the inside of the repeat while true block.
Click NEXT.

Double-check the variables to make sure the pins are correct. Be sure each light turns on, waits, and then turns off before the next light does the same.
What order do lights turn on and off in a traffic light? If I start on green, do I go straight to red?
No silly! You've got to give the spaceships time to slow down and stop. It goes green to yellow to red and then back to green.
Does the code reflect that? If yes, click START to run the code.

Use the DIGITAL VIEW to see if the code is sending current to the correct GPIO pins.

When everything is working, click NEXT.

Hmm, traffic lights don't always stay on red, yellow, and green for the same amount of time, do they?
Oh, good point, Pip! The red light is usually the longest, then it's green to let cars pass, and then the yellow light is super short as a warning to slow down before the red stop light!
Now that we have our LEDs and a basic program in place let's make it work the way we want by adjusting the wait times as follows:

Green = 5 seconds
Yellow = 3 seconds
Red = 8 seconds
When you finish adjusting the wait times, click NEXT.

Cool feature alert! While you're building with blocks, Piper Make is generating code in a programming language called Python!
You can see the code you're dragging and dropping written as Python code by clicking the PYTHON tab at the bottom of the screen.

Go ahead, drag out some blocks, and see what the text-based code looks like.
You can delete blocks by dragging them to the trash can in the lower-right corner of the workspace, or you can click them once and press your backspace or delete key.
When you are done exploring the PYTHON tab, click NEXT.

If we were in your spaceship, we would stop at the red LED, go when it turned green, and (maybe at the next light) slow down when we see yellow before it switches to red so we can stop again.
Click the EXPLORE tab at the bottom of the screen to see if your code will help Pip and Piperbot fix the traffic jam on Mars!

Then, click START to run your code.

The pattern will loop until we press the STOP button because it forms an infinite loop. It's based on the traffic light pattern used in real-world traffic control systems but sped up.
Giving spaceships just five seconds to pass through would only let a few pass through on the green light!

Troubleshooting

If the LEDs are not working, use the DIGITAL VIEW to troubleshoot the code. You should see the GPIO pins light up as your code calls to them. If the code is working but the LEDs are not lighting up, check the wiring of the hardware by going back to the first steps.

Once everything is working, click NEXT.

Hold on! I need a button to cross traffic and see my buddies on the other side of Mars!
At many intersections, we might see a button on the traffic light pole that people can push to let the system know they want to cross the street.

To create this crossing, we need to add a Push-button to our circuit and code!
Did you know that at night, some traffic lights are always set at a green light until a pedestrian hits the crosswalk light?
Click NEXT.

Man, Pip's really pestering me for that Button! Let's add a Push-button to our circuit like the one Commander used to make me move in Getting Started!
Make sure the input is wired to GP12 and there is a connection to the ground to complete the circuit.
What is the purpose of the side rail that the Resistors and the black wires are plugged into?
That rail is plugged into the GND pin of the Pico, so the other black wire grounds the circuit with the Button and the Resistors ground the LED circuits.
There is no point of that side rail; we just wanted to make things more complicated.
That rail is plugged into the power which lets LEDs light up and provides power to the Button.
That rail is plugged into a GND pin of the Pico, providing power for the lights and the Button.

The point of the side rail is to have an easy way to access POWER or GROUND anywhere along the Breadboard. The GROUND rail is typically closer to the black/blue bar, and the POWER rail is closer to the RED, but it depends on where you plug in your wires. Since all circuits have to go from POWER to GROUND to be considered complete, we have our Resistors and our Button's wiring plugged into that side rail to GROUND them.
Once you have your parts, click NEXT.

Okay, okay, let's get to it! So, step one, how do we know when the Button is pressed?
Hmm, well, we want our code to wait for you to hit the Button, right? But the only way I know how to use the wait block is to wait for a certain amount of time.
There is another block that waits for something to be true or false. It's called the wait until block from the Chip menu. Find that block and connect it under the turn pin 13 ON block:
In coding, when something has a value of true or false, it is referred to as a boolean variable.
Maybe I can get a boolean of whether the Button is pressed by using that "is pin" block!
We can check a Button using the is pin block from the Chip menu. Our Button is connected to GP12, so drag out an is pin block and place it in the wait until block. Change the "pin" variable to 12.

Finally, change the time in the wait block under the wait until block to 1 second:
Click NEXT.

Let's try it! Hit CONNECT and then START.
If it's working correctly, when you press the Button, the green LED will stay on for 1 more second, then the yellow LED will come on, and then the red LED.
That doesn't seem like enough time for pedestrians to cross our Mars multilane highway.
Adjust the wait time for the red LED block to experiment and find the perfect time to be sure the pedestrian crosses the street safely!
Try experimenting with different wait times or moving the wait until block to different places in your code.

When you are finished, click NEXT.

Congratulations! You created a prototype that simulates how traffic lights work late at night!
Challenge: Can you build a crosswalk signal?

In the United States, a crosswalk signal is usually a walking person for a bit of time, then a flashing red hand, and finally a solid red hand. Using the red and green to represent the hand and walking person symbols, can you modify your circuit and code to build this crosswalk signal?

Click NEXT.
Do you remember what a Boolean is?
Someone who is startled easily
A numerical value
A True or False value
A pack of Resistors

In computing, a boolean variable is one with a TRUE or FALSE value.

Do you have this part in your kit?
If you do, click the button below for an additional Traffic Light Challenge!
Otherwise, click EXIT to return to the menu and start your next coding challenge.


CHALLENGE MISSION TUTORIAL STEPS Traffic Light PCBA

I'm glad we got that working! Spaceship traffic was really starting to get backed up!
This circuit is cool! But Mars can have some nasty wind storms. Do you think these wires will stay connected in a storm?
On Earth, we use Breadboards to help us design new circuits, but these are usually temporary. Eventually, when we finish one circuit, we take our Breadboard back apart to build a new one.
But if we disconnect the traffic light we just made, traffic will get messed up again!
I have a fix for that!
Click NEXT.

My ship has a Fabricator. The Fabricator is like a mini-factory that can make PCBAs from a circuit design.
What's a PCBA?
PCBA stands for Printed Circuit Board Assembly. The Fabricator on my ship can make a more permanent circuit by printing it out of copper metal on something sturdy like a fiberglass board. Then it assembles and solders all of the electronic components onto it!
Can your Fabricator make us a traffic light circuit that we can safely leave here?
It sure can! Let's make one now!
Click NEXT.

This is so cool!
Okay, I programmed our traffic light circuit into the Fabricator, so all we need to do is push the button below to fabricate a Traffic Light PCBA.
Click this button:
Now that you've fabricated a Traffic Light PCBA let's grab everything we need to hook it up:
Umm... this doesn't look like our circuit.
Click NEXT.

You're right, Pip. This doesn't look the same as our Breadboard, but it's the same circuit. If you look closely, you can see that the PCBA has 3 LEDs, 3 Resistors, and 1 Pushbutton, just like our Breadboard circuit.
How do we make it work?
We just need to connect it using a few jumper wires...
Connect your Traffic Light PCBA using the diagram below:
That was easy!
You can use the small wood piece and 2 short screws in your Base Station kit to attach the Traffic Light PCBA to the Base Station like this:
Once your circuit is built, click NEXT.

You should already have working code for a Traffic Light circuit. Click the button below to import the code you built from your Traffic Light project:
Click CONNECT and START to run your code.
That's so cool! Piperbot, you have some really neat technology!
Thanks!
When you're finished, click STOP, then click NEXT.

So now we can use our Breadboard for another project, and the ships won't get stuck in bad traffic.
I'm sure this won't be the last time we use our Fabricator!
When you're done, click EXIT to return to the menu and start your next coding challenge.
If you want to challenge your circuit and coding skills, try making a dual stoplight. Use your Breadboard and LEDs as the lights for one direction and the Traffic Light PCBA as the lights for the other direction.
When you're finished, click EXIT to return to the menu and start your next coding challenge!

Blueprint

OPEN IN BLUEPRINT VIEWER  DOWNLOAD

Have an different version? Look for more information on the Support Page.

Troubleshooting Tips

  • Is the LED failing to light up when you hit START?
    • The most common issue is that the LEDs may be plugged in incorrectly. Be sure the anode and cathode (i.e., short and long sides of LEDs) are oriented correctly, according to the tutorial.
    • Ensure that you’ve plugged the wires into the right GPIO. Look at the Digital View to see which pin you’re affecting.

Our customer support specialists are on hand to ensure your implementation of Piper runs seamlessly.
View Support Docs or Contact Support
EXPANDED RESOURCES

Term Glossary


Ground Pin A ground pin is a connection point in an electronic circuit that provides a common return path for electrical current. It helps complete the circuit by allowing excess electricity to flow safely away, which helps prevent damage to the circuit and keep everything working correctly.

Loop A part of a computer program that repeats a chunk of code a specified number of times or while a condition is true.

Boolean A type of data or expression with two possible values: true and false.

View Full Glossary

Material Library

Button
Mini buttons are types of momentary switches that only remain in their state as long as they're being actuated (pressed or held down). Pressing down on the button will close the circuit, letting the microcontroller know that current can pass through the circuit. When you let go of the button, the circuit opens back up letting the microcontroller know to stop allowing current to flow through the circuit. Most often momentary switches are best used for intermittent user-input cases like mode buttons for controllers because they are so easy to press or "click".
This button has two terminals which means it can only connect to a single input (connected by Jumper wire to a GPIO pin on a microcontroller) and a single output (connected by Jumper wire to a ground pin on a microcontroller). These work well as simple on/off circuits for one conducting loop.

Standards Alignment