4050 digital distance sensor on a long wire

Hello! I’m using the Digital Distance Sensor (#4050) to sense trains, putting them under the track looking up between ties. Perfect, however…

I’m using 30 gauge wire, about 15 feet at the longest, to the Pi over in the corner. Some of the sensors (2 of 8) don’t seem to like that, but I have found that if I put a capacitor across power and ground at the sensor, it might work better (0.1 uF no, 10 uF maybe).

It is possible my options are (1) bigger wire, or (2) capacitors at each sensor. I like #2 better.

Question: is it possible to say what an appropriate capacitance would be? I’m not a fan of “see what works”, but maybe that’s the answer. I did not see a schematic for this sensor to see what’s already there at power input to the board.

I’m running them at 3.3V. The DC level at the sensor Vin looks fine when it’s not working, where “not working” means connecting power and ground only, looking at the red light on the back. Another detail, when it’s not working the DC voltage on the output is about 15 mV below the voltage on Vin (and when it’s working, they are the same). Odd. I have not scoped the power input with/without added capacitance.



These sensors tend to draw current in bursts, and adding a capacitor across power and ground right at the sensor should help prevent the input voltage from dropping during those burst. I recommend at least 10uF. You can look at the input voltage with your scope to see the effect of different capacitor sizes.


Thank you, Claire. I’ll probably do some measurements in the next week or two and see how much seems to be enough. I have one more that “doesn’t work” (no cap yet), but the rest are probably on the edge.

Hello again. It looks like it’s not the “run time” powering of the sensor, but there’s something at power up that glitches power pretty good 20 msec after power comes up. When it is not working, the glitch appears every 20 msec, like it’s continuously brown-out rebooting maybe. If I put a cap on it to let it boot, I can then pull the cap and it continues working, pointing at just boot time being the problem.

I’m testing with “short wires” (breadboard jumpers) vs. “long wires” (12’ of awg 30 between regulator and module), scope at the module. With short wires, the power up dip is ~80mV. With long wires and no cap, it’s about 700mV, down to ~2.5V in my case. 10uF is almost enough; it dips to ~2.65V and one sample works and another doesn’t. 47uF keeps it above 3V (200mV dip). I’ll probably go with 100uF (still dips ~150mv, to 3.1V).

Thanks for following up and letting us know what you found!