Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Accurate voltage measurement

Status
Not open for further replies.

Wond3rboy

Member
Hello

I wanted to measure DC voltage in the range of 0 to 24 V using an Arduino and I was looking at sensors as well as things I will have to be careful about. I am ofcourse looking to measure the voltage as accurately as I can. I couldn't find a digital voltage sensor but found some analog ones. For using the analog sensors, however, to have good accuracy (hopefully within < 0.5 V from actually value) I was thinking of:

1. Having a good reference voltage (probably use a Low Drop Out regulator or something)
2. Just to be on the safe side using a voltage follower at the A/D input of the Arduino.

The voltage to be measured would be the output of a Solar charge controller.

Do you guys have any input on this in terms of a sensor that you can point or things I need to be careful about when designing my circuit for this?

Thanks !
 
A voltage followed looses 0.65 volts and is not temperature stable. Why do you need one?

Ah ok. I was just thinking about it from a precautionary point of view in regard to potential impedance mismatch issues. I dont have the hardware with me right now. I guess it's a bad idea to include one. Thanks so much for the input Ron!

Do you feel I need to be careful about any other thing that I might be overlooking ?
 
I couldn't find a digital voltage sensor but found some analog ones.
I'm confused.
If you are using the A/D input of the Arduino to measure voltage, what are these digital/analog "sensors" for?
 
I do not know which Arduino you are using.
Some are 10 bit and some can do 12 bit.
Some measure 0-3.3V and some 0 to 5Volts.
 
As long as the Arduino ground can be connected to the 0V of the 24V system, all you need is a resistive divider.

If you use 1K from ADC input to ground and eg. 7.2K from ADC input to the 24V being measured, that will give a range up to 27V for a 3.3V device.

Or eg. 1K to ground and a 4k7 input for a 5V supply device, that would allow 28.5V maximum

Use a higher value resistor between the ADC input and 24V if you need a higher maximum possible reading.

As long as you are using 1K ADC input to ground, the maximum input voltage to the divider is the ADC maximum input voltage x the sum of the two resistors in K Ohms.

ie. for a 3.3V input limit using 1K and 8.2K, the limit is 3.3 x 9.2 = 30.36V
You could use a lower slightly value resistor plus a preset resistor in series, to allow the input range to be calibrated.


The reference voltage is often just the supply voltage for the microcontroller. If you do (can?) use a separate external reference for the ADC, then the voltage of that would presumably also be the ADC input voltage limit for the above calculation.
 
ronsimpson

Atm, I have two boards under consideration. I have a Nano that I can use that works at 5 Volts and has multiple Analog inputs ( 10 bits, I can only see needing one atm). I also have a nodeMCU which does 3.3 V and has only 1 Analog input (I have never used the ADC input before so have to read up on its specs except that its 10 bit but haven't gone through other things). I would like to push the data up to a server if I can for later viewing so I am inclined to use the NodeMCU.

I'm confused.
If you are using the A/D input of the Arduino to measure voltage, what are these digital/analog "sensors" for?

Its basically a voltage divider packaged in to a sensing module. Its cheap (chinese) and decreases chances for variability (my bet is their product is superior to me plugging in two 5% tolerant resistors for a voltage divider).

Voltage 'sensor'

rjenkinsgb

Yeah that works. However, I didn't want to create a divider and have to calibrate things/potentially get low tolerance resistances. Over here it would be easier to get this module than get low tolerance resistances.

Since both resistors will be exposed to the same environmental conditions, I am not confident (inexperienced in deployed circuit design) if I should bet on them exhibiting a similar type of deviation from their standard values.


Thanks so much guys!

Edit: Forgot to thank you all for your replies.
 
5% tolerant resistors for a voltage divider).
Get 1% resistors. You can get 0.1% resistors or better. The Chinese divider does not say but it looks like 1% resistors.
I should bet on them exhibiting a similar type of deviation from their standard values.
If you get the two resistors from the same company, same series, they will have the same temperature curve.
within < 0.5 V from actually value)
I think you are over thinking this. 0.5/24 is not very good. that is only 2%.
Resistors are low cost. Get 0.1% it will not brake the bank.
Your 3.3V supply is probably 1% or 2% and you can calibrate that in software. If the supply is actually 3.4 then multiply by 0.9706 and you are gold.
 
Thanks Ron.

I think I will go with what you suggested and use 0.1% resistors. A better strategy then going for the module.

Cool tip on the power supply correction. I was intending to buy a LDO regulator but this I think would work fine and reduce circuit space.

Thanks so much again for getting back on this! You guys are awesome as always :)
 
Do any Arduinos have a decent voltage reference built in for this kind of thing?

Mike.
 
