PyRaspBeta

← All practice problems

Raspberry Pi practice problem · Projects

Bin gauge

MediumBudget $16Python · gpiozero

A distance sensor in the lid of a 50 cm deep bin looks down at the rubbish (TRIG GPIO23, ECHO GPIO24, 5 V, ECHO divided down). A NeoPixel stick (8 LEDs, data GPIO18, 5 V) shows how full it is, updated 5 times a second:

  • lit pixels: round((50 − distance) / 50 × 8), clamped to 0–8, from pixel 0; the rest off
  • colour: green (0, 255, 0), or red (255, 0, 0) when 7 or more are lit (time to empty it)

The test bin reads 60 cm (empty), 25 cm at 2 s, 5 cm at 4 s and 30 cm at 6 s.

More in Projects