PSU issue

Hello all

I'm quite new to all this, so I may have missed something obvious.

I am building a project that uses a standard voltage divider.

The problem I am having is that when I have the project powered from my laptop via the USB port it measures correctly. But when I power it from a PSU (USB or 9V) it measures about 400mv low. I've tried several different (3xUSB, 1x9V) PSUs including a PSU from my Raspberry Pi project.

Any comments would be most appreciated.

Regards

Fred

(deleted)

Hi Drew

Laptop 5.02 Pi1 5.05 Pi2 5.01 Blitzwolf 4.90 9V 4.95

This is measuring the 5V pin on the Uno.

All external PSUs measure the divider at around 400mv low. The laptop measures correctly.

I'm wondering if there is to much ripple on the external PSUs.

Regards

Fred

Take a look at this : https://www.arduino.cc/en/Reference/AnalogReference , use one of the internal reference for the board that you are using, and change the voltage divider to suit the new value.

Cheers, Ale.

Hi Ale

I'm obviously missing something here. I've looked at the AnalogReference stuff. I can't seem to work out how it is implemented. So I gave up on it.

Besides that, I don't think it is my actual problem given the actual voltages I am getting on the 5V pin from the various external PSUs.

After all, I'm simply measuring the battery voltage of an offline 12V power system. Its not complicated. And the divider is a standard 30K and 7k5.

I'm going to see if I can borrow a decent scope so I can investigate things further.

Regards

Fred

derfz:
Hi Ale

I’m obviously missing something here. I’ve looked at the AnalogReference stuff. I can’t seem to work out how it is implemented. So I gave up on it.

Very strange, I can’t see so much differences in using a different reference.

derfz:
Besides that, I don’t think it is my actual problem given the actual voltages I am getting on the 5V pin from the various external PSUs.

Well, it’s hard to say where the actual problem is, we don’t see either your code and your schematic, for what you said the only thing you swapped is the PS, and this means that your analog reference is always different, so the first thing I would try is to make the reference stable.

derfz:
After all, I’m simply measuring the battery voltage of an offline 12V power system. Its not complicated. And the divider is a standard 30K and 7k5.

I’m going to see if I can borrow a decent scope so I can investigate things further.

Regards

Fred

Make a quick test by changing the 30K with 82K and use the internal 1.1 volt reference.

Cheers, Ale.

I have managed to resolve my problem.
Whilst there was some considerable noise generated by the PSUs, it wasn’t the real culprit.

In the end I added some code I found using google that made my reference the 1.1V reference.

I must say that if you don’t know much about software (as I do) the documentation about reference voltages and how to implement them seems very obscure. Or at best vague. I guess there is the assumption of a certain level of knowledge.

I still have no idea how or why the software I simply copied and pasted works. But I assume I will learn over time.

To all those who made a comment, I thank you as your comments pointed me in the right direction.

Here is the code that solved my problem.

long readVcc() {
  long result;
  // Read 1.1V reference against AVcc
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Convert
  while (bit_is_set(ADCSRA, ADSC));
  result = ADCL;
  result |= ADCH << 8;
  result = 1125300L / result; // Back-calculate AVcc in mV
  return result;
}

void loop() {
  unsigned int ADCValue;
  double Voltage;
  double Vcc;

  Vcc = readVcc() / 1000.0;
  ADCValue = analogRead(0);
  Voltage = (ADCValue / Res) * Vcc;
}

I simply referenced “Voltage” as my Reference voltage in my formula and it now measures within 50mv

Regards

Fred

I thought I had better reference the work I got my solution from.

https://hackingmajenkoblog.wordpress.com/2016/02/01/making-accurate-adc-readings-on-the-arduino/

Regards

Fred

derfz: I have managed to resolve my problem. Whilst there was some considerable noise generated by the PSUs, it wasn't the real culprit.

I'm glad you solved your problem!

derfz: In the end I added some code I found using google that made my reference the 1.1V reference.

No, you don't. The code that you added use the internal 1.1V reference to calculate the actual Vcc (Avcc, but is usually the same). The voltage reference is still the Vcc (5V).

derfz: I must say that if you don't know much about software (as I do) the documentation about reference voltages and how to implement them seems very obscure. Or at best vague. I guess there is the assumption of a certain level of knowledge.

Yes, but it's not so difficult, at least if my very simple mind can understand it! Arduino as 10 bit adc, meaning that the value returned by the analogRead() can have 1024 different values, ranging from 0 to 1023. What this number mean? It's not of course the value in volt of the voltage applied to analog in! Here the reference, that is the max value (1023) in volt. So if you reference is 5V, each unit in adc reading is equivalent of 5 / 1024 = 0.0048 Volts, so if your reading is say 347, the voltage will be 347 * 0.0048 = 1,6656 volts. If your reference is 1.1V , the unit is 1.1 / 1024 = 0.0010 volt, so the same read of 347 this time will be 0.0010 x 347 = 0.347 volts.

derfz: I still have no idea how or why the software I simply copied and pasted works. But I assume I will learn over time.

To all those who made a comment, I thank you as your comments pointed me in the right direction.

Just to let you know: the solution that you find is working, and is very good and smart one, but in your specific case it's a bit 'overkilled'.

Cheers, Ale