 # how to measure a voltage

Hi everyone !!

I urgently need your help :) My question is very simple: how to measure a voltage across a resistance with an arduino?

At the moment I am using a voltage divider bridge with this formula : voltage=value*(5/1023) where "value" is what is measured by the analog pin A0. The problem is that I get false voltages !! (In my case R1 = 10 kohm, R2 = 13 kohm, I'm supposed to get U2 = 2,82V and I get U2 = 1,92V).

Here is my code.

thank you very much for your help !! ;)

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

void loop() { int valeur = analogRead(A0); // Mesure la tension sur la broche A0 float tension = valeur * (5.0 / 1023.0); // Transforme la mesure (nombre entier) en tension via un produit en croix Serial.println(tension); delay(3000); }

Is your 5v really 5v (and not 4.5v or even a 3.3v Arduino) ?

Are your resistors the right way round (10K to 5v, 13k to ground) ?

Can you measure the middle of the resistors with a meter ?

Yours,
TonyWilk

5V------/\/\/----- -+------/\/\/------GND 10k | 13k 2.83V

``````float aRef = 4.98; // your Vcc measured with DMM
float volts;
volts = analogRead(aInPin) * aRef / 1024;
Serial.println(volts);
delay(1000);
``````

EDIT: WHOOPS :confused:

cestpasfaut: Hi everyone !!

I urgently need your help :) My question is very simple: how to measure a voltage across a resistance with an arduino?

Your approach is fine, assuming the 10k goes to +5V and the 13k to ground, you must have some detail wrong - for instance have you checked:

The 5V rail is really a stable 5.0V? The 10k resistor is really 10k? The 13k resistor is really 13k? All the connections are sound? Nothing else is connected to the analog pin that could be affecting it? That there is no interference such as RFI coming into the circuit and perturbing it.

cestpasfaut: voltage=value*(5/1023) where "value" is what is measured by the analog pin A0. The problem is that I get false voltages !!

Not that it matters for most things, but many ADC's divide the voltage range into equal buckets, so that the ideal formula would be `5.0 * (value + 0.5)/1024` - returning the centre voltage for the bucket.