Project 2 - Measuring the distance of an object using ultrasonic sensor and also smoothen the sensor data using moving average filter
Answer: Project:2-
Overview
This project involves:
- Measuring the distance of an object using an ultrasonic distance sensor (28015 Ping).
- Implementing a moving average filter to smooth out the distance data, reducing noise and high-frequency variations.
Goals
- Measure the distance to an object in inches using the Ultrasonic Distance Sensor (28015 Ping).
- Apply a moving average filter to the measured distance values to eliminate high-frequency noise, providing more stable and reliable distance measurements.
Key Highlights
- Ultrasonic Distance Measurement:
- The sensor emits an ultrasonic pulse that bounces back from an object.
- The time taken for the pulse to travel to the object and return is used to calculate the distance.
- Data Smoothing with Moving Average Filter:
- The moving average filter smooths the sensor data by averaging a set number of previous readings.
- The filter window determines how many data points are averaged, which affects the level of smoothing.
Deliverables
- A program that measures the distance of an object using an ultrasonic distance sensor.
- A moving average filter implementation to smooth the sensor data, reducing high-frequency jitters.
Expected Outcomes
- Students will gain knowledge about using the Ultrasonic Sensor (28015 Ping) to measure distance.
- Understanding of hardware connections involving Arduino and ultrasonic sensors.
- Practical experience in implementing and applying the Moving Average Filter Technique to remove noise from sensor data.
Arduino Code Implementation
Requirements
- Hardware: 2 Arduino boards (1 as master, 1 as slave), an ultrasonic sensor (28015 Ping), and connecting wires.
- Software: Arduino IDE.
Code Description
- The ultrasonic sensor is used to measure distance.
- The distance data is then smoothed using a moving average filter.
Explanation
Slave Node:
- The ultrasonic sensor measures the distance by emitting a pulse and timing its return.
- The
measureDistance()function calculates the distance in inches. - The
movingAverage()function smooths the data by averaging the lastFILTER_SIZEmeasurements. - The smoothed data is sent to the master upon request via I2C.
Master Node:
- The master requests data from the slave every second.
- The received data is printed via serial for monitoring.