Atm, I have two boards under consideration. I have a Nano that I can use that works at 5 Volts and has multiple Analog inputs ( 10 bits, I can only see needing one atm). I also have a nodeMCU which does 3.3 V and has only 1 Analog input (I have never used the ADC input before so have to read up on its specs except that its 10 bit but haven't gone through other things). I would like to push the data up to a server if I can for later viewing so I am inclined to use the NodeMCU.

The NodeMCU is an ESP8266, if you upgrade to the ESP32 then that provides many more analogue inputs - however, apparently the A2D isn't very linear.
 
A couple of thoughts....

Yes, any Arduino that uses an ATMega328, including the Nano, has a Vref pin (0-5V). They also have an internal Vref and, if you don't specify, they will use the Vin pin (see here).

If you are using a voltage divider to go from 0-24v to 0-5v, 1% resistors (E96 range) offer an advantage of more choices relative to 5% or 10%

Using an Arduino, you want the impedance of the signal into the converter within a 2k-10k range (see the ATMega328 data sheet which I am to lazy to go link and am going on memory which may or may not be completely accurate).

Use an op-amp (with a 5v nano, a rail-to-rail 5v op amp like the MCP601 will work as will many others) in a unity-gain configuration so you don't need to worry too much about the impedance matching.

So, you go to your friendly neighborhood calculator - like this one. Plug in your values and you can use 5230 for R1 and 1370 for R2 or a multiple, to reduce current draw, keeping the ratio (of course you want to verify the values with your meter). At the bottom of the page you will see the op-amp buffer already drawn out for you. 0-24V to 0-4.98V, Easy Peasy. So close to the Vin you may be ok with the accuracy as is and not bother with trying to duplicate the high range (the 4.98V) and using it for Vref.
 
DrG

Thanks for the detailed insight. I will definitely add the voltage follower for impedance matching as you suggest too. Especially since I am probably going to end up using the ESP32.

The calculator is very handy, thank you!

Nigel Goodwin and Pommie

Thats what I was doubting too about the Arduinos. I did look at one ESP32 board that fits the bill.

HiLetgo ESP-WROOM-32

Atm, I am not considering PICs as they will require a longer design cycle than an Arduino based device. I might shift to using PICs if I see an advantage in terms of cost (which is mostly availability based as importing things will overrun unit affordable cost where I live, high end PICs are not easy to acquire as they are not required by the hobbyist market we have here) as I am doing this for a potentially marketable application and moving to a more lets say 'fixed' system rather than a swap and fix model.

Dont see an analog Vref from pin out shown in the listing but will read up upon that, by working through the manual. Thanks so much for pointing me to it!
 
I have never used the ESP32 A2D but the ESP8266 was disappointing. In any event, be sure to do the background reading for the ESP32. The ATMega328 has a huge amount of info out there and what I was saying previously was, of course, relative to that chip.

 
I have never used the ESP32 A2D but the ESP8266 was disappointing. In any event, be sure to do the background reading for the ESP32.

I've used both, mostly to measure the battery voltage, and upload it a MYSQL database with the other readings - this is from an Wemos Mini D1 and BME280, temperature was off the top of the screen.

BatteryVolts.png


And this is a Wemos Mini D1 and SHT30, uploading to ThingSpeak:

ThingSpeak.png
 
Nice! I was disappointed in the ESP8266 A2D because it is native 0-1 v as I recall. I don't know if there is a divider on the Weemos board (and I should because I have one).

The best A2D that I have used was on a Quark D2000 (no longer made) it was 12-bit and all the code for the firmware was available. I am in awe of folks that use very high resolution A2D and do so without much noise.

Yeah, data loggers are cool. Here is a humidity graph from the TI Sensortag. At first, I could not figure out those two increases circled and then I realized that the shower was on and the sensortag was close enough to pick it up.
120136


Have you ever done any data sonification? I played around with it a little bit....take this ambient light graph (also from a SensorTag):

120137


Then you assign different tones to the data points (different tones for the Lux values) and then you can play the data song... If you rename the attached file AL2midi.txt to AL2midi.midi, you can play the sound in Windows player or whatever - You can hear the overcast days near the end of the time series - kind of cool.

OK, this is now WAYYYY off topic, but you started it :)

Edited to add: I did the sonification using the Sonification Sandbox (I actually still have it and actually remembered!).
 

Attachments

  • AL2midi.txt
    20.1 KB · Views: 232
Last edited:
Nice! I was disappointed in the ESP8266 A2D because it is native 0-1 v as I recall. I don't know if there is a divider on the Weemos board (and I should because I have one).

Why disappointed?, 0-1V is a great advantage it avoids needing an amplifier, and is easily attenuated in any case.

The Wemos Mini D1 has such an attenuator (which I 'think' scales it to 3.3V? the chip supply) - it's shown on the schematic, and explained in the documentation.

Anyhow, not much use like that - as I want to measure the voltage before the regulator (so up to 4.2V) - so I simply added a resistor (160K if I recall correctly?) from A2D input, to the 5V rail, which is fed from my Li-Ion battery, to scale it further. This gives a nice 10 bit range, to 10.23V, so no messy scaling, and only applies a small load to the battery. I also add a wire link for the sleep reset, and the boards wake every ten minutes, send the readings, and go back to sleep.

If it can't connect to the WiFi, it tries a number of times, then gives up - so as not to waste the battery.
 
Status
Not open for further replies.

Latest threads

Back
Top