Measure Distance

Intermediate

Read the HC-SR04 ultrasonic sensor and display the live distance on the OLED. Watch the number change as you move your hand closer and farther from the board.

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 ultrasonic sensor is wired to GP16 (TRIG) and GP17 (ECHO) on the board — no extra connections needed.

The HC-SR04 sends an ultrasonic pulse and times how long it takes to bounce back. The board converts that round-trip time into centimetres for you automatically.