Distance Sensor in Python

Intermediate

Read the HC-SR04 ultrasonic sensor with `pybot.distance()`, display the live reading on the OLED, and apply a threshold to trigger a LED and buzzer alert.

20 min5 steps
DistanceHC-SR04SensorOLEDIntermediate
0 of 5 steps

Step 1 of 5

Connect your board

Power on your Beaver Board — the OLED will show a PIN code. Click Connect in the toolbar, choose Connect via Bluetooth, and select your board. If it's your first time, enter the PIN shown on the screen.

The HC-SR04 is wired to GP16 (TRIG) and GP17 (ECHO) — no extra connections needed.