Using an ultrasonic sensor to measure distance.

Components

  • 1x Ultrasonic sensor

Instructions

Connect VCC and GND to the Pico 3.3V and GND. Connect TRIG to GP15 and ECHO to GP14.

Open ultrasonic.cpp and run it on the Pico. In the serial console, it will print out the measured distance.

Info

The ultrasonic sensor measures distance by echolocation; it sends out a pulse of ultrasonic sound, and waits until the echo comes back. The ECHO pin goes high for the amount of time it took the sound to come back.

Use the following formula to convert to distance:

  • in air.

Exercise

Exercise

Integrate the ultrasonic sensor with another component you have used.

  • Turn on an LED if the distance crosses a threshold.
  • Dim an LED using PWM based on distance

Exercise

Use a piezo buzzer and the ultrasonic sensor to build a theremin.

Hint: Refer to Module 2.3