PIPER MAKE

EDUCATOR GUIDES


YOU ARE HERE

Sensors expedition

Mission 4 of 6

Sensors expedition: Mission 4 of 6

Ther-Mood-Stat


Intermediate

1 hour

Grades 3 - 8

MISSION OBJECTIVE

Learn how to reflect mood using temperature measurements.

Head back to Earth to help our scientists create a temperature-sensing suit! Ask students: “Where do you think detecting temperature is important? Other than emojis, what response could you code?”

View student interface at make.playpiper.com
MISSION MATERIALS

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

MISSION RESOURCES

Learning Goals

  1. Students will be able to connect and configure a temperature sensor to a microcontroller using a breadboard and appropriate wiring.
  2. Students will be able to create a function to measure temperature and return corresponding emojis based on temperature ranges.
  3. Students will be able to test and modify their temperature sensor program to display temperature readings and corresponding emojis and personalize the program by setting different temperature ranges and emojis.

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




Code Diagram




Tutorial Steps

Ther-Mood-Stat

In this tutorial, we will be using a temperature sensor to measure how hot or cold it is! You're going to need a Temperature sensor for this project. If you have one that looks similar to the picture below, great!

If you don't - then guess what? You can use the temperature sensor that's already inside of the Pico on your breadboard!
If you've got your Temperature sensor, click NEXT to get started!

Brrrrr! Have you ever been somewhere cold and the hairs on your arms stand up? But wait, doesn't the same thing happen when you're watching a scary movie and you get really scared?

Yep, it turns out that your skin has really tiny sensors kind of like the one in front of you—with little muscles to pull up your strands of hair when you're cold or scared! If you were really hairy, the extra fur length would make you warmer in the cold and make you look much bigger to whatever you were scared of!

We're going to code up your Temperature sensor to measure the temperature outside and use it to print how you feel inside!

That makes me feel pretty 🔥

Click NEXT.

Let's start by connecting up our Temperature sensor.

If you are using the temperature sensor inside of your Pico, you can skip this step (there is no circuit to build).

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)
  • SDA to GP20
  • SCL to GP21
  • VCC to 3V
Follow this guide and use the wiring diagram below.
Once you've connected your Temperature sensor, click NEXT.

Now that our Temperature sensor is wired up, let's think about what we want it to do. Since we want our code to measure the temperature and then return how we feel (in emoji form), we're going to write a Function. In computer science, this is basically a piece of code that does a specific task and can then output a value. Drag a do something return block from the Function menu out to our workspace. Since the thing we want this block to do is return an emoji, let's rename it from "do something" to "emoji"

Remember that functions do a task, and can send back a value, right? In our case, we want the function to read the Temperature sensor block and return an emoji depending on the temperature.

So if the sensor measures a nice comfortable room temperature between 70-73 degrees Fahrenheit (21-23 Celsius), we want to return a smiley face. How do we code that?

Let's start by dragging an if _ return block from the Function menu into our emoji function block:
Click NEXT.

Awesome, but let's think about what temperatures make us ☹ — it's not just when it's super hot right? Super cold is pretty bad too.

To be able to code for both of those cases, we want to have an OR Logic statement so we can test two things at once—like is it too hot OR is it too cold?

Drag the _ and _ block from the Logic menu to the if return block and change it from an and to an or:
Click NEXT.

But how do we tell the code which temperatures are in the right range? Let's tell the code to test whether a statement (like "the temperature is above 73 degrees") is TRUE or FALSE.

Find the _ = _ blocks in the Logic menu and place one before and one after the or Logic block as shown. Change the first = to a ≤ and change the second = to a >.

What do these symbols represent? Why are we using these inequalities in this case?

But wait, we have our Temperature sensor connected, shouldn't we use that measurement somewhere? Why yes, this is where we need to get the measurement from it to test it out!

We need to read the temperature and store it into a variable so we can use it in our function. In the Variables menu, click the Create variable button and name our new variable "the temp".

Then, drag out a set the temp to block and place it at the beginning of the emoji function. Finally, drag a Temperature sensor block from the Sensing menu into the set the temp to block:
If you are using the sensor inside your Pico, use the Chip Temperatureblock instead:
Click NEXT.

