What You'll Learn
When you finish this mission, you'll be able to:
- Build a smart traffic light system that changes color based on your battery level
- Use floating-point numbers to calculate precise percentages instead of whole numbers
- Master else-if statements to make complex decisions with multiple conditions
- Create visual alerts that work even when you're not looking at the screen
- Combine previous concepts like RGB LEDs and sensor readings into one powerful system
By the end, your ship will have a glowing status light that tells you at a glance whether your power situation is safe, concerning, or critical. No more constantly checking numbers—just look for the light.
Understanding Traffic Light Logic
Think about the traffic lights you see every day on Earth. Red means stop, green means go, and yellow means "get ready to stop." This simple color system works because it gives you instant information without having to read numbers or text. Your brain processes colors faster than it processes words or numbers.
Now imagine you're a pilot flying a helicopter. Instead of constantly looking down at gauges showing fuel percentages, oil pressure readings, and engine temperature numbers, you have a simple light on your dashboard. Green = everything's fine, keep flying. Amber = pay attention, something needs monitoring. Red = urgent, land immediately. This is exactly what we're building for your spacecraft's battery system.
But here's where it gets interesting. To make smart decisions about which color to show, our microcontroller needs to understand ranges and make comparisons. It's like teaching a computer to be a traffic light controller that knows about battery levels instead of car traffic. We need to give it rules: "If the battery is above 50%, show green. If it's between 25% and 50%, show amber. If it's below 25%, show red and make it pulse to grab attention."
The magic happens when we combine three things we've already learned: reading sensor values (from our photoresistor "solar panel"), controlling LED colors (from our RGB experiments), and making decisions (with if statements). Today we're adding floating-point math to get precise percentages, and else-if statements to handle multiple conditions elegantly.
This isn't just about batteries—it's about creating interfaces that communicate critical information instantly. Whether it's a heart rate monitor in a hospital, a temperature warning in a nuclear reactor, or a fuel gauge in your car, the same principles apply. Clear, immediate, visual feedback saves lives.
Wiring Your Battery Status Light
Good news! We're using the exact same circuit from Day 8. Your RGB LED should already be connected to pins 9, 10, and 11, and your photoresistor (acting as our "solar panel") should be on pin A0. Here's why each connection matters:
- Photoresistor on A0: This simulates your solar panel charging system. The brighter the light, the more "power" it generates. The microcontroller reads this as a voltage level between 0-1023.
- RGB Red leg to Pin 11: Pin 11 supports PWM, which lets us control the brightness of the red light from 0 (off) to 255 (maximum brightness).
- RGB Green leg to Pin 10: Also PWM-capable, for precise green light control. When we want amber/yellow, we'll mix red and green.
- RGB Blue leg to Pin 9: PWM pin for blue control. We won't use blue today, but having it connected keeps our options open.
- RGB Common Cathode to Ground: All three LED colors share this ground connection. Think of it as the return path for electricity.

If your RGB LED isn't working, double-check that you have the common cathode (longest leg) connected to ground. Common anode LEDs exist too, but they work differently!
Setting Up Our Pin Definitions
Just like we learned in previous days, we start by telling our microcontroller which pins we're using. This creates a "map" that makes our code easier to read and modify later:
// Our photoresistor will give us a reading of the current light level on this analog pin
const byte PHOTORESISTOR_PIN = A0; // Photoresistor analog pin
// RGB LED pins
const byte RED_PIN = 11; // pin controlling the red leg of our RGB LED
const byte GREEN_PIN = 10; // pin ccontrolling the green leg of our RGB LED
const byte BLUE_PIN = 9; // pin ccontrolling the blue leg of our RGB LED
const unsigned long BATTERY_CAPACITY = 50000; // Maximum battery capacityThis is lesson 10 of 31 in 30 Days Lost in Space — a professionally produced Arduino course taught by Dr. Greg Lyzenga (NASA JPL scientist, Harvey Mudd professor). Each lesson features cinematic-quality video produced with a 20-30 person professional crew.
All video lessons are free to watch. Get the kit at craftingtable.com — $100 with a 30-day money-back guarantee.