Lift-Off with CodeX - Mission 6: Life Support

Mission 6 Lesson Plan

Life Support

Astronauts need air too. Students wire up a 360 continuous servo and a switch, then write code that spins the fan clockwise and counter-clockwise to keep air circulating through the spacecraft.

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

Overview

Astronauts need air too! Being on another planet can get lonely sometimes, and it doesn't matter how safe the crew is if they can't breathe. Ensuring consistent air quality is key to the success of this mission. Students use a 360 continuous servo to make sure air circulates throughout the spacecraft.

This project is a great opportunity to connect life science with computer science. Students can discuss the impact of poor air quality on human health while they build the system that fixes it. Along the way they meet exp.pwm_out(), integer division, and nested if statements that move the program from one state to the next.

🎯 Mission Goal: Students write code to simulate air circulation.

🎯

Learning Targets

  • I can set the analog period on the 360 servo.
  • I can make the servo spin clockwise and counter-clockwise.
  • I can start and stop the servo using a switch.
💡

Key Concepts

  • The duty cycle determines the speed and direction of the 360 servo.
  • A program can use "states", or phases, to determine what happens next.
  • Nested if statements let the program transition from one state to the next.

Assessment Opportunities

  • Check for Understanding in CodeSpace
  • Mission 6 Assignment
  • Make a chart of percent, speed, and direction of the servo, based on observation using code
  • Exit ticket - draw a diagram of the finite-state machine for this mission
  • Submit and/or check the LifeSupport program
  • Journal entry on their learning experience
☑️

Success Criteria

  • Connect a servo with a servo horn to the CodeX.
  • Use a function call to control the servo's speed and direction.
  • Control the servo with a switch.
🧰

Classroom Materials

  • Laptop/computer with the Chrome browser
  • CodeX and connecting cable
  • 360 continuous servo and one servo horn
  • Switch peripheral
360 degree continuous micro servo with a three-wire cable, used as the life support fan Switch peripheral board for the CodeX with a blue push button and the G, V, S labels
🌍

Real-World Applications

🚙Servos drive the motors on rover wheels used for terrain exploration.
🏥Life support fans in a hospital keep air moving where patients need it most.
🔧Hydraulic pump operation depends on precise motor control.
✈️Cabin pressure on an airplane is regulated by servo-controlled systems.
💬Have students discuss where and how servos might show up in their own lives.
🚀

Extensions & Cross-Curricular

ChallengeGive the fan multiple speeds and cycle through them, like a ceiling fan.
ChallengeAdd a temperature sensor and speed the fan up when it gets warm, or use the motion detector to turn the fan on.
ChallengeUse the potentiometer for variable speed and direction, the computer's clock for a run timer, or the NeoPixels and display screen to show system status.
AdvancedUse the accelerometer to simulate the effects of movement on air circulation. Tilt the CodeX to represent a change in the spaceship's orientation, which affects airflow and requires an adjustment.
Lang ArtsStudents read a technical report on servos, then summarize it in a paragraph or share it verbally with a partner.
ScienceHow much air does a person or animal need? Teach a lesson on oxygen levels and survival. How much power does the fan need, and how does the ship supply it? Teach a lesson on energy and conservation.
MathStudents experiment with different percent values and chart the speed and direction for each data point. For advanced math, plot the points and write the equation for the servo.
🔤

Vocabulary

Servo - A DC motor with a controller circuit, an internal feedback mechanism, and a gearbox. The 360 continuous servo turns in both directions at different speeds. The 180 positional servo turns to a specific angle and holds that position.
Finite-State Machine - The status of a system, with transitions between statuses. Your program can only be in one of a known set of states at any given time. Usually the state is based on variables in your code.
State - A phase of a program. Keeping track of states helps you understand and manage your code, and each state might have its own set of conditions it is tracking.
Transition - Moving between states. The program transitions from one state to another when certain conditions are met.
🐍

New Python Code

exp.pwm_out(exp.PORT0, frequency=20)Sets up a 360 servo using PWM with a frequency of 20.
//Integer division. It returns only the whole number, with no decimal and no rounding. Example: CYCLE * percent//100
nested ifThe first if statement is checked. If it is True, the second if statement is checked. If it is False, the whole block is skipped. Nested ifs are also how the program transitions to a different state.
📐

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-17 2-AP-19

