All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Q: In this project the implementation of code for “Measuring distance of an object using ultrasonic distance sensor (28015 Ping) and also smoothen the sensor data using moving average filter”. Ans: Aim: To Measured distance of an object using ultrasonic distance sensor (28015 Ping) and display it…
Chandrakumar ADEPU
updated on 20 Apr 2023
Q: In this project the implementation of code for “Measuring distance of an object using ultrasonic distance sensor (28015 Ping) and also smoothen the sensor data using moving average filter”.
Ans:
Aim: To Measured distance of an object using ultrasonic distance sensor (28015 Ping) and display it on the LCD display.
Explanation:
The ultrasonic sensor has 4 pins that are vcc, trigger, echo, ground. the vcc pin is connected to the 5v of the arduino and trigger and echo pins are connected to the digital pins 8 and pin 9 . trigger is used as an output and echo is receive the reflected signal and send to find the distance of the object and trigger is used to display the distance value in the LCD display. the lcd pins are wired below:
To wire your LCD screen to your board, connect the following pins:
Code:
#include <LiquidCrystal.h> // lcd library include
#define trigger 8 // defining the trigger pin
#define echo 9 // defining the echo pin
LiquidCrystal lcd(12,11,5,4,3,2); // declaring the pins of the lcd RS, EN, D4,D5,D6,D7
float time=0,distance=0; // Declaring the variables in float
void setup()
{
lcd.begin(16,2); // begin the LCD
pinMode(trigger,OUTPUT); // pinmode declaration of the trigger pin
pinMode(echo,INPUT); // pin mode declaration of the echo pins
lcd.print(" Ultra sonic"); // printing on lcd
lcd.setCursor(0,1); // zero row coloum 1
lcd.print("Distance Meter"); // printing on lcd
delay(2000);
lcd.clear();
}
void loop()
{
lcd.clear();
digitalWrite(trigger,LOW); // trigger pin to low
delayMicroseconds(2);
digitalWrite(trigger,HIGH);// trigger pin to high to get the signals
delayMicroseconds(10);
digitalWrite(trigger,LOW);// trigger pin to low
delayMicroseconds(2);
time=pulseIn(echo,HIGH); // get the time value from echo pin is stored in variable time.
//formula for finding the distance
// distance =((time * sound in the air) /20000)
distance=time*340/20000;
lcd.clear();
lcd.print("Distance:");// printing on lcd
lcd.print(distance);// printing the distance value on lcd
lcd.print("cm"); // printing on lcd
delay(1000);
}
Output:
Note:
In the ultrasonic sensor shoes the 210.3 but in the display the distance = 207.62 cm so, this will occurs on the hardware side only.
--------------------------------------*************************-----------------------------------------
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Week - 4
Implement control logic of a “washing machine” using Stateflow as per given sequence: If the power supply is available, the system gets activated If the Water supply is not available, stop the process & indicate through LED Soaking time should be 200s followed by Washing time of 100s. Then rinsing…
29 Sep 2023 07:17 AM IST
Project 2 - V&V SW Analysis II
Q:- 1. Perform Static Code Review Analysis for “C:\**\LDRA_workarea\Examples\C_Testbed_examples\Testrain\Testrain.c” Generate Code review report and upload them. Ans: Aim: To gernetate the code review report and upload them. Steps: Steps for White box testing:- Source ->…
18 Aug 2023 01:16 PM IST
Project 1 - V&V SW Analysis - I
Q:- Write a Test plan to test features of a new mobile phone (Blackbox test) that needs to be implemented based on the following requirements. (The product is still under development stage and is yet to be UA (User Acceptance ) tested…
12 Jul 2023 03:17 AM IST
Project 2 - Measuring distance of an object using ultrasonic sensor (HC-SR04)
PROJECT-2: Aim: To write a program to measure the distance using ultasonic sensot Schematic Diagram: Steps of Programming ATmega16 microcontroller needs to transmit at least 10 us trigger pulse to the HC-SR04 Trig Pin. After getting a trigger pulse, HC-SR04 automatically sends eight 40 kHz sound waves and the microcontroller…
24 Jun 2023 09:50 AM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.