UltraSonic Sensor With Arduino
by anuragfulmali in Circuits > Arduino
146 Views, 1 Favorites, 0 Comments
UltraSonic Sensor With Arduino
In this project i got to learn about the pairing of Ultra Sonic Sensors with the Arduino Uno to detect the objects lying in between the 2cm-20cm. This Electronic Device is Economical, Easy to Operate and it works like a SONAR means it transmits the ultra sonic waves following if there is some object in between the Sensing Range it receive the signal back including with the dispersed frequencies of object as the object in between the given range the device starts to show HIGH output on the LED embedded on the Breadboard. This is the basic analogy and working of UltraSonic Sensor.
Supplies
1.Arduino Uno
2.Arduino IDE
3.Connecting Wires
4.LED
5.Resistor(100 Ohm)
6.UltraSonic Sensor
UltraSonic Sensor
The Ultrasonic Sensor SR-04 is a widely used distance measuring device that leverages the principles of sound wave reflection. This sensor consists of two main components: a transmitter that emits ultrasonic sound waves and a receiver that detects the waves after they bounce off a nearby object. When the transmitter sends out a sound pulse, it travels through the air until it hits an object and reflects back to the receiver. The time taken for this round trip is then used to calculate the distance to the object, using the speed of sound in air.
The SR-04 sensor is highly valued for its impressive range, capable of measuring distances from as close as 2 cm up to 400 cm, with an accuracy margin of about 3 mm. Its operational voltage of 5V makes it compatible with various microcontrollers, such as Arduino, allowing for straightforward integration and use in projects. Typical applications of the SR-04 include robotic navigation, where it helps in detecting obstacles, monitoring fluid levels, and even in automated parking systems for cars. The combination of affordability, ease of use, and dependable performance makes the Ultrasonic Sensor SR-04 a staple device for electronics projects.
https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf
Programme
#define trigPin 9
#define echoPin 10
#define ledPin 13 // Define the pin for the LED
void setup() {
// Initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// Set the trigPin as an output:
pinMode(trigPin, OUTPUT);
// Set the echoPin as an input:
pinMode(echoPin, INPUT);
// Set the ledPin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// Clear the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Set the trigPin on HIGH state for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the echoPin, returns the sound wave travel time in microseconds
long duration = pulseIn(echoPin, HIGH);
// Calculate the distance
long distance = duration * 0.034 / 2;
// Print the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
// Check if the distance is less than a threshold (e.g., 20 cm)
if (distance < 20) {
// Turn the LED on
digitalWrite(ledPin, HIGH);
} else {
// Turn the LED off
digitalWrite(ledPin, LOW);
}
// Wait for a short period before taking the next measurement
delay(1000);
}
Hardware Connection
All the Connections has done as mentioned in the above programme.