Challenge

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

PRoject Measuring the distance of an object using ultrasonic sensor and also smoothen the sensor data using moving average filter:

int a[4];

void setup()

{

 Float sum;

Float average;  // initializing varibles//

  Serial.begin(9600);

}

void loop()

{

   for (int i=0;i<5;i++)

  {

   pinMode(4,OUTPUT);   //pinmode setup//

  digitalWrite(4,LOW);  // sensor putting off condition//

  delay(1);

  digitalWrite(4,HIGH);  //sensor putting on condition//

  delay(1);

  digitalWrite(4,LOW);

   pinMode(4,INPUT);

   a[i] =pulseIn(4,HIGH);   //releasing the pulses//

  Serial.println (a[i]);

  }

   for (int i=0;i<5;i++)

  {

    sum=a[i]+sum;

  }

  Serial.println(sum);

  average=(sum/5);   // average the values//

  delay(10);

  int inches= t(average);  //calculating the distance//

  int centimeters= c(average);

  Serial.println(inches);

  delay(1000);

  Serial.println(centimeters);

  delay(1000);

}

int t(int time)

{

  time= (time/74);    // calculating time//

  return time/2;

}

int c(int time)

{

  time= (time/29);

  return time/2;

}

 Link details:   https://www.tinkercad.com/things/4eWMOoXvZ25-brave-sango/editel?sharecode=n9GMZbxL1KVZBxVTjiosEo0CSOOxrLgLqZkcK0vgpIA

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.