Distance Measurement Using Ultrasonic Sensor (Hc-Sr04) And Arduino
Distance Measurement Using Ultrasonic Sensor (Hc-Sr04) And Arduino
The Arduino is connected to an HC-SR04 ultrasonic sensor, enabling the measurement of distances within a short range, spanning from 2 cm to 400 cm or 1 inch to 13 feet. This adaptable project finds utility in tasks like water level measurement and distance measurement. The HC-SR04 sensor excels in non-contact range detection, providing high accuracy and consistent readings in a user-friendly design. Importantly, its performance remains unaffected by sunlight or material color, distinguishing it from Sharp rangefinders. The HC-SR04 comprises both an ultrasonic transmitter and a receiver module.
Components Required:
- Arduino Uno with USB 2.0 Cable
- Ultrasonic Sensor(HC-SR04)
- Jumper Wires
- Breadboard
Arduino Uno with USB 2.0 Cable:
Ultrasonic Sensor:
The Ultrasonic sensor HC-SR04 is employed in this setup to measure distances within a range of 2 cm to 400 cm. This is achieved through the transmission and reception of ultrasonic waves. The transmitter emits an ultrasonic wave, and the sensor calculates the distance by measuring the time duration between sending the signal and receiving its reflection from the target.
distance can be calculated by using formula:
Distance=(Time duration/2)* Speed of
sound in air
(speed of sound in air is about 343
meters per second)
Specifications (HC_SR04):
- Power Supply :+5V DC
- Quiescent Current : <2mA
- Working Current: 15mA
- Effectual Angle: <15°
- Ranging Distance : 2cm – 400 cm/1" - 13ft
- Resolution : 0.3 cm
- Measuring Angle: 30 degree
- Trigger Input Pulse width: 10uS
- Dimension: 45mm x 20mm x 15mm
Jumper Wires:
A jumper wire is an electrical wire equipped with connectors or pins at each end. It is commonly employed to interconnect components without the need for soldering, providing a convenient method for establishing electrical connections between different parts of a circuit.
Breadboard:
A breadboard is a solderless device for temporary prototyping of
electronics. It is used to interconnection between sensors and hardware
boards using jumper wires.
Connection Diagram:
Connect your components according to the provided diagram and link the USB cable from Arduino to your computer.
Arduino Code:
#define
trigPin 12
#define
echoPin 11
//
defines variables
int
duration, distance;
void
setup ()
{
Serial.begin(9600); //
Starts the serial communication
pinMode(trigPin,
OUTPUT);// Sets the trigPin as an Output
pinMode(echoPin,
INPUT);//
Sets the echoPin as an Input
Serial.print("Ultrasonic
Sensor Starting!!!");
Serial.println("");
delay(1000);
}
void
loop ()
{
//
Clears the trigPin
digitalWrite(trigPin,
HIGH);
delay(1000);
digitalWrite(trigPin,
LOW);
duration
= pulseIn(echoPin, HIGH);
distance
=(duration/2) * 0.0343; // Calculating the distance in cm
//
Prints the distance on the Serial Monitor
Serial.print("Distance
= ");
Serial.print(distance);
Serial.println("
cm");
delay(1000);
}
Upload
Code:
Connect
Arduino board to computer using USB cable and wait for few seconds then it will
show you "Com port".
Check
your Com Port and Board Selection before upload arduino code and upload.
Output:
Additional Projects:
Subscribe to:
Post Comments
(
Atom
)
Internet of Things
What is Internet of Things?
What is IoT? The Internet of Things (IoT) is the network of physical objects/things are embedded with software, sensors, and hardw...
No comments :
Post a Comment