2

my Problem is, that I get random values from my ultra sonic sensor if my arduino is connected to any external power supply (vin port 30) on my arduino nano.

If I power up from the laptop usb port, I get consistent values.

I have tested 3 different power supplies between 7-17V and up to 2000mA. I have tested this on 2 different nano boards. Also tested with an extra 2000uF capacitor between vin and gnd

pls help if you got an idea :)

5
  • What voltage are you reading on a +5 pin? (Ie "pin 27" in your 30-pin numbering scheme, or pin 6 on the ICSP header.) Also, what model of ultrasonic sensor do you have, and which sketch is running? And do some other sketches seem to work ok with external power? Nov 1, 2015 at 23:43
  • I got the HC-SR04 Ultrasonic Sensor and the basic demo code. I found the solution see below. Thanks for your comment anyway :) Nov 1, 2015 at 23:59
  • I've been facing this problems as well. Different readings with different power supplies. In fact, i get wrong readings with a good 5v 2A power supply, but get good reading with a cheap 5v 1 A power supply. Not sure why this is happening. Similar results with ultrasonic library mentioned above as well.
    – user70295
    Nov 21, 2020 at 10:42
  • as I wrote above, this seems to be a floating ground thing. On the good supply the mains ground is routed through to the arduino (-) ground so it is not floating. I would have expected to get invaild readings in floating condition, but it seems to be the other way around. On pc USB you also have proper ground and you also get invalid results with newPing. Nov 22, 2020 at 16:13
  • I was running into this issue as well. For me I was plugged in via USB to my computer, and i had my breadboard powering the sonic sensor through a 30v lab supply tuned to 5.02v.(5v at the other end of the meter). I solved my spurious ranging by "giving" the 5V back to my arduino by plugging my lab bench supply and the 5v pin on the arduino to the same rail. Feb 17 at 23:29

1 Answer 1

3

So i tried to used a stable 5V input on the 5V input pin and got the same more or less random values (jumping all around... especially on targets more than 1m away)

So I changed form newPing lib (http://forum.arduino.cc/index.php?topic=37712.0) to Ultrasonic lib (http://forum.arduino.cc/index.php?topic=37712.0).

Now the values are correct on each power supply and even more accurate on high distance than with newPing on USB power supply.

Don't know whats broken with the newPing v1.7 lib -.- but this works!

3
  • Glad the library helped. I think perhaps the problem had to do with reference voltages. If you are using two supplies, you need to make sure they are grounded together very well. One library could stand the different voltages and the other couldn't. But the key to using two power supplies for anything is to make sure they are grounded together.
    – SDsolar
    May 29, 2017 at 3:22
  • Is it possible that one library reports instantaneous values, and the other uses averaging? Or even if both use averaging, that one is synchronous with 60Hz mains?
    – Boggyman
    Nov 21, 2020 at 14:07
  • the arduino side (dc) don't has access to the mains frequency (ac), so I don't think this is the difference. The only obvious difference seems to be the ground level as @SDsolar wrote below. I don't have access to my setup anymore but you could test this by temp connecting main ground to the arduino gnd and see if the values change. Nov 22, 2020 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.