PyRasp

← All practice problems

Raspberry Pi Pico practice problem · Raspberry Pi Pico

Parking sensor

HardBudget $13MicroPython

Build a parking sensor from an HC-SR04 and a warning light:

  • TRIG GP20, ECHO GP21, VCC 5 V (VBUS), GND
  • active buzzer GP13
  • red LED GP15 (with its 330 Ω resistor)

Ping the sensor, measure the echo with time_pulse_us, and when the object is closer than 20 cm, turn the buzzer and the LED on. Otherwise leave both off. The test starts with a clear path (100 cm) and moves an object to 10 cm at 1.2 s.

trig.value(1)
utime.sleep_us(10)
trig.value(0)
distance = time_pulse_us(echo, 1) / 58

More in Raspberry Pi Pico