Ultrasonic Sensor Coding

Good day,

The ultrasonic sensor i used can now read signals, what i want to happen is like a sort of calibration, wherein the first distance that was measured by the sensor when turned on is its base distance wherein i can make the codes +- distance for changing of slopes. Specifically the sensor is used for detecting whether the road is going up or down etc and we all know that people have different height, so i need to make this sort of calibration. Recording the first distance and setting it as its base distance and then +- distance for changes of slope. Thank you so much in advance for the help, if my question was not to clear please feel free to ask. Thanks

For best accuracy in your "base" value measurement, maybe you could add a pushbutton, "Zero".

When the "Zero" button is pressed, the 'ping' sensor takes a series of measurements, averages the values, then stores the result as a "base" value.
That would also allow you to set the "base" value at any time, without having to unpower/re-power the Arduino.

If you're using the "NewPing" library, the averaging can be done automatically by using the 'ping.median()' member function.

Are you using "NewPing"?

Are you sure this will work for what you want though. The range is very limited, so you can't 'ping' a very high distance for measuring the slope of a road, plus the 'ping' sensor really needs a reflection from an object at 90 degrees to the sensing direction to work well. And if the 'road' slopes down away from the sensor, a ping may not be returned at all.

No I'm not using NewPing but i could atleast study the codes of newping and give it a try. Thanks for the suggestion. Specifically i'm using the ultrasonic sensor codes for measuring distance and then an if else statement to play an audio. the audio comes from a player and will be transmitted to earphones.

roldsalamat:
No I'm not using NewPing but i could atleast study the codes of newping and give it a try. Thanks for the suggestion. Specifically i'm using the ultrasonic sensor codes for measuring distance and then an if else statement to play an audio. the audio comes from a player and will be transmitted to earphones.

Where does the "base" value and road slope stuff come into it?

Specifically sir, when the sensor turns on the first distance it detected is its base distance, wherein that is the height of the wearer. And then if the slope goes up, the distance will decrease. The base is the first distance detected of the sensor therefore the machine can be used by other person with different heights.

Is it possible that i will put the codes in the void setup and then save that distance and then the +- on the void loop, is it possible that way? so that i will run only once and then save that variable

roldsalamat:
Is it possible that i will put the codes in the void setup and then save that distance and then the +- on the void loop, is it possible that way? so that i will run only once and then save that variable

Yes. That's what 'setup()' is for - stuff that only happens once, at the beginning of the program.