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.4
Ultrasonic Sensor
CODE
#include
#define trigger 9
#define echo 10
LiquidCrystal lcd(7,6,5,4,3,2);
float time=0,duration=0;
long sum=0;
long avg,inches=0;
void setup()
{
Serial.begin (9600);
lcd.begin(16,2);
pinMode(trigger,OUTPUT);
pinMode(echo,INPUT);
lcd.print(" Ultra sonic");
lcd.setCursor(0,1);
lcd.print("Distance Meter");
delay(2000);
lcd.clear();
}
void loop()
{
digitalWrite(trigger,LOW);
delayMicroseconds(2);
digitalWrite(trigger,HIGH);
delayMicroseconds(10);
digitalWrite(trigger,LOW);
delayMicroseconds(2);
time=pulseIn(echo,HIGH);
duration=(time/2)/29;
inches = (duration/2) / 74; // Divide by 74 or multiply by 0.0135
for (int i=0; i<5; i++)
{
sum=sum+inches;
avg = sum/5;
}
lcd.clear();
lcd.print("Distance:");
lcd.print(duration);
lcd.print("cm");
lcd.setCursor(0,1);
lcd.print("Average:");
lcd.print(avg);
//Serial.print(avg);
//Serial.print("Avg, ");
//Serial.print(duration);
//Serial.print("cm");
//Serial.println();
//Serial.print(inches);
//Serial.print("in");
//Serial.println();
delay(250);
}
CIRCUIT DIAGRAM

OUTPUT

