How to Use an Ultrasonic Sensor with RPi and C++

Follow this wiring diagram for the HC-SR04 ultrasonic sensor: I used 1KΩ and 2KΩ resistors instead of 330Ω and 470Ω (because it's what I had on hand). Here's what that looked like: Test the wiring with this simple Python script: from gpiozero import DistanceSensor from time import sleep ultrasonic = DistanceSensor(echo=17, trigger=4, max_distance=4) while True: print(f"{ultrasonic.distance *…