CSTA Standards - Grades 9-10

3A-CS-01 3A-CS-03 3A-DA-11 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-21 3B-AP-22 3B-AP-23
📝
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.
  • Pull one servo horn per servo and set the extra horns and screws aside before you hand out the peripherals.
  • Connect a servo and run it yourself once so you can demonstrate the clockwise and counter-clockwise spin.

🧑‍🏫
Teacher Notes
  • The wires on the servo are slightly different colors than the other peripherals. Brown corresponds to black, and orange corresponds to yellow.
  • Students only need one of the plastic pieces (horns) included with the servo. You may want to remove the others, along with the screws, before distributing the peripherals.
  • Integer division // is used in this mission. Some practice problems are included in the assignment, and you can cover the operation in more detail if your students need it.
  • You may need to discuss duty cycles to help students understand the servo's analog control signals. A duty cycles table works well as a guide, and you can read more about servos and duty cycles at PCB Cadence.
  • The goal validator can be particular on some objectives. Python does not distinguish between single and double quotes, but the verifier sometimes will. If a student's code is having trouble verifying on Objective 4, check the quotes first.
  • Extensions and cross-curricular projects are included to enhance the concepts in the mission. A remix is not explicitly planned here, but you can add one as an option for extra learning. A remix and assessment follows Mission 6.
🗺️

Lesson Outline

🗣️Warm-up / Hook

Students access prior knowledge by answering the pre-mission questions in the assignment doc.

  • Ask: "A spacecraft is sealed shut. Where does the air come from, and what happens to it if nothing moves it around?"
  • Ask: "Name something in your house with a motor that has to run at different speeds. How does it know which speed to use?"
Teaching tip: Tie this straight to health. Poor air quality is something students have felt, in a stuffy classroom or on a bad air quality day, so the mission problem is not abstract.
📖Introduce the Mission

Front-load the hardware and the two new ideas before students start typing.

  • Show the 360 continuous servo and a servo horn, and point out that brown is ground and orange is signal on this peripheral.
  • Introduce exp.pwm_out(exp.PORT0, frequency=20) and explain that the duty cycle sets both speed and direction.
  • Walk through integer division // with two or three quick examples on the board.
  • Sketch a simple finite-state machine on the board: off, spinning one way, spinning the other. Name the transitions out loud.
Teaching tip: Run the servo at a few different percent values in front of the class before students code. Seeing the direction flip at the midpoint makes the duty cycle idea click faster than any explanation.
💻Coding Time

Students work through the mission objectives in CodeSpace, taking notes and answering questions in their assignment doc as they go.

  1. Attach a horn to the servo and connect the servo to the CodeX, checking the wire colors.
  2. Build LifeSupport, setting up the servo with exp.pwm_out(exp.PORT0, frequency=20).
  3. Write a function that takes a percent and sets the duty cycle, then test values that spin the fan clockwise and counter-clockwise.
  4. Add the switch and use nested if statements to start, stop, and reverse the fan as the program moves between states.
  5. Complete the Check for Understanding in CodeSpace.
Teaching tip: If a servo will not move, check the wire colors before the code. Brown to black and orange to yellow trips up more students than the duty cycle math does.
Teaching tip: Fast finishers can start the multi-speed ceiling fan challenge or add the temperature sensor.
🧑‍🤝‍🧑Class Debrief

Bring the class back together to lock in states and transitions.

  • Ask: "What percent values made the fan spin clockwise, and what values reversed it? Where was the stopping point?"
  • Ask: "What states does your program have, and what has to happen for it to move from one to the next?"
  • Ask: "Why do we need nested if statements here instead of one long list of separate ifs?"
Teaching tip: Use the exit ticket here. Having students draw the finite-state machine tells you in one glance who understands the structure and who was just copying code.
✏️Wrap-up & Review

Students answer the reflection question in the assignment doc, add a journal entry about their learning experience, and submit.

Use the Mission 6 Review Questions or the Mission 6 Review Kahoot! through whichever method you prefer, class discussion, Kahoot!, or an LMS quiz.

Teaching tip: The percent, speed, and direction chart doubles as a math artifact. Keep the class data and use it when you plot the servo equation later.