Challenge

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

/* P2: Measure Distance using Ultrasonic Distance Sensor *//

// Master code

#include

#include

LiquidCrystal lcd(2,3,4,5,6,7);

int Distance;

void setup()

{

Wire.begin();

Serial.begin(9600);

}

void loop()

{

Wire.requestFrom(8,1);

Distance=Wire.read();

lcd.setCursor(0,0);

lcd.print("Distace= ");

lcd.print(Distance);

lcd.print("inch");

Serial.println(Distance);

delay(50);

Wire.end();

}

//* P2: Measure Distance using Ultrasonic Distance Sensor *//

// Slave Code

#include

#include

int Signal=2;

LiquidCrystal lcd(2,3,4,5,6,7);

int Value,Duration;

void setup()

{

Wire.begin(8);

Serial.begin(9600);

Wire.onRequest(Distance);

}

void loop()

{

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.