Introduction: Ultrasonic Distance Sensor Using Arduino
We are going to use the HC-SR04 ultrasonic sensor which enables your robots to avoid obstacles and will move in different directions.
Ultrasonic Sensor - HC-SR04
16X2 LCD with I2C Converter
Step 1: About the Project
Ultrasonic sensors are useful tools to measure distance without actual contact and utilized at various places like distance measurement, water level measurement, etc. This is an effective way to measure small distances accurately.
IoT Training online adds additional advantage to learn those concepts with its practical implementation to build End-to-End IoT Solutions.
In this project, we have used an Ultrasonic Sensor to determine the distance of an obstacle from the sensor and then the device will display it on a screen. Ultrasonic sensor HC-SR04 is utilized here to measure distance within the range of 2cm-400cm with an accuracy of 3mm.
The sensor module includes an ultrasonic transmitter, receiver and control circuit. In-circuit connections Ultrasonic sensor module’s “trigger” and “echo” pins are directly attached to pin 18(A4) and 19(A5) of Arduino.
A 16x2 LCD with I2C is connected with Arduino in 4-bit mode. Control pins RS, RW and En are attached directly to Arduino pin 2, GND and 3. And data pin D4-D7 is connected to 4, 5, 6 and 7 of Arduino.
First of all, it is necessary to trigger the ultrasonic sensor module to transfer signals by using Arduino and then wait to receive ECHO. Arduino reads the time between triggering and Received ECHO. A 16x2 LCD is generally used for displaying distance.
so we can evaluate the distance by using the following formula: Distance= (time/2) * speed of sound Where speed of sound around 340m per second.
Step 2: Run a Program
#define trigger 18
#define echo 19
lcd.print(" Ultra sonic");
lcd.print(" Circuit Digest");
Question 3 years ago on Step 2
what should be included here?The IDE is showing n error message with "#include expects "FILENAME" "
What is the solution for this?
Reply 3 years ago
It is #include<LiquidCrystal.h>
for more detail kinldy check https://www.hackster.io/hiotron/ultrasonic-distance-sensor-using-arduino-26869d