Go Down

Topic: [SOLVED] Analog read from PSU is higher than actual value (Read 620 times) previous topic - next topic

Bjerknez

I'm going to make an 12V battery voltage tester with Wemos D1 and i have used Voltage dividers and connected to A0 input.

All works fine and measurements is almost spot on, when i measure batteries. I have measured 1x AA battery and it's almost spot on. I have measured 9V battery and this is the same. almost spot on. Or good enough.

But when i connect my adjustable bench power Supply and set it to lets say 12V. i see the serial gives me 0.3 - 0.4V more voltage than the PSU is adjusted to.

I have measured with multimeter on batteries and PSU and all is almost spot on, but NOT the readings from the PSU.

Why is my PSU readings 0.3 - 0.4V higher than the PSU is adjusted for?

Here is my code by the way:

Code: [Select]
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

int vPin = A0;
int LED_1 = 5;
float realVoltage;

char auth[] = "*******";

char ssid[] = "*******";
char pass[] = "*******";

BlynkTimer timer;

void setup() {
  Blynk.begin(auth, ssid, pass);
  Serial.begin(9600);
  pinMode(vPin, INPUT);
  pinMode(LED_1, OUTPUT);
  timer.setInterval(100L, readVoltage);
  timer.setInterval(100L, ledBar);
}

void readVoltage(){
  int voltageValue = analogRead(vPin);
  realVoltage = (14.7/1023)*voltageValue;

  if(realVoltage < 1){
  Blynk.virtualWrite(V1, "0.00V");
  Serial.print("Battery Voltage: ");
  Serial.print("0.00");
  Serial.println("V");
  }
  else{
  Blynk.virtualWrite(V1, realVoltage);
  Serial.print("Battery Voltage: ");
  Serial.print(realVoltage);
  Serial.println("V");
  }
}

void ledBar(){
  if(realVoltage >9){
    digitalWrite(LED_1, HIGH);
  }
  else{
    digitalWrite(LED_1, LOW);
  }
}

void loop() {
  Blynk.run();
  timer.run();
}

wildbill

What's the tolerance on the resistors in your divider?

Bjerknez

#2
Oct 04, 2020, 05:40 pm Last Edit: Oct 04, 2020, 05:41 pm by Bjerknez
The first resistor is 12K (2x6K) and the last one 3.3K. I think it is 1% metal film resistors.

wildbill

Well, you've got a small percentage error - might be just the impact of that tolerance.

Bjerknez

But the voltage from my batteries is absolutelig spot on. 9.56V measured from 9V battery with multimeter shows in serial monitor as 9.58-9.60V. The samr from my AA battery. 1.62V shows as 1.59-1.62V in serial monitor.

But when i connects my Power supply and adjust it to 9V, 12V or whatever, the serial monitor gives me 0.3V-0.4V too high readings.

I just can't understand why the serial shows too high readings from Power Supply, when my batteries is almost spot on.

johnerrington

It depends on the reference you are using for measurement.
IF (as I suspect) you are using DEFAULT then check the voltage.
Many boards have a protection diode that drops the Vcc voltage by about 0.5V.

http://www.skillbank.co.uk/arduino/measure-usb.htm

For accurate measurements you need an accurate reference.

More info here on measuring voltage with the arduinos.
I'm trying to help. If I find your question interesting I'll give you karma. If you find my input useful please give me karma (I need it)

Bjerknez

Bit why does the voltage from my batteries spot on, and not my PSU reffered to the serieal output?

If all voltage output had been wrong i understand, but the batteries shows correct.

johnerrington

You still havent said what board or what reference you are using.

Where does your calibration figure of 14.7 come from?

Check your resistors - are they actually 6k? or 6k2?

Quote
I think it is 1% metal film resistors.
1% resitors are marked differntly

https://www.electronics-tutorials.ws/resistor/res_2.html


Please add a serial.print after this line

Code: [Select]
int voltageValue = analogRead(vPin);

and post the results from the serial monitor.
I'm trying to help. If I find your question interesting I'll give you karma. If you find my input useful please give me karma (I need it)

Bjerknez

I can check that tomorrow.

But i still do not know why it is difference between battery and my PSU regards to what the serial monitor prints out.

Voltage from batteries are spot on, and voltge from PSU in the same rNGE IS 0.3 to 0.4V over.

slipstick

And when you measure the bench PSU output with the multimeter what does that read?

Is the D1 always powered in exactly the same way for all readings?

Steve

Bjerknez

The output from PSU is measured with multimeter and that its ecactly the samt that the PSU display shows. But the Wemos D1 Mini shows 0.3-0.4V over that in serial monitor.

Wemos is connected from computer with USB and that i have never changed.

Wawa

I'm going to make an 12V battery voltage tester with Wemos D1 and i have used Voltage dividers and connected to A0 input.
Must NOT use a voltage divider with a Wemos D1 mini, because the board already has a 220k:100k voltage divider on the board.

Just use a 1Megohm resistor between 12volt and A0.
Leo..

Bjerknez

Can you explain the 1Megohm resistor? Is'nt that a wery high value?

Wawa

There is a 330k (100k:220k) voltage divider on the Wemos, to drop ~3.3volt to 1volt for A0.
Meaning they use about 100k for every volt. A 1Megohm resistor adds about 10volt to that 3.3volt.
The divider becomes (100+220+1000)/100 = ~13.2volt full scale.
Leo..

jremington

#14
Oct 05, 2020, 12:28 am Last Edit: Oct 05, 2020, 12:56 am by jremington
The additional 1M resistor creates a voltage division ratio of 100/1320, which is about what you want.

Go Up