Lift-Off with CodeX - Mission 7: Solar Tracking!
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.
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.
Digital Resources
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
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.
- 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.
- 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
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?"
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 = 0stops 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.
Students work through the mission objectives in CodeSpace, taking notes and answering questions in their assignment doc as they go.
- Attach a horn to the servo and connect the servo to the CodeX, checking the wire colors as they plug in.
- 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.
- Connect the light sensor through the divider, read it, and display the values in the console panel.
- Build SolarTracking using a state variable to rotate the panels from morning to noon to evening as the light changes.
- Complete both Checks for Understanding in CodeSpace.
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?"
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.