Challenge

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

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

ANSWER:-

AIM:-

To implement the code for “Measuring distance of an object using ultrasonic distance sensor (28015 Ping) and also smoothen the sensor data using moving average filter”.

COMPONENTS REQUIRED:-

  • BREADBOARD
  • ARDUNIO
  • RESISTOR
  • ULTRASONIC DISTANCE SENSOR
  • CONNECTING WIRE
  • POTENTIOMETER
  • LCD 16*2

CODE OF THE PROJECT:-

#include<LiquidCrystal.h> //Header to use LCD functions

#define trigger 18

#define echo 19

LiquidCrystal lcd(2,3,4,5,6,7); //pins connected to LCD

float time=0,distance=0;

void setup()

{

lcd.begin(16,2); //To begin LCD display

pinMode(trigger,OUTPUT); //declaring pin2 as output

pinMode(echo,INPUT);

lcd.print(" Ultra sonic"); //To display in LCD

lcd.setCursor(0,1);

lcd.print("Distance Meter"); //To display in LCD

delay(2000);

lcd.clear();

lcd.print(" Circuit Digest"); //To display in LCD

delay(2000); //delay

}

void loop()

{

lcd.clear();

digitalWrite(trigger,LOW); //sensor is triggered by pin 2 as output

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:"); //to display in LCD

lcd.print(distance);

lcd.print("cm"); //To display in LCD

lcd.setCursor(0,1);

lcd.print("Distance:");

lcd.print(distance/100); //To display in LCD

lcd.print("m");

delay(1000); //delay

}

OUTPUT:-

it was showing the distance of an object in the LCD.

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.