I was wondering if I connect a HC-SR04 to an Arduino or any other microcontroller by normal cables, what would be the maximum length of this cable so that the measurements will still be true, and not affected by the length of this cable?
this problem consists of 2 things :
- supply level drop (this one has severe effect)
- signal level drop (a little more forgiving)
as the signals on the cables don't have high frequencies, the problem narrows down to just voltage level drop due to cable resistance.
supply level drop: the datasheet for SR04 says a maximum active current of 20mA is required for device to work properly. the supply voltage is 4.5~5.5v. so if you provide a 5v power for it, the cable must not drop it under 4.5v. the maximum resistance for the cable is calculated
R=V/I => R = (0.5/20)*10^3 = 25 Ohms
. you can use this value to find out maximum cable length using resistance tables provided by cable makers. e.g. if you have bought a 5ohms/meter cable, the maximum length should be under 5 meters to ensure a good power delivery.
the signals on the other hand, have very little current going between them. as the MCU/Module pins have a very high input impedance. so they are not as severe as the supply drop.
using a 100uF cap near SR04's supply pins would be great.
I have a couple measuring the liquid level of two tanks.
The units are distanced from the microcontroller by 12' of 18ga solid-core copper cable.
Testing was done with another microcontroller with the sensor attached by 6" cable to ensure accurate readings.
That's the longest I needed, so I haven't tested beyond that.