arduino voltmeter


This morning I had to turn the central heating on today, but we press on because I’m still working on the summer project, which is to build something like this it’s. An eight settle up to eight cells, monitor that can monitor the voltage on a lithium pack. And this is also a discharger so that this can discharge and balance the cells in that pack. So today I want to play with this it’s the secret voltmeter. This is on Google Code archive and I’ll provide a link to this page, but in the description beneath the video. So what this does is it’s um, a piece of code that allows the Arduino using an 80 mega 328 to measure its own voltage, rail to measure V, DD or VCC. So let’s cut this code section out here, paste it into arduino, download it to that arduino uno and see if it works right, so here’s a new sketch for today August the 10th and let’s paste in there control V. That code I got from the secret voltmeter page. I don’t quite know why they’ve written the first line is one great big, long line which runs over about three widths of the screen. I might try and put that on separate lines a bit later, but just for the moment, let’s see if that runs as it stands, so just saw there’s a space there which I could take out. The other thing is some: a couple of people were saying: can we have bigotech so I’ve increased it from 12? I don’t know it pointers it to 18, so it’s bigger now so let’s see if that will compile and upload right.

Well, this is a classic isn’t. It this won’t, compile it says a function. Definition is not allowed here before bracket token, whatever that means right. Well, I’ve moved a couple of these bracket things down, but that doesn’t seem to help. So I think what I’m gon na have to do is take this big long single line and break it up into separate lines, but it’s not actually easy to see where lines begin and end, because here we’ve got long result, there’s the semicolon and then there’s a Comment so I think the next line starts there, a VCC, oh no, read one point: one volt reference against a bzz, so it’s that’s their ad MUX equals so let’s bring that onto a new line, so add MUX equals these registers all odds together. Then there’s a delay that could be another line. That’S got a comment. Wait for V ref to settle then there’s. Another register is that that must be the beginning of the next line. I’Ll keep go, keep going, bringing these lines on two separate lines and see. If I can piece this thing together and get rid of this compilation, error, okay, so I’ve chopped this up into separate lines. It does seem to compile now so now, I’m going to do a compile and upload that compulsion to long as it’s already done it let’s see what the Arduino does right. Well, not an awful lot, although I can see there that the RX LED is briefly flashing.

Once per second, if I look at the code, there is a delay 1000 in there. So I think what it’s doing is it’s writing a value back to the serial monitor, so we’ll need to open the serial, monitor and see what’s coming back from that and here’s the serial monitor and yes, we’re getting this number coming back 507. Three, it is scrolling down the screen, but it’s not changing at all. Now it did say on the secret voltmeter page. Well, actually, let’s have a look at it. Oh, it has just changed. Look 507. 3. 509. 6. Let’S go back to that page yeah. So it says here the voltage is returned in millivolts, so 5000 is 5. Volts 3300 is 3.3 volts. So, looking back at the results coming back from the board, what we have here appears to be five point: zero, seven, three volts or five thousand, and seventy three mini volts and that’s just flicking up to five: oh nine! Six! Now this is not very useful and I can’t actually very VCC, because I can’t vary the voltage coming out of my PC, but it does tell me something and that is we’re going from 73 to 96, so that’s 23 millivolts of resolution, because that’s going to be One analog to digital conversion, bit change and that’s fairly coarse isn’t. It 23 millivolts of resolution I’m, not sure that’s going to be fine enough to measure the voltage of a lithium cell, for example.

So what I really want to do here is power, this from a voltage less than five volts, but then send that voltage information well somewhere at the moment, it’s going back over the USB to my PC. But, of course, if that cable is plugged in, I can’t have less than five volts on this board. So I think I’m gon na have to bring in my old friends the OLED and this Arduino Pro Mini this ammeter, this iron, a two and I won’t be used. But what I can do here is install the code in here and also add in some code to drive the OLED so that we can see that millivolt value on there. Then I can power this with less than five volts and see if that display responds to the voltage change. So what I need to do here is open. My other sketch, which is this one, my OLED and I n a two or nine that’s open that and I’m just going to have to sort of chop it’s out of here that I feel that I need to get both the reading of the VCC voltage and Then writing that to the OLED display, so I’ll start doing that now what I’m going to need is wire for I, squared C Arduino H, probably u8g Lib. I don’t need iron a to a none. I don’t think I need spi so let’s take those bits. I’M. Also going to need this, you a g2 constructor call here and also the you h, g2 begins.

