PyRaspBeta

← All practice problems

Raspberry Pi practice problem · Sensors

Imperial ruler

EasyBudget $7Python · gpiozero

An HC-SR04 distance sensor with TRIG on GPIO23 and ECHO on GPIO24 — its ECHO is 5 V, so divide it down (1 kΩ + 2 kΩ) or use the 3.3 V-safe module. Every 0.5 s print the distance in whole inches (1 inch = 2.54 cm):

20 in

The target is 50.8 cm away, then moves to 25.4 cm at 3 s.

More in Sensors