Challenge

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

Topic: The distance of an object using ultrasonic sensor and also smoothen the sensor data using moving average filter.

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

Hardware Requirements:

  1. Arduino UNO board
  2. USB cable connecter for Arduino UNO
  3. 16X2 LCD Screen
  4. I2C Controller
  5. Ultra Sonic Sensor HC-SR04
  6. Jumper wires Male/Female

Software requirements:

  1. Arduino software(Arduino IDE)

Explanation:

The ultrasonic sensor emits a high-frequency sound pulse and calculates the distance depending upon the time taken by the echo signal to travel back after reflecting from the desired target. The speed of sound is 341 meters per second in air. After the distance is calculated, it will be displayed on the LCD display.

Circuit Connection:

Pin Configuration of ULTRASONIC SENSOR:

16X2 LCD SCREEN PIN DETAILS:

  1. LCD PIN 1-GND
  2. LCD PIN 2-VCC
  3. LCD PIN 3-VEE
  4. LCD PIN 4-RS (Register Select)
  5. LCD PIN 5-RW (Read/Write)
  6. LCD PIN 6-E (Enable)
  7. LCD PIN 7 to PIN 14-Data Bits
  8. LCD PIN 15-LED Positive
  9. LCD PIN 16-LED Negative

CODING:

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

#define trigPin 9 //Sensor trig pin connected to Arduino pin 9

#define echoPin 8 //Sensor echo pin connected to Arduino pin 8

void setup()

{

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

lcd.begin();

lcd.backlight();

lcd.clear();

lcd.setCursor(4,0);

lcd.print("Skill Lync");

delay(1500);

lcd.setCursor(0,0); //Set LCD cursor to column 0, row 0

lcd.print("Target Distance:"); //Print the Message on First Row

}

void loop()

{

long duration, distance; // Initialize duration and distance

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration/2) / 29.1;

lcd.setCursor(0,1); //Set cursor to first column of second row

lcd.print(" "); //Print blanks to clear the row

lcd.setCursor(0,1); //Set Cursor again to first column of second row

lcd.print(distance); //Print measured distance

lcd.print(" cm"); //Print units.

delay(300); //pause to let things settle

}

OUTPUT:

Experimental setup:

Experimental setup-switched ON:

:

Measured distance-6cm:

Measured distance-9cm:

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.