So let’s grab those two bits and I’m also going to need the stuff which actually writes to the display so clear, buffer set font set. The cursor then print a value and what I’ll do is. Instead of this print line, read of EC C I’ll. Do a UHG to print read. Vcc I’ve already got a delay, so I don’t need that yeah let’s cut those bits out right, so I think that’s everything I’m doing the read of the VDD and then I’m sending that out to that little OLED. Now I need a course to change this from an Arduino Uno to a pro mini okay, so that’s all done, compile and upload and let’s see what the result of that is, and the result of that is this, which is encouraging. We’Ve got that same number, so that’s almost exactly 5 volts, but this is jumping around a bit more 5 double o 6 and was it 502 8. I saw yeah so that’s 22 me volts of resolution. I think we had 23 before so that’s similar now. 5. Double O 6. What would be the one under that? 4? 9, 8, 4. So four, nine, eight four up to six again: yes, that’s 22 millivolts of resolution, so that’s working the same. What I want to do now is see whether this number here tracks the voltage. If I whined the voltage down so I’m actually going to power this now through the raw input.

Now that does go through the voltage regulator but I’m going to drop the voltage down below the regulation. The regulator’s regulation voltage, and so it will probably just not do anything. Maybe just act as a a diode voltage. A semiconductor volt drop and just see whether this number drops as VCC drops so let’s, find a little power supply right so I’m going to use this little power supply. This is the minke b3 603, so up to 36 volts out, of course, it’s only a buck. So you’d have to put 38 bolts or something in up to three amps. So what do we got? We got 5 volts what’s it set to current hundred milliamps that’s a bit low. Let’S give it our do. We know you sort of current let’s, give it half an amp, save that so we’ve got five volts and half an amp, now I’m going to connect other little display, and I shall need a piece of wire with a suitable plug on so I’ll use that right, Let’S put the negative in the negative out stop running properly. Take a clamp that down on there yeah, it seems all right positive into positive out and then the big switch on will it work course. There may be quite a lot of noise coming out of this power supply, but then I suppose the 5 volt PSU in a PC is also switch mode, so, okay, so 5 volts switch on right.

Yes, that would be right because we’ve got 4. 9. 4. Oh yeah we’ve got almost point 6 of a volt of drop, so I suppose that’s happening in the voltage regulator. Now. The interesting thing is when I whine this down, so let’s come down to 3.7 yeah. We got 3.6 there. So, yes, that bit of code is actually measuring. Vdd let’s come down to about 3 volts 2.8 come down a bit further. Oh that has gone very dim and it seems to have locked up now, that’s, probably because at 2 volts this display isn’t going to function. All if I take that back up whether that’ll burst back into life, let’s go up to two and a half volts wears brighter, but it’s still saying to 727 that’s got to two point: seven volts notes: aren’t working two point: eight box, all right, that’s, come back To life now so at two point, eight volts, the OLED is working I’m, pretty sure the microcontroller can run at a lower voltage than this that’s. Probably the OLED that’s packing up at this low voltage, but yeah that’s tracking, reasonably well that’s, saying two point: seven: four! So again, at 0.6 volt drop from two point. A to C me all these voltages are accurate, so certainly that seems to be tracking VDD reasonably well now what’s the millivolt resolution here. Well, it looks like it’s 33 to 40, which is much better because that’s only seven millivolts of resolution, whereas up at five volts we were getting what was it twenty two mini volts of resolution, so the resolution certainly seems to be better at the low voltage end.

So how is this Arduino, this Arduino Pro Mini, able to measure its own VCC and that’s the only thing connected to this Arduino it’s, just these two wires and it’s actually measuring the value of VCC. How is it able to do that? Well, I’ve printed out a couple of pages from the 80 mega 328p datasheet, and this is the section on the analog to digital converter. So the way the analog to digital converter works is that you have a comparator here and a digital to analog converter. So what you do is you put different values on the digital to analog converter, and you find the point using a process called successive approximation I’m not going to go into that here, but I will put a link to a video I did on how a to D converters work previously, so you can view that. But you find the point at which this comparator is just flipping from one state to the other, and that means that the output of the digital to your converter is the same as your analog value. Coming in on one of the 8 analog pins a 0 to a 7 now the point is the digital: to analog. Converter works a bit like a potentiometer. It gives you out on its output a proportion of the voltage on its input, and that proportion is simply the binary number that you put in relative to the maximum binary number, which is 102 4, will use 1 or 2 4, because that makes the maths correct.

