Raspberry Pi practice problem · Sensors
Tank level
MediumBudget $9Python · gpiozero
An HC-SR04 (TRIG GPIO23, ECHO GPIO24 through a divider, or the 3.3 V-safe module) is mounted on the lid of a 100 cm deep tank, looking down at the water. The water level in percent is (100 − distance in cm). Every 0.5 s print it as a whole number:
Tank: 70%
and keep a red LED on GPIO17 lit while the tank is below 20 %.
The water surface starts 30 cm below the sensor, drops to 60 cm at 3 s and to 85 cm at 6 s. (gpiozero's DistanceSensor reads at most 1 m by default.)