Distance Sensing in a Compact Space

Hello there buccaneers!
I’ve been messing around with the Explorer pHat and one of the small Pololu track sets and I was wondering if anybody has any suggestions for a small, compact sensor I could use in order to do a little distance sensing?

I’ve tried using a HC-SR04 ultrasonic sensor, but I seem to be running into the same problem as this thread here where it doesn’t actually seem to give me any values at all (when running on battery power that is. I’m yet to try it actually using a power supply). I tried this by using the second piece of code found here. (thanks to ColinD!)
It was also mentioned in that thread about using this IR sensor, but I would have preferred to use a sensor from Pimoroni if possible ;)

So, any ideas? This sensor here seems to fulfil what I want it to do, but the support is mostly Arduino based, and being terrible at electronics in general as I am, figuring out which pins go where is a problem. It took me long enough to figure it out for the HC-SR04 and it only had four pins… Clearly labelled at that!

Thanks for all the help!

Hi Picard,
The IR sensors from Sharp are awesome+ . They’ve become my go-to sensor of choice now.

The Time of Flight (ToF) sensor states that only a narrow angle is covered. While good for a digital tape measure or a trip wire this would be less good for a robot where a little bit more of a cone is desirable for when an object is not dead-set in front of the sensor. Of course one solution is to then mount it to a stepping motor and “scan” back and forth. Yes, you’re re-inventing KITT so I expect a suitable “swooshy” noise to be played as well :)

The ToF’s minimum distance of ~30mm-50mm is comparable to my Sharp IR sensor (~40mm): remember to code some error handling code for the blindspot this creates! I’m also adding microswitch bumpers to my bot for impact scenarios not covered by the IR sensor.

With the Sharp IR sensor you can pick them up for about £3-£4 via eBay so they’re definitely worth a punt though:)

If you do go with the ToF please do post your results with it. I’m very interested in these sensors for various applications.


1 Like

Thanks Colin,
I’ll probably order a Sharp IR distance sensor just to try out anyway. I’m running out of space on this chassis so the “swooshing” may have to wait. :)
The small cone would certainly be a problem, although I could mount two at either side and use a little mathematics to guess whether there’s something dead centre, but that would be taking up even more precious space. Despite that, I might end up making a larger chassis myself out of some spare wood I have laying around and use one of those sensors as a sort of radar system mounted on a stepper motor to “scan” the environment. Could be interesting for some more automated abilities.
I’ll certainly keep you informed with how things go along with some pictures of any new chassis I come up with.
Time for some SketchUp drawing!