
The accuracy gets better at larger time scales, e.g. Time elapsed: 1786.0 microseconds, expected 10 microseconds Time elapsed: 3488.0 microseconds, expected 10 microseconds Time elapsed: 1201.0 microseconds, expected 10 microseconds Time elapsed: 3583.0 microseconds, expected 10 microseconds I verified this with the following simple code: I believe this is because of the non-pre-emptive multi-tasking OS on the pi – it’s not able to guarantee the required time-precision (10 microseconds). Arduino works fine with the equivalent code. I found that I cannot get an accurate reading on the HC-SR04 using a raspberry pi.

Print (“Measured Distance = %.1f cm” % dist) # and divide by 2, because there and back # multiply with the sonic speed (34300 cm/s) # time difference between start and arrival tup(8, GPIO.OUT) # Set pin 8 to be an output pin and set initial value to low (off) twarnings(False) # Ignore warning for now I made little changes, but it does not light up the LED when the distance is less than 50 cm. If low cost ultrasonic distance sensors aren’t effective in this environment then an optical approach using something more like what a camera uses for infrared assisted autofocus may work. Once you get something mounted cover the sensor(s) with something like polyester cushion fill and get the signal is quiet enough to make figuring out the echo signal from the hole so you aren’t measuring vibration from the engine, hydraulic system, and boom arm as much as the hole. It may or may not be necessary to do something more elaborate depending on the design details. Secure the cable in a flexible shape (a hairpin bend, an S bend, or a clock spring spiral in order of isolation and durability) to avoid transmitting vibration up the cable. One way to avoid multiple evolutions of a vibration damping scheme is to begin with a multiple step approach something like conventional rubber vibration mounts to fix an 1/8 inch thick steel plate and then a layer of cork/tar adhesive to fix a lower mass aluminum plate to secure a sensor housing. One of the key steps to making a successful sensor is going to be isolating the sensor platform from the vibration of the excavating machine. It will also add a large interfering signal to the echo return signal picked up. Make sure modules with clock circuits use a ceramic resonator not a quartz crystal. Subjecting the raspberry pi components to any significant vibration may shorten the operating life to minutes/hours/days. Everything changes when it has to operate in a vibrating environment, even the choice of solder alloy. The components aren’t made for that environment. The sensor, whether mounted on the cab or the hydraulic arm will be mounted on a platform attached to a steel structure that transmits and mechanically amplifies vibration. You may need multiple sensors to determine what’s happening at the sides of the hole to determine what’s happening at the bottom. The echo from a complex surface of stone(s), hard packed natural contour, loosened earth and material falling/fallen back into the hole will be a more complex and return from the sides of the hole will mimic a soft bottom to some extent, making it even more difficult to determine the hole depth. The echo from a hard flat surface is easy to interpret.


The sensor measures the time delay of a sonic echo returning to infer distance. Re: mount in backhoe … two significant challenges beyond mounting it somewhere it can make the measurement and, assuming that it’s not mounted on the cab, finding shielded cable with fine stranding and soft insulation that can withstand the bending at the arms joints, and a flexible plastic armor to encase it in. Here is the structure as a circuit diagram: If there would be no connection to GND, the input would be undefined if no signal is sent ( randomly 0 or 1), so ambiguous. If no pulse is sent, the signal is 0 ( through the connection with GND), else it is 1. The connection to GND is to have a obvious signal on GPIO24.

We do this because the GPIO pins only tolerate maximal 3.3V. On its end you connect it to Pin 18 (GPIO24) and through a 470Ω resistor you connect it also to Pin6 (GND). There are four pins on the ultrasound module that are connected to the Raspberry: This tutorial shows the connection and control. These small modules are available starting at 1-2 bucks and can measure the distance up to 4-5 meters by ultrasound and are suprisingly accurate. For many ( outdoor) projects a distance measurement is necessary or advantageous.
