Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Experiment # 2

Distance Measurement System based on Arduino Uno R3

Objective

To interface the HR-SO4 module with Arduino in order to measure the distance

Apparatus

 HR-so4
 LCD16x 2
 Arduino UNO R3 board
 LDR
 bread Board
 Jumper wires

Theory:
The ultrasonic sensor uses sonar to determine the distance to an object. This sensor reads from
2cm to 400cm (0.8inch to 157inch) with an accuracy of 0.3cm (0.1inches), which is good for
most hobbyist projects. In addition, this particular module comes with ultrasonic transmitter and
receiver modules. The ultrasound transmitter (trig pin) emits a high-frequency sound (40
kHz).The sound travels through the air. If it finds an object, it bounces back to the module. The
ultrasound receiver (echo pin) receives the reflected sound (echo).

Circuit Diagram:

Fig 3 : Measuring distance


with ultrasonic sensor
Procedure:
 Arduino IDE software is used to write and upload the program in Arduino.
 USB -B is used to connect computer& arduino board .
 Connecting the HC-SR04 to Arduino is very easy. Start by placing the sensor on your
breadboard. Connect the VCC pin to the 5V pin on the Arduino and the GND pin to the
ground pin. Now connect the trig and echo pins to digital pins #5 and #6 respectively.

Code
const int Trig =5;
const int Echo =6;
float Time;
int Distance;
#include<Wire.h>
#include<LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16,2);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(Trig,OUTPUT);
pinMode(Echo,INPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("ultrasonicsensor");
delay(1000);

}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(Trig,LOW);
delayMicroseconds(2);
digitalWrite(Trig,HIGH);
delayMicroseconds(10);
digitalWrite(Trig,LOW);
Time=pulseIn(Echo,HIGH);
Figure 17: Ultrasonic Sensor connected with Arduino

//Serial.print(time);
Serial.println(Distance);
lcd.setCursor(2,1);
lcd.print("Distance=");
lcd.print(Distance);
delay(100);

}
Observation and Calculation:

Readings by Meter Rule Readings by Sensor


4.0 3.91
6.0 6.12
8.0 8.01
10.0 10.11
12.0 12.21
14.0 13.92
16.0 16.16
18.0 18.41

Table : Readings for Ultrasonic Sensor

Graph:

Calibration Graph
Reading
20 by Meter Rule
18
16
14
12
10
8
6
4
2
0
0 2 4 6 8 10 12 14 16 18 20
Reading by Sensor

Figure 4: Calibration graph for Ultrasonic Sensor


Conclusion:
The HC-SR04 ultrasonic sensor is a widely used and cost-effective device for measuring distance in
various applications. It operates on the principle of sending ultrasonic pulses and calculating the time it
takes for the pulses to bounce back after hitting an object. By using this time information and the speed of
sound, the sensor accurately determines the distance to the object. Its simple interface and affordable
price make it a popular choice for robotics, automation, and IoT projects. However, it's essential to
consider factors such as accuracy, reliability, and potential interference in certain environmental
conditions when incorporating the HC-SR04 into a specific project. Despite its limitations, the sensor
provides a practical and accessible solution for distance measurement in many scenarios.

You might also like