PIPER MAKE

EDUCATOR GUIDES


YOU ARE HERE

Sensors expedition

Mission 1 of 6

Sensors expedition: Mission 1 of 6

Security Zone


Beginner

1 hour

Grades 3 - 8

MISSION OBJECTIVE

Learn how to set off an alarm when an object breaches a set perimet

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.com
MISSION CHARACTERS

Piperbot

Pip
MISSION MATERIALS

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

MISSION RESOURCES

Learning Goals

  1. Students will build a “security zone” around their Distance Sensor and sound an alarm when a Zomar breaches the zone.
  2. Students will learn to use if/then statements in code to create conditional statements.
  3. Students will understand how the Distance Sensor measures distance using sound waves reflected off objects.

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 Zone

You're going to need an Ultrasonic Range Finder for this project—which you might have on hand if you're one of our earliest Monthly Makers Club members OR if you have an Extended Starter Pack. If not, don't worry -- head over to playpiper.com and search for the Sensor Explorer to get three snazzy sensors.

If 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!

You'll need to snag your ultrasonic range finder and the diode jumper cables for this tutorial.
Click NEXT.

Let's start by connecting up our Ultrasonic Range Finder to your Raspberry Pi Pico.

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
You will leave NC disconnected. Follow this guide and use the wiring diagram below:

So let's go back to pretending we're a bionic dolphin and use our echolocation to detect where objects are in space around us!

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.

Cool, so we know to print something but what do we want to be printed? Let's tell the program to print the input from the Ultrasonic Range Finder!

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.
Click NEXT.

Go ahead and test the program by clicking CONNECT and then clicking START.

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.

Now that we have a sensor that measures how close objects are, let's use it to create a Security Zone!

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:
Click NEXT.

Let's think about what we want the code to do! Basically, if there is an object within a certain range, we want the program to do something (set off an alarm) or we want it to stay silent, right? And we don't want that test to just happen once right, we want to test repeatedly?

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:
Click NEXT.

Okay cool, so we've set up the test, but what do we want to happen if the answer to the question "is there something within 50 cm of the sensor?" is TRUE?

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:
Ready to try it? Click NEXT.

Okay drumroll please... Let's click that START button to test your alarm.

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.

Let's try using the DATA tab to visualize the output from the sensor.

Replace the print block in your program with a graph number block from the Actions menu:
Click on the DATA tab at the bottom of the workspace to open it, and click START to run your program again.

What is the graph showing you?

Click STOP and then click NEXT when you've figured it out!

Maybe you want your Security Zone to be a little narrower or a little wider. Let's adjust the Ultrasonic Range Finder distance based on your preference!

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.

Whew, setting up security systems is hard work! But hey, that's not the only place sensor like these are used—in fact, self-driving cars actually use sensors like these to make sure they're not running into things while on the road!

Can you think of any other places where you might use a range finder like this?
Click NEXT.

Congratulations, you built your own Security Zone! Click EXIT to go back to the start screen and try out more projects and tutorials!

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


Engineer Someone who designs, builds, or fixes things to solve problems.

Sensor A device that produces an output signal to sense a physical phenomenon.

Conditional Statement A coding instruction used to compare values and express and make decisions, like an if-then statement.

List A sequence of several values grouped under a single name in code. A group of items or components. A tool used to store multiple pieces of information at once.

View Full Glossary

Standards Alignment


Individual Standards
  • CA 3-5.CS.1 Describe how computing devices connect to other components to form a system. (P7.2)
  • 3-5.AP.18 Perform different roles when collaborating with peers during the design, implementation, and review stages of program development.