Challenge

Project 2 - Measuring the distance of an object using ultrasonic sensor and also smoothen the sensor data using moving average filter

Overview of the Project:

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”.

Goals:

  • Measuring the distance in terms of inches of an object using Ultrasonic Distance Sensor (28015 Ping).
  • The sensor data is smoothened by using Moving average filter technique to eliminate the high frequency variations from the sensor data.

Key Highlights of the Project:

  • Measuring the distance travelled by the wave to the object and gets bounced back from the object to sensor.
  • Smoothening the sensor data by moving average filter technique, the filter has a window of certain size. That window determines that how many data the filter can take.

Code:-

#include <LiquidCrystal.h> //Header file for LCD
#define trigger 18//Connecting trigger pin of Ultrasonic sensor to Pin no 18 of Arduino
#define echo 19//Connecting echo pin of Ultrasonic sensor to Pin no 19 of Arduino
LiquidCrystal lcd(11,12,2,3,4,5);//Connecting LCD pin with Arduino
float time=0,distance=0;//Declaring variables
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
pinMode(trigger,OUTPUT);//Setting trigger as OUTPUT
pinMode(echo,INPUT);//Setting eco as input
lcd.print(" Ultra sonic");
lcd.setCursor(0,1);
lcd.print("Distance Meter");
delay(2000);
lcd.clear();
lcd.print(" Circuit Digest");
delay(2000);

}
void loop()
{
lcd.clear();
digitalWrite(trigger,LOW);
delayMicroseconds(2);
digitalWrite(trigger,HIGH);
delayMicroseconds(10);
digitalWrite(trigger,LOW);
delayMicroseconds(2);
time=pulseIn(echo,HIGH);
distance=time*340/20000;
lcd.clear();
lcd.print("Distance:");
lcd.print(distance);
lcd.print("cm");
lcd.setCursor(0,1);
lcd.print("Distance:");
lcd.print(distance/1000);
lcd.print("m");
Serial.println(distance);
delay(1000);
}

Note:Here in the serial monitor we sre getting the distance and in the LCD we are getting the filtering process of signals.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.