MISSION OBJECTIVE
Learn how to set off an alarm when an object breaches a set perimeter.
In this mission, you will help Piperbot and Pip detect when an object breaches a set perimeter using the Distance Sensor and sound an alarm. Ask students: “What do you think home security systems use as the sensor? What about smart doorbells?”
View student interface at make.playpiper.comMISSION CHARACTERS
MISSION MATERIALS
Computer with USB port and Chrome or Edge browser
Piper Make Base Station
MISSION RESOURCES
Learning Goals
- Students will build a “security zone” around their Distance Sensor and sound an alarm when a Zomar breaches the zone.
- Students will learn to use if/then statements in code to create conditional statements.
- Students will understand how the Distance Sensor measures distance using sound waves reflected off objects.
- Understand how sensors detect changes
- Code an alarm that is triggered when inputs reach a threshold
Learning Activities
ELA Extension: Security Zone Story
- Pair students up or allow them to work independently based on writing level and preference. Students will write a narrative or procedural account of an event where their robot’s security system was triggered, using descriptive language and cause-and-effect structure.
- Students begin by setting the scene. Ask: Where is the security system located? Options might include: Mars Base 4, the school science lab, or a secret alien bunker.
- Next, students describe the moment the sensor detected something:
- What triggered the alert?
- Who or what entered the zone?
- Was the alert caused by movement, sound, or light?
- Students then describe how the system (or characters) responded:
- Was it a false alarm?
- Was there a real threat?
- Was it something unexpected or silly?
- Students will write using a narrative voice, past tense, and sequencing words like first, then, suddenly, finally. Encourage inclusion of dialogue, sound effects, and emotional reactions to bring the scene to life.
Bonus vocabulary words to include: sensor, input, trigger, detection, condition, alert, zone
EXTENSION: Students turn their stories into short graphic panels or comic strips showing the moment of detection, the alarm being triggered, and the characters’ reactions.
ELD Extension: Motion Detection Roleplay
- Pair students so that each English Learner (EL) is working with a fluent or higher-level EL. Students will practice speaking, listening, and cause-effect sentence structures through visual supports and interactive storytelling related to motion detection.
- Begin with Visual Vocabulary instruction using picture cards, gestures, or real objects to introduce key terms: sensor, zone, alarm, detect, move, stop, alert
- In Partner Roleplay, one student acts as the “security bot” while the other moves through the sensor zone (e.g., crossing a line, waving an arm). The “bot” reacts with a sound, gesture, or phrase.
- Students describe the interaction using sentence frames such as:
- "The bot detected me when I ___."
- "The alarm went off because ___."
- After switching roles, students retell and report what happened by drawing a picture and writing or saying a cause-effect sentence.
Examples: - “When I walked into the zone, the light blinked.”
- “The robot made a sound because I moved too fast.”
Math Extension: Sensor Range & Thresholds
- Pair students together or allow them to choose their partners. Partner A will operate the sensor system while Partner B tests how close an object can get before triggering the alert. Then, they will switch roles.
- Connect back to the Security Zone activity and ask students to estimate: “At what distance will the sensor detect an object?” Record student predictions on the board before testing.
- Start students off with objects like a hand, pencil, or eraser. Measure the distance at which the alert goes off using a ruler or tape measure. Students record the distances in centimeters or inches.
- Have pairs switch roles and repeat the process with a new set of objects. Then, have them organize their results into a chart or simple bar graph.
- Ask students to describe their findings using math language:
- “The pencil triggered the alert at less than 5 cm.”
- “The eraser was detected at a greater distance than the toy.”
- Observe student reasoning and encourage them to explain:
- “What object triggered the alert first?”
- “Was the sensor consistent each time?”
- “How would changing the detection threshold affect results?”
- Finally, challenge students to write simple detection rules using logic terms like:
If distance < 6 cm, then alert.
If distance ≥ 6 cm, no alert.
Encourage them to decide which role they preferred—the one collecting the data or the one interpreting it.
Career Connections
Robotics Engineer: Salary $104,600/yr
Automotive Engineer: Salary $95,300/yr
Civil Engineer: Salary $88,050/yr
Electro-Mechanical and Mechtronics Technicians: Salary $60,570/yr
Hardware Diagram
Tutorial Steps
Security ZoneIf you've got your Ultrasonic Range Finder sensor, let's get started!
Let's pretend you're a dolphin for a second. Go ahead, make your best dolphin face, we'll wait. So the way dolphins orient themselves is through a process called echolocation, where they let out a series of clicks which reflect off of objects around them. Dolphins then sense the sound waves coming back and can figure out where objects are in space — which is exactly what our range finder does as well!
The colors of the wires on your 4-pin cable can vary, so it is important to match the pins on your sensor module to the correct connections on your Breadboard.
Remember, the DIGITAL VIEW is a handy way to see the GPIO pin locations. For this circuit, you will connect:
- GND to G (ground)
- SIG to GP22
- VCC to 5V
To do this, we're basically going to want to print out the distance measured by the sensor, right?
So let's grab a start block and drag it to your programming space. Then find the print block under Chip menu and drag it to the start block.
We want to read the sensor more than once, so start with a repeat forever block from the Loops menu and connect it to the start block.
Find the range finder block under Sensing menu and drag into the print block as shown. When you place the range finder block where the "_" block is, the "_" block will be displaced. That's fine, go ahead and put the "_" block in the trash can.
Now change the pin input to the GPIO pin that we connected the yellow wire to: GP22.
Check out the CONSOLE tab at the bottom of the workspace. Do you see the readings change as you move your hand in front of the sensor?
After you've experimented with the distance sensor, click STOP and then click NEXT.
Basically, if an object comes within the range of our Ultrasonic Range Finder, let's set off an alarm. So how do we do that? Well, we want to set up a conditional statement, with an alarm set off if an object is detected. We can do this using an if _ do block under the Logic menu. Go ahead and drag one of those into the repeat forever block. Use the one with the inequality already in it:
So let's set up the if statement to test if there is an object within a certain range. Duplicate the range finder block and drag the new one to the left side of the _ = _ block. Then set the inequality to ≤ (less than or equal to).
Drag a number value block from the Values menu to the left side of the _ = _ block. Change the value from 0 to 50.
Finally, change the wait time of the repeat forever block to 1 second:
Let's set off an alarm!
There are many different sounds you could play in your program if the condition is met. Do you want a loud alarm to wake you up? Or a funny sound to make you laugh?
Whichever it is, drag a play sounds block from the Sounds menu and place it in the do statement in the if block. Then, pick which sound you want the program to play! You can find lots of different sounds in the Sounds menu.
You may change the sounds at any time by changing the blocks in your program:
Position the sensor and move your hand towards and then away from the sensor. Check the CONSOLE. Do you see the measurements printing?
Check the PYTHON tab. Do you see any text that looks like what the blocks you dragged and dropped above?
If you don't hear any sounds - check your computer's volume. The sound blocks actually send a command back to your computer that tells it to play a sound!
Click NEXT.
Replace the print block in your program with a graph number block from the Actions menu:
What is the graph showing you?
Click STOP and then click NEXT when you've figured it out!
How close can someone come to your sensor without tripping the alarm? How would the alarm change if you used units of inches?
Try it, and when you're finished, click NEXT.
Can you think of any other places where you might use a range finder like this?
Blueprint
OPEN IN BLUEPRINT VIEWER DOWNLOAD
Have an different version? Look for more information on the Support Page.
Troubleshooting Tips
-
Is the Range Finder not measuring distance?
- Pay extra attention to the wiring diagram for this one.
- Verify all your electrical connections, including that your Pico is connected to your computer.
- It is common for the connections to be off by 1 or 2 holes. We recommend going through each build to ensure the connections are correct.
- Don’t worry! One of the wires (NC) does not need to be connected.
-
How does the Distance Sensor work?
- The Distance Sensor emits sound waves and measures the time it takes for them to bounce back. Measuring this determines the distance.
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
Circuit A conductive path for the flow of current or electricity.
Power The current or flow of electric charge and voltage.
Microcontroller An integrated circuit containing a microprocessor with memory and associated circuits.
Variables A value that can change depending on conditions or information passed to the program. A storage location with a symbolic name used to keep track of a value that can change while a program is running (similar concept to using X and Y in an algebraic equation). Variables are not only numbers; they can also hold text, including whole sentences (strings) or logical values (true or false).
Input Device A hardware device that sends data to a computer, allowing interaction and control.
Output Device A piece of hardware that converts information into a form humans can sense and understand.
Standards Alignment

