Ultrasonic Module
Introduction
The ultrasonic module is a commonly used distance measurement sensor that uses ultrasonic echo time to calculate distance. It is widely used in distance measurement, obstacle avoidance, drone navigation, smart car and other fields. The ultrasonic module consists of an ultrasonic transmitter and receiver, which sends ultrasonic pulses and receives echo signals, and determines the distance between the target object and the sensor by measuring the echo time.
The working principle of the ultrasonic module is to utilize the characteristics of ultrasonic waves propagating in air. It sends a short pulse of ultrasonic signal and waits to receive the echo signal. Based on the time difference between sending and receiving, the distance between the target object and the sensor can be calculated. The ultrasonic module has the characteristics of high precision, fast response and non-contact measurement.
Product Photos


Product Specifications
- Operating Voltage: 3.3V-5V
- Operating Frequency: 40kHz
- Maximum Measuring Distance: 250cm
- Output Signal: Digital Signal (Pulse Width Mode)
- Interface Type: PH2.0 4P
Pin Description
No. | Pin | Description |
---|---|---|
1 | GND | Power Negative |
2 | VCC | Power Positive |
3 | Trig | Trigger Signal Input |
4 | Echo | Echo Signal Output |
Arduino Example Code
The following example code demonstrates how to use the ultrasonic module for distance measurement on Arduino.
const int trigPin = 2; // Set trigger pin to D2
const int echoPin = 3; // Set echo pin to D3
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(trigPin, OUTPUT); // Set trigger pin to output mode
pinMode(echoPin, INPUT); // Set echo pin to input mode
}
void loop() {
digitalWrite(trigPin, LOW); // Set trigger pin to low level
delayMicroseconds(2);
digitalWrite(trigPin, HIGH); // Set trigger pin to high level
delayMicroseconds(10);
digitalWrite(trigPin, LOW); // Set trigger pin to low level
long duration = pulseIn(echoPin, HIGH); // Read pulse width of echo pin
float distance = duration * 0.034 / 2; // Calculate distance based on echo time, unit is cm
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(1000); // Delay 1 second
}
MicroPython Example Code
The following example code demonstrates how to use the ultrasonic module for distance measurement in MicroPython environment.
python
Copy code
from machine import Pin, time_pulse_us
trig_pin = Pin(2, Pin.OUT) // Set trigger pin to D2
echo_pin = Pin(3, Pin.IN) // Set echo pin to D3
while True:
trig_pin.low() // Set trigger pin to low level
time.sleep_us(2)
trig_pin.high() // Set trigger pin to high level
time.sleep_us(10)
trig_pin.low() // Set trigger pin to low level
duration = time_pulse_us(echo_pin, 1) // Read pulse width of echo pin
distance = duration * 0.034 / 2 // Calculate distance based on echo time, unit is cm
print("Distance:", distance, "cm")
time.sleep(1) // Delay 1 second
Results
The ultrasonic module is a commonly used distance measurement sensor that calculates the distance between the target object and the sensor by sending ultrasonic signals and measuring echo time. It has the characteristics of high precision, fast response and non-contact measurement, and is widely used in various projects. By using appropriate pin connections and example code, you can easily use the ultrasonic module for distance measurement operations in Arduino or MicroPython environment.
Troubleshooting
For more questions and interesting applications, please visit the Forum or join QQ technical exchange group: 522420541