Challenge

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

Aim :

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.

Components:

Arduino UNO.

Ultrasonic sensor.

Resistor.

LCD 16*2

.

Circuit explaination, connection:

as shown above, pin 7 used for signal pin for ultrasoinc sensor, 

Display data pins tfrom 2 to 5. RS, E to 11,10.

Ultra sonic connected to +5, GND pins, also to LCD display.

Code: 

#include

LiquidCrystal lcd(11,10,5,4,3,2);
int a=0;
int CM=0;
int INCH=0;

void setup()
{
Serial.begin(9600); // begin the serial communication
lcd.begin(16,2); // define the values of LCD as 16*2
}

void loop() //Inititate the loop
{

pinMode(7,OUTPUT); // defin the pin as OUTPUT
digitalWrite(7,HIGH); // send the singal
delayMicroseconds(2); // wait for 2 micros seconds
digitalWrite(7,LOW); // set the signal to 0
pinMode(7,INPUT); // change the pin to INPUT to sens the signal
a =pulseIn(7,HIGH); // if once the pulse came in count the time
CM=0.01723 *a; // by the delay of time reiieved multiply by constant 0.01723
INCH= CM/2.54; // convert to INCH
Serial.println(INCH); // print the values in serial monitor
Serial.println(CM);
lcd.setCursor(0,0); // set cursor and print the CM, INCH
lcd.print("Dist in CM : ");
lcd.print(CM);
lcd.setCursor(0,1);
lcd.print("Dist in IN : ");
lcd.print(INCH);


}

https://www.tinkercad.com/things/jsDT7t0R8su-fantabulous-wolt-blad/editel?sharecode=F5yUmB_kkl4jA6NXAq51rlSilWc0vvA-EkzKsxagfT4

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.