Get analog voltage

Hello everyone,

I just got a new sensor (ultrasonic) which turns distance output as voltage, depending on how far the obstacle is. Output voltage gets to 0-10V, but since Im using voltage divider 2 times, I get 0-5V. The problem is I cannot read analog voltage correctly, mismatch information with my multi-meter. I wonder if you have any idea what could be wrong. Im using arduino mega, on top of that is motor shield (for my project). Wtih dc/dc converter I get from 5V to 24V as input. My multimeter gets stable results as I move the obstacle, futher voltage gets bigger and the other way. If it gets out of range, or too close, it gets max output (5V). Arduino debbug output shows pretty much random numbers, not even close with what multimeter shows, stable data, depending on range.

What I tried to do is here: https://www.arduino.cc/en/Tutorial/ReadAnalogVoltage
Sensor: Sensor link

Hi, Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you post your code as well. Are you using some test code for the sensor?

Thanks.. Tom... :)

Hi!

If you have the multimeter wired in parallel with the analogue pin and Arduino gnd and the Arduino is showing results which loosely line up with a reliable multimeter, that tells me that your calculations within the sketch aren't right.

So, go back a step... Comment out the voltage part of the sketch so that you get the raw 0-1023 values. Then, make the sensor read full 5v and check, then get it to output 0v and check... Then check half way. The raw values should correspond to a voltage on the multimeter.

If it works, your voltage calcs weren't right. Re do them differently.

If it still doesn't work, then that indicates to me that either the Arduino or the multimeter is faulty (or innaccurate) because a potential difference between two points IS that EXACT potential difference at that exact moment in time. A voltage can't be two different values at the same time.

Antony...

antonyc:
Hi!

If you have the multimeter wired in parallel with the analogue pin and Arduino gnd and the Arduino is showing results which loosely line up with a reliable multimeter, that tells me that your calculations within the sketch aren’t right.

So, go back a step… Comment out the voltage part of the sketch so that you get the raw 0-1023 values. Then, make the sensor read full 5v and check, then get it to output 0v and check… Then check half way. The raw values should correspond to a voltage on the multimeter.

If it works, your voltage calcs weren’t right. Re do them differently.

If it still doesn’t work, then that indicates to me that either the Arduino or the multimeter is faulty (or innaccurate) because a potential difference between two points IS that EXACT potential difference at that exact moment in time. A voltage can’t be two different values at the same time.

Antony…

I thought of that but still there is one question. If the math is wrong ok I can fix it, but how come that I get totally random values, at least shouldn’t it be stable? As the multi-meter is stable.

Value example: 0.00
1.32
3.91
3.83
0.00
3.89
3.83
1.29
2.22
3.90
0.96
1.32
5.00
1.28
1.31
3.93
3.88
And so on…

TomGeorge:
Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you post your code as well.
Are you using some test code for the sensor?

Thanks… Tom… :slight_smile:

I made it with paint, don’t mind my paint skills :smiley:
https://ibb.co/mEs90a

Hi, Arduino gnd needs to be connected to -Ub. The output of the sensor is with respect to -Ub, so you have to have the gnd of your Arduino, which the analog input measures with respect to, connected to the -Ub as well.

Tom.... :)

Hi, Please post your images/files as attachments please, off site images can be hard for some users who do not use laptop or PC platforms

Tom..... :) .

TomGeorge: Hi, Arduino gnd needs to be connected to -Ub. The output of the sensor is with respect to -Ub, so you have to have the gnd of your Arduino, which the analog input measures with respect to, connected to the -Ub as well.

Tom.... :)

Thank you! Now it works just fine.

About the images tho, I did uploaded as image URL, but the image didn't showed so I edited it just with link.