Challenge

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:

  1. Measuring the distance of an object using an ultrasonic distance sensor (28015 Ping).
  2. Implementing a moving average filter to smooth out the distance data, reducing noise and high-frequency variations.

Goals

  1. Measure the distance to an object in inches using the Ultrasonic Distance Sensor (28015 Ping).
  2. Apply a moving average filter to the measured distance values to eliminate high-frequency noise, providing more stable and reliable distance measurements.

Key Highlights

  1. 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.
  2. 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

  1. 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 last FILTER_SIZE measurements.
    • The smoothed data is sent to the master upon request via I2C.
  2. Master Node:

    • The master requests data from the slave every second.
    • The received data is printed via serial for monitoring.
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.