Lift-Off with CodeX - Mission 7: Solar Tracking!

Mission 7 Lesson Plan

Solar Tracking

Everybody loves sunshine. Students pair a 180 positional servo with a light sensor and write code that rotates the crew's solar panels to follow the path of the sun.

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

Overview

Everybody loves sunshine! Throughout the Lift-Off curriculum, students write code that helps the crew monitor and conserve different kinds of resources. This project is no different. The crew needs a way to generate energy from the sun, so students use a light sensor to decide when to rotate the solar panels and keep them pointed at the light.

Two new ideas carry the mission. The 180 positional servo turns to a specific angle and holds it, which means there is no "off" position, only a stopped one. And the program needs to remember where it is in the day, so students use a state variable to track morning, noon, and evening and move the panels accordingly.

🎯 Mission Goal: Students write code to simulate rotating solar panels to follow the sun.

🎯

Learning Targets

  • I can set the analog period on the 180 servo.
  • I can change the position of the 180 servo.
  • I can read data from the light sensor.
  • I can use states and a state variable to control the position of the 180 servo.
💡

Key Concepts

  • There is no "off" position for the 180 servo.
  • A variable representing the state allows the program to remember information about events.
  • The console panel can be used to monitor analog data.

Assessment Opportunities

  • Check for Understanding in CodeSpace (2)
  • Mission 7 Assignment
  • Make a chart of percent, angle, and direction of the servo, based on observation using code
  • Exit ticket - explain "bouncing" and how it affects digital input readings
  • Submit and/or check the SolarTracking 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 position.
  • Read and display data from the light sensor.
  • Use a variable for states to control the position of the 180 servo.
🧰

Classroom Materials

  • Laptop/computer with the Chrome browser
  • CodeX and connecting cable
  • 180 positional servo and one servo horn
  • Light sensor and divider
  • White LED
180 degree positional micro servo with a three-wire cable, used to rotate the solar panels Light sensor peripheral board for the CodeX with a photoresistor and the G, V, S labels LED peripheral board for the CodeX with the G, V, S labels Divider connector used to plug two peripherals into one CodeX port
🌍

Real-World Applications

☀️Solar fields and solar powered devices track the sun to pull in more energy.
🦾Robotic arms depend on positional servos to reach an exact spot and hold it.
📡Satellites and antennae aim themselves with positional motors.
🏭Assembly line equipment repeats the same precise motion thousands of times a day.
💬Have students discuss where and how positional servos might be used in their own lives.
🚀

Extensions & Cross-Curricular

ChallengeUse the LED with PWM and the potentiometer readings to change the light from dim to bright.
ChallengeUse a timer or a switch to turn the LED on and off.
ChallengeUse a servo to spin the LED around the light sensor, so the "sun" really moves.
ChallengeAdd a temperature sensor and rotate the panels when the temperature passes a threshold value, either too hot or too cold.
ChallengeUse the CodeX display screen to show additional information, or light up the CodeX pixels to indicate the position of the panels.
ChallengeUse the CodeX buttons to manually control the servo position.
Lang ArtsStudents write a summary of their project using the technical terms from the mission.
ScienceTeach a lesson on solar power. Then ask what a "day" even looks like in space, and teach a lesson about light beyond Earth.
MathTeach a lesson about percents, and a second one about angles. Both show up directly in the servo code.
🔤

Vocabulary

Photoresistor - A sensor that changes its resistance when light shines on it. A high intensity of light causes less resistance, and less light causes more resistance.
Bouncing - When an input peripheral registers multiple times instead of once, like a single button press that reads as three.
State - A phase of a program. Tracking the state lets the program remember what already happened, and each state can watch for its own set of conditions.
180 Positional Servo - A servo that rotates to a specific angle between 0 and 180 degrees and holds that position. Unlike the 360 continuous servo, it does not spin freely.
🐍

New Python Code

servo.duty_cycle = 0Stops a 180 servo. Remember, stopped is not the same as "off". The servo still holds its last position.
state = 'morning'Defines and initializes a variable for the state. This is also where students see that single quotes work for strings, just like double quotes (see the hint in Objective 4).
📐

Standards

CSTA Standards - Grades 6-8

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

CSTA Standards - Grades 9-10

3A-CS-03 3A-DA-11 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 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.
  • Wire up the light sensor, the divider, and the LED yourself once, and check the light readings in the console in your own room lighting so you know what values students should expect.

🧑‍🏫
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.
  • The duty cycles for the 180 servo are different from the 360 continuous servo used in Mission 6. Point that out, and keep a duty cycle table handy as a guide. Students who want the details can read more at PCB Cadence.
  • Like the Life Support project, this mission links life science with computer science. Have students consider the impact of technology on clean energy as well as fossil fuels.
  • There are cross curricular ties to math throughout. Students use percentages to solve the problems, and angles to describe the panel positions.
  • Bouncing shows up when students read the light sensor and the switch. If a program reacts twice to one event, that is the bug, not the student's logic. The console panel is the fastest way to see it happening.
  • 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. The next remix and assessment comes after Mission 9.
🗺️

Lesson Outline

🗣️Warm-up / Hook

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

  • Ask: "The crew is a long way from any power grid. Where does their electricity come from, and what happens when the sun moves?"
  • Ask: "How would a machine know it is morning? What could it measure to find out?"
Teaching tip: Walk an LED slowly across the front of the room and have the class call out "morning, noon, evening" as it passes. That is the whole mission in ten seconds, and students will refer back to it while they code.
📖Introduce the Mission

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

  • Show the 180 positional servo next to the 360 servo from Mission 6, and demonstrate the difference. The 180 turns to an angle and stays there.
  • Explain that there is no "off" for this servo. servo.duty_cycle = 0 stops the signal, but the panel holds its last position.
  • Wire the light sensor through the divider and show live readings in the console panel. Cover the sensor with a hand so the class watches the number drop.
  • Introduce the state variable with state = 'morning' and sketch morning, noon, and evening on the board with the condition that moves the program to the next one.
Teaching tip: Point out the single quotes here. Python treats them the same as double quotes, but the goal validator on Objective 4 can be picky, so it is worth a sentence now instead of a support question later.
💻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 as they plug in.
  2. Set the analog period on the 180 servo, then write a function that moves the panel to a given position and test a few values.
  3. Connect the light sensor through the divider, read it, and display the values in the console panel.
  4. Build SolarTracking using a state variable to rotate the panels from morning to noon to evening as the light changes.
  5. Complete both Checks for Understanding in CodeSpace.
Teaching tip: Have students record percent, angle, and observed direction in a chart as they test. It doubles as the math artifact and it saves them from guessing later when the state logic needs specific values.
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.
🧑‍🤝‍🧑Class Debrief

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

  • Ask: "What light values did you use as your cutoffs, and how did you pick them?"
  • Ask: "What states does your program have, and what has to happen for it to move from one to the next?"
  • Ask: "Did anything happen twice when you only meant it to happen once? What caused that?"
Teaching tip: Use the exit ticket here. Asking students to explain bouncing in their own words shows quickly who understands that sensor data is messy and who assumed the readings were perfect.
✏️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 7 Review Questions or the Mission 7 Review Kahoot! through whichever method you prefer, class discussion, Kahoot!, or an LMS quiz.

Teaching tip: Solar power is an easy bridge to a science lesson. If you have a spare class period, the "what does a day look like in space" question makes a strong follow-up discussion.