Lessons and the learning game

Build a parking assistant

A garage stop light from scratch: an ultrasonic sensor, green, yellow and red LEDs, smoothing for messy echoes, sleep when parked, and mounting notes.

What it teaches

A gentle beginner build in six lessons, for anyone who has run a first Uno sketch:

  • Measure and show: how an HC-SR04 measures with a chirp and an echo (343 m/s, there and back), a beeping parking sensor and its stop line, then a stick of eight WS2812 LEDs that shows green, yellow and red zones.
  • Steady and smart: averaging the last five readings and what that costs in time, riding out a missed echo, and a light that sleeps when the car is parked and wakes when it moves.
  • Build it: where to mount the sensor and the lights, why a cold garage reads 4% long, telling the sketch the temperature, and the project: the finished garage stop light with a flashing "too close".

Open it at /learn/path/build-parking-assistant.

The circuits

  • The first lesson uses the classroom Parking sensor: an HC-SR04 on pins 7 (TRIG) and 6 (ECHO), a buzzer on pin 9 and a red LED on pin 8, running parking.
  • The rest use the Garage stop light: the same sensor pins and a stick of eight WS2812 LEDs on pin 5, running parklight. Its settings are constants at the top of the sketch: the zones (WATCH_MM, YELLOW_MM, STOP_MM, FLASH_MM), SAMPLES, HOLD_MISSES, SLEEP_MS and TEMP_C.

Drag the sensor's slider to move the car (in millimeters, 0 for nothing).

Safety

Power the finished light from a 5 V USB phone charger. Never wire anything into the house's mains wiring yourself.

Troubleshooting

  • The light stays off: the car is more than 2 m away, or the slider is at
    1. Bring it inside 200 cm.
  • The light flickers off for a moment: a missed echo. Set HOLD_MISSES to 3.
  • The reading is a few centimeters off: check TEMP_C against the sensor's temperature.
  • It never sleeps: SLEEP_MS is 0, or the car is still moving more than 3 cm between readings.