

The ULTRASONIC sensor is a device that uses high-frequency sound waves to measure distances or detect objects in its surroundings. It operates by emitting ultrasonic waves and measuring the time it takes for the echo to return after bouncing off an object. This time-of-flight measurement is then used to calculate the distance to the object.
Common applications of the ULTRASONIC sensor include:








The following are the key technical details of the 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, as described below:
| Pin Name | Description |
|---|---|
| VCC | Power supply pin (5V DC) |
| GND | Ground pin |
| TRIG | Trigger pin: Used to send the ultrasonic pulse |
| ECHO | Echo pin: Outputs a pulse proportional to distance |
VCC pin to a 5V power source and the GND pin to ground.TRIG pin to initiate a measurement.ECHO pin. This duration corresponds to the time taken for the ultrasonic wave to travel to the object and back.0.034 represents the speed of sound in cm/µs, and the division by 2 accounts for the round trip of the wave.Below is an example of how to use the ULTRASONIC sensor with an Arduino UNO:
// Define pins for the ULTRASONIC sensor
const int trigPin = 9; // TRIG pin connected to digital pin 9
const int echoPin = 10; // ECHO pin connected to digital pin 10
void setup() {
pinMode(trigPin, OUTPUT); // Set TRIG pin as output
pinMode(echoPin, INPUT); // Set ECHO pin as input
Serial.begin(9600); // Initialize serial communication
}
void loop() {
// Send a 10 µs HIGH pulse to the TRIG pin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Measure the duration of the HIGH pulse on the ECHO pin
long duration = pulseIn(echoPin, HIGH);
// Calculate the distance in cm
float distance = (duration * 0.034) / 2;
// 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
}
No Output or Incorrect Readings:
VCC and GND connected).TRIG and ECHO pins.Inconsistent Measurements:
Interference from Nearby Sensors:
Q: Can the ULTRASONIC sensor detect transparent objects?
A: The sensor may struggle to detect transparent objects like glass, as ultrasonic waves may pass through or reflect unpredictably.
Q: What is the maximum angle of detection?
A: The sensor typically has a detection angle of about 15 degrees. Ensure objects are within this cone for accurate measurements.
Q: Can the sensor be used outdoors?
A: While the sensor can be used outdoors, ensure it is protected from water and extreme environmental conditions to prevent damage.
By following this documentation, users can effectively integrate the ULTRASONIC sensor into their projects and troubleshoot common issues.