Lesson 10 · 60 minutes
The 32 KB Backpack
Engineering is choosing
Today's goal
Choose a feature set that fits in the Arduino's memory, justify every choice, and prove it fits by compiling it.
Ideas in this lesson
- The Arduino Uno has about 32 KB for the program, and our sketch nearly fills it
- Every feature costs memory, and you cannot have everything
- Good engineering is choosing what matters for THIS robot
- Compile flags (USE_...) switch features in and out
Sense → Think → Do
Before any robot senses, thinks or does anything, someone chose which senses, thoughts and actions it has room for. Today you are that someone.
How the session runs
- Show the budget: about 32.2 KB in all. The default build uses about 32.2 KB: it is full.
- Hand out the price list: IMU 1.9 KB, laser 1.3 KB, IR remote 0.8 KB, 20 extra demos 0.75 KB, ADS1115 inputs 0.35 KB, mux 0.34 KB (off by default), sonar 0.3 KB.
- Each group picks a mission: maze runner, line racer, show robot for a party, classroom-safe robot.
- Choose a loadout for the mission. It must fit. Write why each feature is in or out.
- Open the sketch and set the USE_ flags at the top (1 = in, 0 = out). Compile in the Arduino IDE and read 'Sketch uses N bytes'. Did your estimate match?
- Flash it and show the robot doing its mission. The app greys out demos the robot does not have.
- Discuss: the extra demos and everything else do not quite fit together. Which would you drop, and why?
Try this
- A phone has a million times more memory. Why would anyone still build robots on an Uno?
- Which feature is the best value (most useful per KB) for your mission?
- If you had 1 KB more, what would you add?
When it goes wrong
| What you see | What it means |
|---|---|
| 'Sketch too big' when compiling | Over budget: turn one more feature off and compile again. |
| A feature is missing on the robot | Its USE_ flag is 0, or the part was not found at start-up (check the console). |
| Demos greyed out in the app | Built without USE_EXTRA_DEMOS. Expected: the robot tells the app which demos it has. |
Notes for the grown-up
This lesson works best for older kids, but the trade-off idea works at any age as a 'packing for a trip' game. The real story: this sketch went from 84 bytes free to fitting a laser, an IR remote and a sonar by rewriting parts to be smaller. Then in 0.10.19 the laser had to come out to make room for calibration saved on the robot, and in 0.10.20 it came back: the calibration runs moved into their own program, calibration.ino (then named mecanum_calibration.ino), made from the same source with the sensors left out. Two programs sharing one EEPROM is how real products do it: a factory test program, then the product.
Ages: K-5: 'pack the backpack' with paper cards for each feature and a fixed number of slots. 6-12: compile real builds and compare estimated vs actual sizes.
Materials: Laptop with Arduino IDE (or arduino-cli) and the sketch, robot, USB cable, feature price cards, mission cards.