102, 3 is the actual maximum number you can put in here. So if you put in 102 3, then you get pretty much the full value of voltage, that’s being fed into the DAC you’ll get it coming out of here and if your analog input is also the maximum value of voltage, let’s, say 5 volts, then that’s, where You’Ll get a comparison on the comparator and you’ll know that 102 3 is the equivalent of the voltage coming in on your analog input, but that assumes that we’ve got 5 volts, which is here a VCC routed through to the DAC. Now this measuring own VCC program uses a different routing. What it does is it really those registers up here and rearranges, instead of VCC being on the depths instead of the DAC having the full 5 volts and its output being a proportion of that 5 volts dictated by the binary number that you put in, we actually Feed a different value into the DAC we actually feed in and what we feed in we feed in well, we feed in VCC actually that’s not changed it still routes VCC in, but of course, here VCC is now only 2 point 8 volts. So the output of the DAC is a proportion of that currently 2 point 8 volts dictated by the binary value that you’re putting in here. If we put in the full 102 3 binary value, then you’ll get 2 point 8 volts coming out of here.

So what do we put into the analog input? Well, we actually put in this thing the bandgap reference and although it’s got a different name, banget reference and internal 1 point one volt reference it’s, actually, the same thing it’s just that up here, it’s buffered, but this is a fixed one point. One volt analog input. So if we had a fixed five volts on the DAC, then this would always measure one point, one volts, or at least the binary equivalent of one point, one volts, but because we’ve now got a varying VDD or VCC currently down to two point: eight volts. But I can take that up to five volts. We’Ve got one point, one volts as a proportion of this varying amount, and this means that our mathematics is all upside down. Normally we’ve got a fixed five volts driving the DAC and we’ve got a varying analog input. Varying between 0 and 5 volts providing different analog or binary values. This is the other way around. We’Ve got a varying VDD and we’ve got a fixed one point one volts as our analog input, so the maths is actually flipped. It’S inverted, and you can see that from the code that makes this thing work right. So here it is I’ve printed it out in the new larger font size, so I’ll just bring the camera out ever so slightly, and the first section here is what adjusts the registers this register mainly up here to reroute well it’s, the one that selects it’s it’s.

This section here this decoder, this selects, which of these inputs, is fed through to the analog to digital converter than normally you’d, select either a 0 to a 7. Here we are selecting the bandgap reference, so that’s done with this first statement. Then we do an actual analog to digital conversion. We read the result in and here we take a fixed value. This is a long but it’s a fixed value and divide it by the result, so we’re taking the analog to digital conversion result and putting it on the bottom of a division with a fixed constant on the top that’s. This flipped over thing. I was talking about to calculate the voltage in millivolts now normally when you use the analog to digital converter, the right way round, with 5 volts driving the dak and a variable voltage on the analog input between 0 amp 5 volts. The resolution is about 5 millivolts because you’ve got a 10 bit DAC, so you’ve got about a thousand different binary values, it’s actually a thousand and 24, so the resolutions slightly better than 5 millivolts but that’s over 5 volts. So that gives you that 5 millivolts. But here because this thing’s flipped upside down we’ve got a variable resolution: it’s, not bad down at the low voltage end. In fact, if we could get this voltage right down to one point, one volts we’d have the full 5 millivolts of resolution, but even at this two point, eight volts we’re getting 7 millivolts of resolution 33 to 40, is only when we take this up to 5 Volts and I’ll do that now: let’s whizz, that up to 5 volts 5 volts we’re now getting.

I think it was 22 millivolts of resolution. So the resolution is much less good when we’re a long distance away from the bandgap voltage, which is one point one volts we’re getting much poorer resolution now. The question is, for my project is 7 millivolts. Was it a resolution deteriorating to about 22 millivolts at resolution? Although of course, if iam cells don’t go up to 5 volts, so we might call it, I know maybe 15 millivolts of resolution is that enough for building something like this. The cell meter for measuring lithium cells let’s just plug a lithium pack into here and see what resolution this operates at let’s. Take a look at the cell voltages and you can see that it’s sort of oscillating between three point: eight, zero. One and three point: eight zero zero, so this ostensibly is measuring to a 1 millivolt resolution is between 7 and 15 millivolts going to be enough or does each of my Arduinos, and I am planning to have eight of these arduino x’ one measuring the voltage on Each of up to eight cells do these Arduino need some sort of external chip to do a more precise voltage measurement. Or can I get away with this this built in secret voltmeter? Is it good enough? I shall have to have a think about that, but for the moment I just wanted to see this in action and it does seem to work let’s just drop that voltage down again let’s go down to about three volts there enough yeah.

