Lift-Off with CodeX - Mission 5: Alert System!
Alert System
Students build an alarm system for the ship, reading raw data from a temperature sensor and a sound sensor, converting it into usable values, and triggering a light and a siren when a threshold is crossed.
Overview
Did you hear something? Being on another planet can get lonely sometimes. With no neighbors to check on the crew, they'll need a good alarm system. In this project students consider the technical dangers a crew can encounter on the ship, then build the system that watches for them.
It helps to have students think about how different types of sensors might be used to track the temperature or detect an explosion. Students read raw analog data from a temperature sensor and a sound sensor, convert that data into something meaningful, and use a threshold to decide when a reading is out of normal range.
🎯 Mission Goal: Students write code to simulate an alarm system for temperature and sound.
Learning Targets
- I can read data from a sensor and display it on the Console Panel.
- I can convert a raw analog temperature reading to Celsius.
- I can read an analog value from a sound sensor.
- I can calculate the average sound in the room.
Key Concepts
- Raw sensor data must often be converted into a different form before it can be used.
- Sensor behavior can be controlled by setting the analog period.
- A threshold can be used with sensor readings to determine when something is out of normal range.
- Real-world situations can be explored through simulations.
Assessment Opportunities
- Check for Understanding in CodeSpace (2)
- Mission 5 Assignment
- Display temperature readings on the Console Panel, then compare readings between different CodeX devices.
- Display sound sensor readings on the Console Panel, then compare readings between different CodeX devices.
- Exit ticket - explain the difference between how a temperature sensor and a sound sensor work
- Submit and/or check the AlertSystem program
- Journal entry on their learning experience
Success Criteria
- Read data from a sensor and display it on the Console Panel.
- Convert raw data from the temperature sensor to degrees Celsius.
- Use data from the sound sensor to calculate an average sound value.
- Control an alarm system with data from sensors.
Digital Resources
Classroom Materials
- ▸Laptop/computer with the Chrome browser
- ▸CodeX and connecting cable
- ▸Red LED
- ▸Potentiometer and divider
- ▸Temperature sensor
- ▸Sound sensor
- ▸Optional: something to cool and/or warm the temperature sensor
Real-World Applications
Extensions & Cross-Curricular
🔤
Vocabulary
▾
🐍
New Python Code
▾
📐
Standards
▾
CSTA Standards - Grades 6-8
CSTA Standards - Grades 9-10
CSTA Standards - Grades 11-12
- Students need a computer or laptop with the Chrome web browser.
- Make sure students can successfully log in to make.firialabs.com.
- Get supplies to make the temperature sensor read a lower value and a higher value, like ice cubes or a frozen water bottle, and a heat source.
- Build the AlertSystem program yourself once before class so you know what threshold values look like on your own hardware.
- Depending on the temperature of a student's hand, the sensor might not increase very much. After testing with students you may need to adjust to the proper threshold, or use something to cool down the temperature sensor before squeezing it between fingers.
-
Global variables are used inside a function, so the
globaldeclaration is needed. If students have completed Python with CodeX, this will be review. Otherwise you may need to go over the concept of updating a global variable inside a function. - The complexity of this project might be challenging for students, so schedule several checkpoints as students are working. Some functions have very similar names, which can make errors hard to find. Students are also asked to convert raw analog data from a sensor into degrees Celsius.
- The exponential moving average calculation is introduced here, and it leans heavily on statistics. If it makes sense for your students, show a graph of an exponential function and talk about how the relationship between two quantities is not linear. You could also discuss moving averages in fast-moving stock markets to give the statistics some context. This is a great time to collaborate with a math teacher.
- Extensions and cross-curricular projects are included to enhance the concepts in the mission. Use the extensions to extend students' programming experience. A remix is not explicitly planned here, but you can add one as an option for additional learning. A remix is planned after Mission 6.
Lesson Outline
Students access prior knowledge by answering the pre-mission questions in the assignment doc.
- Ask: "What could go wrong on a spacecraft that nobody would notice right away? How would the crew find out in time?"
- Ask: "What alarms go off in your house or your car, and what is each one actually measuring?"
Front-load the two ideas that make this mission hard, raw data conversion and thresholds, before students start typing.
-
Show a raw temperature reading on the Console Panel with
print(), and ask what that number means. It means nothing until it is converted. -
Walk through
degrees_c = raw_temp*0.004577 - 50and connect it to the volts-to-Celsius relationship. - Define a threshold as the line between "normal" and "sound the alarm," and point out that the right value depends on the room and the hardware.
-
Preview the blinking alarm LED with
exp.pwm_out(exp.PORT0, frequency=2)and the duty cycle constants. - Review updating a global variable from inside a function, since the alarm limits are updated that way.
Students work through the mission objectives in CodeSpace, taking notes and answering questions in their assignment doc as they go. Build in checkpoints, this program has a lot of moving parts.
- Connect the temperature sensor and read raw values onto the Console Panel.
- Convert the raw reading to degrees Celsius and display it, then compare readings with a neighbor's CodeX.
- Add the red LED on PWM as the alarm light, using the duty cycle constants to turn it on and off.
- Set a temperature threshold and trigger the alarm when the reading goes over it. Test with ice or a warm hand.
-
Connect the sound sensor, read analog values, and calculate a running average with
avg_sound = avg*(1-WEIGHT) + new_val*WEIGHT. -
Add the siren with
soundmaker.get_tone(), then useglide()andstop()to run the alarm without blocking the rest of the program. - Finish the complete AlertSystem program and complete both Checks for Understanding.
Bring the class back together to connect the sensor work to the bigger idea of simulation.
- Ask: "Why does a raw sensor reading need to be converted before we can use it?"
- Ask: "How did you pick your threshold, and what happens if it is set too high or too low?"
- Ask: "Why average the sound readings instead of reacting to a single value?"
- Ask: "What is the difference between how a temperature sensor and a sound sensor work?"
Students answer the reflection question in the assignment doc, add a journal entry about their learning experience, and submit the AlertSystem program.
Use the Mission 5 Review Questions or the Mission 5 Review Kahoot! through whichever method you prefer, class discussion, Kahoot!, or an LMS quiz.