Challenge

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

int centimeter=0;
int inches=0;

long distance(int triggerPin,int echoPin)
{
pinMode(triggerPin,OUTPUT);
digitalWrite(triggerPin,LOW);
delayMicroseconds(2);
digitalWrite(triggerPin,HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin,LOW);
pinMode(echoPin,INPUT);

return pulseIn(echoPin,HIGH);
}

void setup()
{
Serial.begin(9600);
}

void loop()
{
centimeter=0.01723*distance(8,7);
inches=(centimeter/2.54);
Serial.print(inches);
Serial.print(" in ; \n");

delay(1000);

}

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.