ESP32 | Sensor 08 – Ultrasonic Sensor

ESP32 | Sensor 08 - Ultrasonic Sensor

01

Overview

The ultrasonic sensor is a type of sensor that uses ultrasonic waves to measure the distance to obstacles in front.

This ultrasonic sensor has undergone many optimizations, providing stable performance and accurate distance measurement, and is compatible with LEGO small particle blocks.

02

Principle

Humans can hear sounds due to vibrations of objects, with frequencies ranging from 20Hz to 20kHz. Frequencies above 20kHz are called ultrasonic waves, while those below 20Hz are called infrasonic waves.

The ultrasonic sensor utilizes the reflection characteristics of ultrasonic waves at the interface of two media, recording the time interval from sending the ultrasonic wave to receiving it, thus calculating the distance to the obstacle.

The calculation formula is: Distance = Speed of Sound × Time ÷ 2.

Since the time measured is the round-trip time of the ultrasonic wave, it needs to be divided by 2.

When using the ultrasonic sensor, do not let the object being measured touch the sensor; there should be a gap in between. If the object is too close to the ultrasonic probe, you might think the measured distance should be 0, but that is not the case. As mentioned earlier, it requires two media; if it is touching the sensor, there is only one medium, and the distance cannot be measured. Air is also needed as a medium in between.

03

Wiring

  • Supply Voltage: 3.3V or 5V
  • TRIG: Control pin, connect to pin 2
  • ECHO: Receive pin, connect to pin 4
  • VCC: Positive terminal, connect to 5V
  • GND: Negative terminal, connect to G pin

ESP32 | Sensor 08 - Ultrasonic Sensor

04

Program

ESP32 | Sensor 08 - Ultrasonic SensorESP32 | Sensor 08 - Ultrasonic Sensor

If you need accessories, you can purchase them from my Taobao store under the same name.

ESP32 | Sensor 08 - Ultrasonic SensorFollow me for more sharingWeilan Classroom

Leave a Comment