I'm a newbie at Arduino, and I'm trying to make a project with ultrasonic sensor, I'm using the grove ultrasonic ranger, not the HC-SR04, and I already did test with distance and it worked very well, but now I need help with the code.
I need to create a vector that save the values of the distance to after calculate the speed using distance/time calculus, but the case of my project its to use in open places, so will be times that the distance will be "max" because there's nobody in the range, so I need a condition to exclude those values of the array (the maximum distance printed when the sensor can't feel nothing is 516 cm)
I'm not experienced with Arduino coding, so please help me, in anex is my code for basic scanning.
#include "Ultrasonic.h"
Ultrasonic ultrasonic(7);
void setup()
{
Serial.begin(9600);
}
void loop()
{
long RangeInCentimeters;
Serial.println("The distance to obstacles in front is: ");
// two measurements should keep an interval
RangeInCentimeters = ultrasonic.MeasureInCentimeters();
if(RangeInCentimeters > 400)
Serial.print ("distancia nula");
else
Serial.print(RangeInCentimeters);//0~400cm
Serial.println(" cm");
delay(1000);
}