I am using code similar to what’s shown above to measure the distance away that objects are as they pass by my sensor (HC-SR04 ultrasonic sensor). The code, sensor, and measurements are great so long as there is an object there to measure. If there is open space in front of the sensor it begins to throw random numbers of distance.
I believe the datasheet for this sensor claims to be good to approx. 16 ft. If I wanted to stop the pulseIn function after the distance surpassed say 14 ft, to be safe. How might I do that and return an out of range error or something similar, instead of random numbers that are misleading to my project?
I will say I am only two weeks into learning about the Particle Photon and have no other experience with Arduino’s or any of the likes.
Thanks for any guidance.