Ultrasonic range finder simple code

Yeah, so here’s the code for my ping sensor project.

I’ve even got some sensor reading smoothing in there since this sensor is a bit temperamental. The functions you should check out are avgReading(), readPingSensor(), ping(), microsecondsToInches() and microsecondsToCentimeteres()

This code started out from @BDub’s work from this thread: Simple Photon Ping Sensor (HC-SR04)

3 Likes