Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arduino as Volt Meter
#1
After a bit of Googling around, I find myself more confused than informed.

What is the most effective way of getting accurate voltage measurements with an Arduino? Preference is using the internal ADC. There are apparently issues with powering it from the source you are measuring.

I know a few members are using Arduino/ESP etc. based BMS. Just wondering what method are you using?
Reply
#2
It'll depend on the voltages you're trying to measure.
Specs suggest power supply voltage limits are from 6-20V for powering via regular methods.
https://store.arduino.cc/usa/arduino-uno-rev3

This link discusses specialized changes for fixed 3.3V operation, not so easy....
https://forum.arduino.cc/index.php?topic=409415.0

If you tried powering via fixed 5V or 3.3V & accidentally applied a higher voltage, the magic smoke would come out.

The internal voltage reference can be switched to use a 1.1V or 5V internal source. So if working with say the 1.1V ref, your "full scale" would be when 1.1V arrived at the analogue input pin - so you would scale down higher voltages to be in that range with resistor dividers.
Running off solar, DIY & electronics fan :-)
Reply
#3
You "can" measure the voltage you are powering from. However, you must calibrate the ADC before each major read (ie, ever 250ms or so).

Even if you aren't measuring the same voltage as your powering voltage, you should still calibrate the ADC.

As Redpacket mentions, the internal voltage reference 1.1V. This voltage is dependent on the input voltage. If there is exactly 5V to the arduino, this voltage should be 1.1V on the nose. If it's 4.7V, then it could be 1.06V, or something like that. By measuring the internal voltage first, you can then get a more accurate reading on the ADC.

Code:
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 setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println( readVcc(), DEC );
  delay(1000);
}

References:
https://hackingmajenkoblog.wordpress.com...e-arduino/
https://provideyourown.com/2012/secret-a...y-voltage/
Geek likes this post
Proceed with caution. Knowledge is Power! Literally! Cool 
Knowledge is Power; Absolute Knowledge is Absolutely Shocking!
Certified 18650 Cell Reclamation Technician

Please come join in general chit-chat and randomness at Discord Chat (channels: general, 3d-printing, linux&coding, 18650, humor, ...)
(this chat is not directly affiliated with SecondLifeStorage; VALID email req'd)

Kickstarter: Honest STM32F103 based dev Boards
Patreon: Korishan
Reply
#4
Korishan, I think it comes back to how the arduino is being powered:
If from 6-20V external source then the +5V & 1.1V internally generated voltages should be quite stable but need calibrating
If powered from 5V, then the 5V ref only as stable as your 5V source is & still needs calibrating.
If using the 1.1V ref it should be stable if other sources vary but still need calibrating.
Korishan likes this post
Running off solar, DIY & electronics fan :-)
Reply
#5
Thanks for the info! Surprising how hard it can be to find simple tricks online.
Reply
#6
(10-04-2018, 02:26 AM)Geek Wrote: Thanks for the info! Surprising how hard it can be to find simple tricks online.

Yeah, it's not so much that the info isn't there, it's know the right combination of words to use as the search criteria.

As Redpacket mentions, the power voltage "should" be stable if the main power is >5.5-6V and bucked down to 5V. But, we know that this is not "always" true. Connection issues can always cause issues, and this can vary between power ups. If the power is being provided via a usb cable or other type of connector, there can be variations on the input. So it's pretty good to calibrate on startup/bootup. Maybe even have an option to re-calibrate manually if you suspect an issue.
But usually once is fine after power up.

However, if the power source is lower than 5V and boosted up, then you probably want to calibrate on a pretty regular basis just before you do a read with the ADC. Just remember you have to pause a little to give time for the internals to reset back from internal to external pins. That is discussed in those articles.
Proceed with caution. Knowledge is Power! Literally! Cool 
Knowledge is Power; Absolute Knowledge is Absolutely Shocking!
Certified 18650 Cell Reclamation Technician

Please come join in general chit-chat and randomness at Discord Chat (channels: general, 3d-printing, linux&coding, 18650, humor, ...)
(this chat is not directly affiliated with SecondLifeStorage; VALID email req'd)

Kickstarter: Honest STM32F103 based dev Boards
Patreon: Korishan
Reply
#7
I think there might be another nuance to it:
The arduino's external 6-20V input has a ~1V drop out threshold headroom, ie it needs to be min 1V higher than the 5V internal reference it's generating (they say 7-12V so is may be 2V droput headroom needed).
Running off solar, DIY & electronics fan :-)
Reply
#8
(10-04-2018, 04:00 AM)Redpacket Wrote: I think there might be another nuance to it:
The arduino's external 6-20V input has a ~1V drop out threshold headroom, ie it needs to be min 1V higher than the 5V internal reference it's generating (they say 7-12V so is may be 2V droput headroom needed).

I imagine that shouldn't cause too much trouble for the 1.1v internal reference. I don't need incredibly accurate - about +/-0.05v. But it does need to be reasonably consistent.
Korishan likes this post
Reply
#9
This is crazy 'accurate' thanks guys. Is there an easy way to get a proper reference voltage? I have seen setups on Ali for sale. But this is so consistent I'd like to go the next level.

Reply
#10
(02-11-2019, 07:22 AM)Geek Wrote: This is crazy 'accurate' thanks guys. Is there an easy way to get a proper reference voltage? I have seen setups on Ali for sale. But this is so consistent I'd like to go the next level.


Could you advise the setup you had for that?
ie, what supply voltage, which reference used, what voltage divider resistors, etc?

I'd suggest using the 1.1V internal ref, calibrate it once, save that cal value, then log some values.

Also beware of supply noise, so have eg a 10uF capacitor across it.
Running off solar, DIY & electronics fan :-)
Reply


Who read this thread?
64 User(s) read this thread:
daromer, Sean, Joaquinsfy, owitte, Korishan, PAF, jdeadman, wim, watts-on, Stefaan De Ridder, BlueSwordM, Geek, Bloater, ChrisD5710, Nikhil Mahajan, spyroslo, karmi27, Ste Collister, Charly144, brwainer, drchips, Roland Domke, Redpacket, Ibiza, davidtrn24, Bubba, Cherry67, Riplash, mishok, Rasmus Godske, michaell, tig77, chuckp, emuland-metroman, hazSolar, Beholder, Christiaan Plug, Leipi35, Jaster, Wolf, Cesar_Tee, camthecam, Dallski, rettore, PaulDane, richie241, kevinjaye, holdman_2004, mart1nn, LEDSchlucker, zoookii, ibp, 1Lukas1, Gremlin, Richard, Overmind, Church1182, Edster, Lucan, Leafnut, wreckless, ganushak, MonkeyThink, tmodx

Forum Jump:


Users browsing this thread: 1 Guest(s)