Challenge

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

Code for this Project is:

int inches = 0;
#define SAMPLESIZE 10
const int UL_PIN = 7;

int INDEX = 0;
int VALUE = 0;
int SUM = 0;
int avg[SAMPLESIZE];
int AVERAGE = 0;
int cm = 0;


void setup()
{
Serial.begin(9600);

}

void loop()
{
pinMode(UL_PIN, OUTPUT);
digitalWrite(UL_PIN, LOW);
delayMicroseconds(2);
digitalWrite(UL_PIN, HIGH);
delayMicroseconds(5);
digitalWrite(UL_PIN, LOW);
SUM = SUM - avg[INDEX];
VALUE = analogRead(UL_PIN);SUM = SUM+VALUE;
INDEX = (INDEX+1)%SAMPLESIZE;
AVERAGE = SUM / SAMPLESIZE;
Serial.print(VALUE);
Serial.print(",");
Serial.println(AVERAGE);
delay(5);

}

Explaination:

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

The PING))) sensor detects objects by emitting a short ultrasonic burst and then "listening" for the echo. Under control of a host microcontroller (trigger pulse), the sensor emits a short 40 kHz (ultrasonic) burst. This burst travels through the air, hits an object and then bounces back to the sensor. The PING))) sensor provides an output pulse to the host that will terminate when the echo is detected, hence the width of this pulse corresponds to the distance to the target.

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.