This does seem to measure its own VDD.


arduino voltmeter Video







arduino voltmeter news








arduino voltmeter Social






A modular, Arduino Mega-controlled delta robot for your desktop.
safe image.php?d=AQDI5lGBL JxubWR&w=720&h=720& content%2Fuploads%2F2019%2F08%2F9154041566833130733 - arduino voltmeter

This interactive floor recalls the precariousness of standing on an icy surface, enhanced with imagery, sounds and physical dynamics.
safe image.php?d=AQDDp  jywcEiEdX&w=720&h=720& v6%252Fshare%252Fplay icon overlay - arduino voltmeter
0rB1oLPP normal - arduino voltmeter
Thu May 08 21:07:51 +0000 2014

RT @MicrochipMakes: Spotted on @Reddit: An ATtiny85-based wireless voltmeter for batteries up to 6V!…
BAlEFgAV normal - arduino voltmeter
Sun Jun 15 16:42:59 +0000 2014

#arduino Wireless voltmeter I made using ATtiny 85, NRF24L01 and an UNO. Monitor voltage of up to 6 batteries. Next step: BLE.

Instrumentation Family Photo

DIY: voltage programmable ‘active load’



(Visited 22 times, 1 visits today)

About The Author

You might be interested in

Comment (20)

  1. Not sure how secret the ADCs are but nice video anyway. I like the explanation of the bandgap reference. Good work!

  2. The only thing wrong with Arduino stuff is finding a good practical use for it. I can buy dedicated device that is ready to go without need to hook it up to program it as all options are done at the device. As for experimenting it’s already been done.

  3. Wow, I have never tried to feed an arduino on less then 5 volts, unless it was classed as a 3.3 volt! It brings all sorts of possibilities to mind, such as using some of those old 3.7 volt cells I have recovered from all sorts of old android tablets that I purchased when they were suddenly obsolete and selling like hotcakes for 4 bucks each. I have a pile of some rather large flat cells that are very healthy, and contain all sorts of wonderful power just waiting to be released on some project or another. I shall have to try some of them and see if I can get an arduino project to run on them!
    Thanks for sharing, I always learn something from your videos, and I have it stuck in my head that if I continue learning, my mind will remain a bit fresh in it’s aging state.

  4. I might be slow as I got up WAY too early this morning – but why not just set the Arduino (I use Nano clones) to 1v1 reference – and use the analog inputs – on the little Nanos you have 8 of them (providing you are not using I2c of course)…. I generally average readings over, say 8 samples so as to get a smoother input.

    With dividers you can get any voltage you like – you don’t even need high precision resistors as you can do a multiplier in software to compensate assuming you have a half-decent multimeter.

    The alternative of course is to use the INA219… voltage readings on those devices is just fine – but before anyone says “they do current as well” – you might want to do the math on the voltage drop across that 0.1r resistor…

    As an alternative, the INA3221 board has THREE such inputs.. and as I just found out a sensitivity which means you could measure a couple of amps or so by replacing the 0.1r resistor with a 0.05r resistor – and hence half the voltage drop…

    I just did this – and in the meantime (re-)discovered PROCESSING tool for the PC and knock up a little PC monitor. Progress so far is here… be interesting to hear comments however about what’s wrong with simply using the normal Arduino commands to read the analog inputs. A little OLED display and assuming no I2c, you could get 8 voltage measurements..

    Anyway, here’s the link – work in progress…

  5. Nah no secret and the Voltage of the reference is not always 1.1V. Some MCU’s have it a bit higher or lower and it changes a little between different VCC voltages.

  6. Why not use a voltage comparator on vdd at a low voltage close to the cutoff voltage then program a offset in the code to give better resolution?

  7. Aiiiyah! It’s pronounced “ming her” NOT “ming hee” – and to be strictly correct, there is a low to high rising tone on the syllable “her”.

  8. Very interesting, thank you for showing this page and debugging the code for us.
    I plan on using this code in all my battery operated sketches to keep an eye on my rails to alert me if the source is going too low and possibly cause damage to my Li-Ion batteries. Almost like make this a general purpose library.

  9. Greetings from Portugal.This was a mild summer in Europe (around 30ºC here) but central heating in August? It seems that Grand Solar Minimum is here to stay……..hihihihi.

  10. Hint: The “Secret Voltmeter” doesn’t have to measure VCC. It can also measure the analog reference (AREF) pin’s voltage with the same resolution as it measures VCC. Just change the proper bits in the register configuration.


Your email address will not be published. Required fields are marked *