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.

Deliverables of this project:

  • The distance travelled by a wave to the object for which we want to measure the distance using Ultrasonic Distance Sensor (28015 Ping).
  • Eliminate the high frequency jitters from the sensor data by Moving Average filter to smoothen the sensor data.

Expected Outcomes:

The students will get the Knowledge on Ultrasonic sensor (28015 Ping) to measure the distance travelled by wave to the object, the hardware connection of 2 Arduino’s connected to the sensor and smoothening the sensor data by removing high frequency variations using Moving Average Filter Technique.

......................................................................................................................................................................................................

CODE :-

#include <LiquidCrystal.h> // lcd header file(liquidcrystal.h)
LiquidCrystal lcd(7,6,5,4,3,2); // this are the my UNO pins for lcd

int echoPin = 11; // ECHO PIN
int trigPin = 12; // TRIG pin
long value, cm, inches; // this are my variables long data type
long sum=0; //sum my variables long data type
long avg;
int i; // i variables for "for" loop

void setup()

{
lcd.begin(16,2); // lcd starters
lcd.setCursor(0,0); //this is my cusor position
lcd.print(" >>HC-SR04 ON<<"); // (0,0) position this data printed
lcd.setCursor(0,1); //this is my cusor position
lcd.print("________________"); // (0,1) position this data printed
delay(2000); //delay is 2000 ms
lcd.clear(); // after the 2000 ms lcd will be cleared

Serial.begin (9600); //Serial Port begin

pinMode(trigPin, OUTPUT); // TRIG pin has output pin
pinMode(echoPin, INPUT); // ECNO pin has input pin


}

void loop()

{

digitalWrite(trigPin, LOW); //starting my TRIG pin will be LOW
delayMicroseconds(5); //delay 5 Microseconds
digitalWrite(trigPin, HIGH); // after the 5 Microseconds my TRIG pin will be HIGH
delayMicroseconds(10); // again delay is 10 Microseconds
digitalWrite(trigPin, LOW); // after the 10 Microseconds my TRIG pin will be HIGH


pinMode(echoPin, INPUT); //ECHO pin is input pin
value = pulseIn(echoPin, HIGH);

// Convert the time into a distance

cm = (value/2) / 29.1; // Divide by 29.1 or multiply by 0.0343
inches = (value/2) / 74; // Divide by 74 or multiply by 0.0135
for (i=0; i<5; i++)
{
sum=sum+inches;
avg = sum/5;
}

Serial.println();
Serial.print("cm:-");
Serial.print(cm);
lcd.setCursor(0,0); // lcd position is 0th position 0th line
lcd.print("DISTANCE CM:-"); // in this position(0,0) this data prints
lcd.print(cm);



Serial.println();
Serial.print("in:-");
Serial.print(inches);
lcd.setCursor(0,1); // lcd position is 0th position 1st line
lcd.print("D.IN:"); // in this position (0,1) this data prints
lcd.print(inches);

Serial.println();
Serial.print("Avg:- ");
Serial.print(avg);
lcd.setCursor(8,1); // lcd position is 8th position 1st line
lcd.print("AVG:-"); // in this position(8,1) this data prints
lcd.print(avg);

delay(250);
}

....................................................................................................................................................................................................

circuit :-

output :-

////////////////////////////////////////////////////////////////////////////////////////////////////////

*****************************************************************************************************

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.