Can't correctly get the analogRead value

Hello everyone, I'm a Rookie. I use the Analog pin to get the analog input.
the voltage between the two cables is 2.2V. But when I use the analogRead(), I can't get the value, I can't figure out it.
Thanks in advance for the help.
the Pictures are below:

For a 2.2 V, the result of the analogRead(A1) should be around 450 and 451. Take 5 V / 1024. And Take 2.2 V / ( 5 / 1024 ) equal 450.56. So it will be 450 or 451. For an UNO board.

Did you check the analogRead() - Arduino Reference for analogRead.

In your code, your analog result a is a float, it should be an Integer.

To display a voltage, you need to convert the integer data from the analogRead into a voltage value. For an UNO, Take 5 V divide by 1024. That is the resolution. So you take the reading from the analogRead(A1) multiply by the resolution ( 5/1024) equal the voltage. In Theory.

In practice, the measure point may be different, not the expect 2.2 V, double check with a voltmeter, measure the actual voltage, do the calculations and should get the integer data value for the analogRead(A1)

int analogPin = A3; // potentiometer wiper (middle terminal) connected to analog pin 3
                    // outside leads to ground and +5V
int val = 0;  // variable to store the value read

void setup() {
  Serial.begin(9600);           //  setup serial
}

void loop() {
  val = analogRead(analogPin);  // read the input pin
  Serial.println(val);          // debug value
}
1 Like

Arduino analog input can't read differential value between two signals, only between one signal and ground.
So you have two options - ether connect wire with lowest signal to arduino's GND terminal, or measure both signals relative GND and then calculate the difference in the code

1 Like

Hi, @fernweh1zz
Welcome to the forum.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, component names and pin labels.

What are the sources of your 2.2V differential?
Can you please post your code?

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:

This is a youtube tutorial showing how to produce schematics using Fritzing

Thanks for the answer. the Grey cable is from the GND of the SOC Monitor and is already connected to the GND of Arduino.

Thanks for the help. but I have tried to use another 5V potentiometer with the same code to get the analog input, and it works.

Hello, Tom. the circuit and code are below:


`void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
float a;
a=analogRead(A1);
Serial.println(a);
delay(1000);
}`

And I have tried to use another 5V potentiometer with the same code to get the analog input, and it works.

I don't know why in this case it doesn't work.

Best regards

Hi,
To add code please click this link;

Tom... :smiley: :+1: :coffee: :australia:

Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, component names and pin labels.

The image does not show pin numbers or component names.
What is the device in the top right and what are the wires in the protoboard on the bottom right?

What model Arduino are you using and do you need the shield on it at the moment.

Do you have a DMM?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

analogRead() read an integer value, not a float value.

1 Like

To me, it looks so far, like you are treating the Arduino ground as if it is floating. But actually all your devices may have their grounds connected via power supplies and/or the PC. That would effectively short one of the terminals that you are taking a differential reading from - thus it is no longer differential, instead reading the voltage referenced to ground on the other terminal.

It's a familiar (noob) problem with oscilloscope users too. They have to learn to use two probes with ADD and INVERT selected to make a true differential reading, separate from chassis ground.

But I completely agree, such a specific circuit question needs a schematic.

Thanks for the answer.

below the picture is the schematic of the SOC Monitor.
I connect the PIN1 gnd terminal to the gnd of Arduino UNO, and PIN6 to analogPin1. it can't get the correct analog Input.

Hi, @fernweh1zz

Sorry we need a schematic, that is the PCB pattern.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, component names and pin labels.
Not just the components on the PCB but the external components such as power supplies.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

You're welcome. Did you try implementing my suggestion? It was first explained also in reply #3. It's not clear whether you had the ground offset problem mentioned there, or whether or not you made the changes in your measurements mentioned in both posts.

Because, you didn't provide any feedback on either suggestion.

In reply #13, your verbal indication of connections indicates that you have not implemented these suggestions.

You should either try it, or provide a diagram showing how the test is configured, proving that the Arduino ground is not shorting one of your measurement points.

Without any acknowledgement or rebuttal, it displays indifference to suggestions, which will discourage people from offering any.

1 Like

The Analog read in post #1 is correct for a 3V3 system.

Have you wanted to mean that -- ?
analogRead() returns an integer value (0 - 1023 = 0x0000 - 0x03FF) on Arduinos with a 10 bit ADC. //edit

On Arduinos with a 10 bit ADC.

1 Like

Hmmm. I wonder what system the OP has?

We'll never know as it's a sooper secret along with the model # of the SoC Monitor and a schematic of the system.

1 Like