Lift-Off with CodeX - Mission 5: Alert System!

Mission 5 Lesson Plan

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.

⏱ 60-90 min 🎯 Grades 4-12+ 💻 CodeSpace 📱 CodeX 🔌 Peripherals Kit 🐍 Python
View Lesson Outline
📋

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.
🧰

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
Red LED peripheral board for the CodeX, showing the latching cable connector and the G, V, S labels Potentiometer peripheral board for the CodeX with a knob and the G, V, S labels Temperature sensor peripheral board for the CodeX with the G, V, S labels Sound sensor peripheral board for the CodeX with a round microphone element Green divider board labeled CodeX and Sensor with numbered ports 1 and 2, used to split one CodeX port between two peripherals
🌍

Real-World Applications

🏠Home surveillance detectors and alarm systems watch for motion, smoke, and sound, then decide when to sound an alert.
🥶Refrigeration and cooling in the food industry depends on temperature sensors and thresholds to keep food safe.
🚗Sensors in cars detect problems and warn the driver, like a low tire indicator or an overheating engine.
💬Have students discuss how sensors are used in their own lives to help people.
🚀

Extensions & Cross-Curricular

ChallengeChange the raw temperature to Fahrenheit.
ChallengeUse the buttons on the CodeX to switch between Celsius and Fahrenheit temperatures.
ChallengeFind images that go with the different alerts and display them on the CodeX screen when the alarm is triggered.
ChallengeLike a traffic light, add a "warning" period before the alarm is triggered, alerting the crew to a potential danger before the actual threshold is reached.
ChallengeCheck the sound reading two different ways. Below the threshold could mean a power failure with no electronics working, and above the threshold could mean an explosion. Give a different warning for each situation.
Lang ArtsStudents write a poem about a topic from the lesson, or about their coding experience.
ScienceExplore sound waves and how sound behaves in space.
MathChart the sensor readings, practice converting between Fahrenheit and Celsius, graph sample data to write the volts-to-Celsius equation, and compare the exponential moving average with other weighted averages.
ArtStudents draw or use mixed media to show the interior of their own spacecraft. Discuss the use of color and perspective in their artwork.
🔤

Vocabulary

Duty Cycle - The percentage of time power is ON during pulse-width modulation.
Frequency - The analog period, or how rapidly the device pulses during pulse-width modulation.
REPL - "Read, evaluate, print loop" command line that enables print statement output.
Simulation - Code that builds a model of something, and lets you play with that model to explore "virtual" situations.
Threshold - A specific limit or point that must be met or exceeded in order for something to occur.
🐍

New Python Code

LED_ON = 2**16 // 2Maximum duty cycle for an LED using PWM.
LED_OFF = 0Minimum duty cycle for an LED using PWM.
exp.pwm_out(exp.PORT0, frequency=2)Sets up an LED using PWM for a blinking light.
degrees_c = raw_temp*0.004577 - 50Conversion of a raw temperature reading to degrees Celsius.
avg_sound = avg*(1-WEIGHT) + new_val*WEIGHTAverage sound calculation using an exponential moving average.
import soundlibImports the sound library to add non-blocking sound functions.
siren = soundmaker.get_tone("violin")Sets up a variable for the sound.
siren.set_pitch()Sets the pitch tone at the given frequency.
siren.play()Plays the sound at the set pitch.
siren.glide()A non-blocking way to ramp the pitch from the current setting to a new setting over a specified amount of time.
siren.stop()Stops playing the tone.
global temp_limitAllows for updating a global variable while it is being used in a function.
print("Temp:", degrees_c)The print() function displays text on the Console Panel.
📐

Standards

CSTA Standards - Grades 6-8

2-CS-02 2-CS-03 2-DA-07 2-DA-08 2-AP-10 2-AP-11 2-AP-12 2-AP-13 2-AP-14 2-AP-19

CSTA Standards - Grades 9-10

3A-CS-02 3A-CS-03 3A-DA-09 3A-DA-12 3A-AP-13 3A-AP-15 3A-AP-16 3A-AP-17 3A-AP-18 3A-IC-26

CSTA Standards - Grades 11-12

3B-CS-02 3B-DA-05 3B-DA-06 3B-DA-07 3B-AP-10 3B-AP-14 3B-AP-15 3B-AP-16 3B-AP-17
📝
Preparing for the Lesson
  • 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.

🧑‍🏫
Teacher Notes
  • 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 global declaration 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

🗣️Warm-up / Hook

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?"
Teaching tip: Make a quick class list of shipboard dangers, then sort them into "a sensor could catch this" and "a sensor could not." It sets up why thresholds matter before any code is written.
📖Introduce the Mission

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 - 50 and 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.
Teaching tip: Have every student read their raw temperature out loud before converting. The spread across the room is the whole argument for calibrating thresholds instead of hard-coding one number.
💻Coding Time

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.

  1. Connect the temperature sensor and read raw values onto the Console Panel.
  2. Convert the raw reading to degrees Celsius and display it, then compare readings with a neighbor's CodeX.
  3. Add the red LED on PWM as the alarm light, using the duty cycle constants to turn it on and off.
  4. Set a temperature threshold and trigger the alarm when the reading goes over it. Test with ice or a warm hand.
  5. Connect the sound sensor, read analog values, and calculate a running average with avg_sound = avg*(1-WEIGHT) + new_val*WEIGHT.
  6. Add the siren with soundmaker.get_tone(), then use glide() and stop() to run the alarm without blocking the rest of the program.
  7. Finish the complete AlertSystem program and complete both Checks for Understanding.
Teaching tip: Several function names in this mission look almost identical. When a student is stuck, have them read their function names out loud before you look at the logic. It catches most of the bugs.
Teaching tip: A quiet classroom makes the sound alarm easy to test. A loud one makes it impossible. Plan a "silence, then everybody clap" moment so every student gets a clean before-and-after reading.
🧑‍🤝‍🧑Class Debrief

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?"
Teaching tip: Use the temperature-vs-sound question as the exit ticket. It tells you fast who understood the sensors and who just copied the code.
✏️Wrap-up & Review

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.

Teaching tip: Fast finishers should take a challenge, the Fahrenheit conversion and the "warning before alarm" traffic light version are the two that reinforce this mission best.