Project 2 - Measuring the distance of an object using ultrasonic sensor and also smoothen the sensor data using moving average filter
OFFLINE BATCH
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 :
//MASTER ARDUINO
//I2C Communication between two arduino
//library for I2C communication function
#include <Wire.h>
//library for LCD display
#include <LiquidCrystal.h>
//Define LCD module pins
LiquidCrystal lcd_1(12, 11, 5, 4, 3, 2);
void setup()
{
//Begin I2C communication at A4,A5
Wire.begin();
//Begin Serial communication at 9600 band rate
Serial.begin(9600);
}
void loop()
{
//request 1 byte from slave arduino(2)
Wire.requestFrom(2,2);
//receive a byte from the slave arduino and store in masterReceived
byte CMReceive = Wire.read();
//read analog value from value
lcd_1.begin(16,2);
//set cursor at line one in LCD
lcd_1.setCursor(0, 0);
//print master ate LCD
lcd_1.print("DIS IN CM");
lcd_1.setCursor(6,1);
//print master received in LCD received from slave
lcd_1.print(CMReceive);
// Wait for 1000 millisecond(s)
delay(1000);
//receive a byte from the slave arduino and store in masterReceived
byte INCHReceive = Wire.read();
//read analog value from value
lcd_1.begin(16,2);
//set cursor at line one in LCD
lcd_1.setCursor(0,0);
//print in serial monitor
lcd_1.println("DIS IN INCH");
lcd_1.setCursor(6,1);
//print master received in LCD received from slave
lcd_1.print(INCHReceive);
//print the changing vlaue of temperature sensor
Serial.println(CMReceive);
//print the changing vlaue of temperature sensor
Serial.println(INCHReceive);
// Wait for 1000 millisecond(s)
delay(1000);
}
//SLAVE ARDUINO
//I2C Communication between two arduino
//library for I2C communication function
#include<Wire.h>
int Master =0 ;
int Slave = 0;
int duration =0;
void setup()
{
pinMode(11,INPUT);
pinMode(12,OUTPUT);
//Begin Serial communication at 9600 band rate
Serial.begin(9600);
//Begin I2C communication at A4,A5
Wire.begin(2);
//Function call when master request value from slave
Wire.onRequest(requestEvent);
}
void loop()
{
}
//This function is called when master wants value from slave
void requestEvent ()
{
digitalWrite(12, LOW);
delayMicroseconds(2);
digitalWrite(12, HIGH);
delayMicroseconds(10);
digitalWrite(12, LOW);
duration = pulseIn(11, HIGH); // it will find the duration of ultrosonic wave
Master = 0.01723 * duration;// formula to convert the cm
Wire.write(Master);//write the value in wire
Slave = (Master / 2.54); //formula for inch conversion
Wire.write(Slave);//write the value in wire
}
OUTPUT :
DIS IN CM : 198
DIS IN INCH : 77