What You'll Learn
By the end of today's mission, you'll have transformed your power-hungry emergency light into an intelligent, switch-controlled system. You'll master the art of reading input signals from the physical world and making your microcontroller respond with precise output control.
When you finish this lesson, you'll be able to:
- Wire a DIP switch as an input device that talks to your HERO Board
- Use digitalRead() to listen for switch positions (ON/OFF, HIGH/LOW)
- Write conditional logic with if and else statements
- Control LED output based on real-world input switches
- Understand the difference between assignment (=) and comparison (==) operators
- Build a complete input-processing-output system that conserves battery power
Most importantly, you'll understand how microcontrollers make decisions—reading the world around them and responding intelligently to changing conditions.
Understanding Input and Output
Think of your microcontroller as the brain of a very attentive robot. Just like you use your senses to understand the world—your eyes see light, your fingers feel texture, your ears hear sounds—a microcontroller uses its pins to "sense" the electrical world around it.
Inputs are like the microcontroller's senses. When you flip a switch, press a button, or a sensor detects motion, these devices send electrical signals to input pins. The microcontroller "reads" these signals and says, "Aha! Something in the world has changed!" It's exactly like when you hear a doorbell and know someone wants to come in.
Outputs are like the microcontroller's actions. Just as you might turn on a light when you hear that doorbell, the microcontroller can send signals to output pins to control LEDs, motors, buzzers, or any other device. It's the microcontroller saying, "Based on what I sensed, here's what I'm going to do about it."
In your survival situation, the DIP switch becomes your way of communicating with the lander's computer. When you flip that switch to ON, you're sending a HIGH signal (about 5 volts) to an input pin. When you flip it OFF, you're sending a LOW signal (0 volts). The microcontroller constantly checks that input pin, asking "What's the human telling me to do right now?"
This input-processing-output cycle happens incredibly fast—thousands of times per second. Your microcontroller is like an extremely dedicated assistant, constantly asking "What should I do? What should I do? What should I do?" and responding immediately to any changes in the input signals.
Today's project demonstrates this beautifully: your switch position (input) gets read by the microcontroller (processing), which then decides whether to turn the LED on or off (output). It's a complete feedback loop between human intention and electronic response.
Mission-Critical Wiring

Your survival depends on making these connections correctly. Each wire carries vital signals between your switch and the lander's control systems.
- DIP Switch Power: Connect the DIP switch's VCC pin to the 5V rail on your breadboard. This gives the switch the power it needs to send clear HIGH signals.
- Switch to Input Pin: Connect one of the DIP switch positions to digital pin 2 on your HERO Board. This creates the communication pathway for your switch commands.
- Pull-down Resistor: Connect a 10kΩ resistor from pin 2 to Ground (GND). This prevents "floating" voltage when the switch is OFF—without it, your switch readings would be unreliable.
- LED Output: Keep your LED connected to digital pin 12 (just like Day 2). The switch will control this light through your code.
- Common Ground: Ensure all GND connections share the same ground rail. This gives every component the same voltage reference point.
The pull-down resistor isn't optional—it's essential for reliable switch readings. Without it, your input pin "floats" and can give random readings, causing your lights to flicker unpredictably.
Code Walkthrough: Building Intelligence
Now comes the moment where your lander's computer brain learns to make decisions. We'll build this intelligence step by step, teaching your microcontroller to listen for your commands and respond appropriately.
Step 1: Including the HERO Board Libraries
#include "Arduino.h"This is lesson 4 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.