

The ultrasonic sensor is an electronic component that uses high-frequency sound waves to measure distances or detect objects. It operates by emitting ultrasonic waves and measuring the time it takes for the waves to bounce back after hitting an object. This time-of-flight measurement is then used to calculate the distance to the object. Ultrasonic sensors are widely used in robotics, automation, automotive parking systems, and obstacle detection.








Below are the key technical details of a typical ultrasonic sensor:
| Parameter | Value |
|---|---|
| Operating Voltage | 5V DC |
| Operating Current | 15 mA |
| Measuring Range | 2 cm to 400 cm |
| Accuracy | ±3 mm |
| Operating Frequency | 40 kHz |
| Trigger Input Signal | 10 µs TTL pulse |
| Echo Output Signal | TTL pulse proportional to distance |
| Dimensions | 45 mm x 20 mm x 15 mm |
The ultrasonic sensor typically has four pins. Their configuration and descriptions are as follows:
| Pin | Name | Description |
|---|---|---|
| 1 | VCC | Power supply pin. Connect to 5V DC. |
| 2 | Trig | Trigger pin. Send a 10 µs pulse to initiate distance measurement. |
| 3 | Echo | Echo pin. Outputs a pulse width proportional to the distance of the detected object. |
| 4 | GND | Ground pin. Connect to the ground of the circuit. |
Below is an example of how to use the ultrasonic sensor with an Arduino UNO to measure distance:
// Define pins for the ultrasonic sensor
const int trigPin = 9; // Trigger pin connected to digital pin 9
const int echoPin = 10; // Echo pin connected to digital pin 10
void setup() {
pinMode(trigPin, OUTPUT); // Set the trigger pin as an output
pinMode(echoPin, INPUT); // Set the echo pin as an input
Serial.begin(9600); // Initialize serial communication at 9600 baud
}
void loop() {
// Send a 10 µs HIGH pulse to the trigger pin
digitalWrite(trigPin, LOW);
delayMicroseconds(2); // Ensure a clean LOW signal
digitalWrite(trigPin, HIGH);
delayMicroseconds(10); // Send a 10 µs HIGH pulse
digitalWrite(trigPin, LOW);
// Measure the duration of the HIGH pulse on the echo pin
long duration = pulseIn(echoPin, HIGH);
// Calculate the distance in centimeters
float distance = duration / 58.0;
// Print the distance to the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(500); // Wait for 500 ms before the next measurement
}
pulseIn() function measures the duration of the HIGH pulse on the Echo pin.No Output or Incorrect Distance Readings:
Unstable or Fluctuating Readings:
Sensor Not Responding:
Echo Pin Always LOW:
Q1: Can the ultrasonic sensor detect transparent objects?
A1: No, ultrasonic sensors may struggle to detect transparent objects like glass, as sound waves can pass through or reflect unpredictably.
Q2: What is the maximum range of the sensor?
A2: The maximum range is typically 400 cm, but accuracy decreases at longer distances.
Q3: Can I use the sensor outdoors?
A3: Yes, but environmental factors like wind, rain, and temperature changes may affect performance.
Q4: How do I improve accuracy?
A4: Use averaging techniques by taking multiple readings and calculating the mean distance.
By following this documentation, you can effectively integrate and troubleshoot the ultrasonic sensor in your projects.