We're really close now, we just need to put the the temp blocks in the right places in the OR logic statement next to the inequalities. Find the the temp block in the Variables menu and drag one to the left of the first inequality and a second to the left of the second inequality:
Click NEXT.

Now let's set those numbers! What temperature do we want to test? Let's say that we're the happiest between 70-73 degrees Fahrenheit, we would want to test whether the temperature is below 70 or above 73, correct?

Under the Values menu, find the number value block with a 0. Add one number value block to the right side of each inequality.

Now, let's set our temperature range by changing the number values to 70 and 73 respectively.

If you are using the sensor in the Pico, you might have noticed that is not as accurate. That's because it's designed to measure the temperature of the Pico itself, not the temperature of the room. That's okay! It's still really good at measuring changes in the temperature, so you may have to adjust your numbers to make everything work.
When your values are set, click NEXT.

Let's assume you're super picky, and anything outside the range of 70-73 degrees makes you sad.

Drag an emoji block from the Values menu and add it to the return statement in the if return block.

Change the emoji block to the sad face, and our program will know to return that emoji if the temperature reading is above 73 degrees OR below 70 degrees, like we coded!
Click NEXT.

But hey, if it's not too cold and it's not too hot, it must be just right! So go ahead and drag another emoji block to the return slot of the emoji function and set it the happy face.

This will make the program return a sad face if the measured temperature is in the ranges we coded and a happy face if it's not!
Click NEXT.

Now the fun part, let's display our emoji to the world! To have your emoji show on the screen and keep it on the screen, you will need to run a program to shout the emoji (which just means to have it pop up on the screen).

The emoji that is being shouted needs to be the one we generated from the function.

First grab a start block and add a shout block in the Chip menu. We want to have the program constantly running so add a repeat forever block under Loops. Change the wait time to 2 seconds.

The shout block will show the returned emoji on your workspace. To show the emoji we generated, add the emoji block found under Function menu to the value of the shout block:
Click NEXT.

Looks like you're in the hot seat, let's try it out!!

Be careful! Don't try to measure things that are dangerously hot or cold, and don't put your sensor in anything liquid or wet!

Click START in the top left corner of the screen to start your code. Let's see what the room temperature is and see if it falls in the range of 70-73 degrees. How about when we rub our hands together and hold the sensor? Do the emojis pop up like you expected?

Curious about what temperature you're measuring? Drag a print block into your loop and tell the program to print the Temperature sensor measurement.

When you hit START, click on the CONSOLE tab you'll see the temperature reading as well!
When you're happy with your program, click STOP, then click NEXT.

But everyone's ther-mood-stat is a bit different right? Maybe you really love when it's colder but your friend is happier basking in the heat.

Well not to worry, this is your moment to personalize your ther-mood-stat! Go ahead and add more ranges by clicking on the if, return block you've already coded. Once highlighted, right click and select duplicate. Drag the duplicate blocks back into the to emoji function.

With each if return block, you can set different temperature ranges and emojis depending on what you like and don't like. Start your program again and measure items with different temperatures and see your emojis show up!!

It's a good practice to place the conditions that are less likely to happen first in your function. If you put them last, the function will exit before it gets to them.

Be careful though! Don't try to measure things that are dangerously hot or cold, and don't put your sensor in anything liquid or wet!
Click NEXT.

You now know how the air conditioning system in your home or school measures the temperature to "know" when to turn on or off. Can you think of other uses for a Temperature sensor that you might run into?

Click EXIT to go back to the start screen and try out other projects or tutorials!

Blueprint

OPEN IN BLUEPRINT VIEWER  DOWNLOAD

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

Troubleshooting Tips

  • Is the Temperature Sensor failing to detect temperature changes?
    • Ensure that you’ve plugged the wires into the right GPIO. Look at the Digital View to see which pin you’re affecting.
    • Use simple changes in temperature, such as the side of a cup of hot or ice water. DO NOT place the temperature sensor in liquid!
  • How does the Temperature Sensor detect temperature changes?
    • Temperature Sensors are composed of two metals that generate an electrical voltage or resistance when a temperature change occurs by measuring the voltage across the diode terminals.

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.