Ultrasonic sensors use high-frequency sound waves to detect distance, then they measure the time it takes for the echoes to bounce back.
When combined with the Arduino microcontrollers computing capacity, we can build a system that can precisely calculate an objects distance from us.
This assignment will examine the fundamentals of ultrasonic sensors, the necessary Arduino code and the procedures for constructing a system for measuring distance.
Code and Explanations:
const int trigPin = 2;
const int echoPin = 3;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
}
void loop() {
// Trigger the sensor
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Measure pulse duration
long duration = pulseIn(echoPin, HIGH);
// Calculate distance
int distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(100);
}
- Add the required libraries for this project, there are no external libraries needed.
- Describe pin decide on pin numbers for the echo and trigger pins.
- Setup is assign the output pin to the trigger.
- Choose input for the echo pin.
- Start the serial communication process.
- Loop gives the sensor a trigger pulse.
- Calculate how long the echo pulse lasted.
- Use the following formula to calculate the distance:
- distance =
(duration*speedofsound)/2
- Print the distance to the serial monitor that was determined.
Ultrasonic Sensor Circuit Working :
Parts List:
Component | Quantity |
---|---|
Arduino UNO | 1 |
LCD 16X2 Display | 1 |
Ultrasonic Sensor Module | 1 |
IC 7809 | 1 |
Potentiometer 10k | 1 |
A transmitter and a receiver are the two transducers that are usually found in an ultrasonic sensor.
Transmission is a brief burst of ultrasonic waves is released by the transmitter.
Waves propagate across the atmosphere until they come into contact with an item.
Reflection is the waves create an echo when they strike an item and return.
Reception is the returning echo is picked up by the receiver.
Calculating distance is the distance to an object is exactly proportional to the amount of time that passes between sending a signal and receiving an echo.
How to Build:
To build a Distance Measurement using Ultrasonic Sensor and Arduino follow the below mentioned steps for connections:
- Gather all the components as shown in the above circuit diagram.
- Connect a regulated IC1 7809 to provide a regulated 9V DC to the Arduino board
- Connect pot 10k 1st pin to VDD (5V) pin of LCD display board, 2nd leg of pot 10k to VE (contrast) pin of LCD display board and 3rd leg of pot 10k to VSS (GND) pin of LCD display board.
Connections details of Arduino and LCD
- Connect LCD VDD to Arduino 5V
- Connect LCD VSS GND to Arduino GND
- Connect LCD RS register select to Arduino digital pin 12
- Connect LCD Enable E to Arduino digital pin 11
- Connect LCD RW Read/Write to Arduino GND
- Connect LCD D4 to Arduino digital pin 5
- Connect LCD D5 to Arduino digital pin 4
- Connect LCD D6 to Arduino digital pin 3
- Connect LCD D7 to Arduino digital pin 2
- Connect LCD backlight anode to Arduino 5V
- Connect LCD backlight cathode to Arduino GND
Connections details of Ultrasonic Sensor:
- Connect Trig pin to a digital output pin on the Arduino pin 2
- Connect Echo pin to a digital input pin on the Arduino pin 3
- Connect Vcc to the 5V pin on the Arduino.
- Connect GND pin to the ground pin on the Arduino.
Note:
The estimated speed of sound, which is 0.034 cm/µs, is a rough figure that might change based on the air temperature and humidity.
You might need to modify this number for measurements that are more exact.
Conclusion:
Through the integration of an Arduino board and an ultrasonic sensor, we can effectively develop a distance measurement system.
The foundation for several applications, including as proximity sensing, object identification and obstacle avoidance, is provided by this research.
More sophisticated systems can be created by adding more sensors, displays or actuators for further improvements.
Leave a Reply