This is the first of two videos on measuring voltage and current with an Arduino. In this video, we will be working with Direct Current.
Article with code samples: https://dbot.ws/dcvc
There are many reasons why you might want to measure voltage and current using a microcontroller. You might want to measure the current consumption of your project, test the output of a solar cell or monitor the charging and discharging of a LiPo battery.
Voltage and current measurement are fundamental techniques, and so I’ve decided to do a couple of videos about the subject. In this first one, we will work with DC or Direct Current. And, obviously, we’ll be looking at AC in a future video and article.
Although I use an Arduino Uno in these experiments the principle of operation applies to pretty well any microcontroller.
We’ll start with DC voltage measurements, using the Arduino's analog to digital converter, or ADC. We’ll see how we can employ a voltage divider to increase the range of measurement, and how a precision external voltage reference can be used to improve accuracy.
Then we’ll move on to current, using both a Hall Effect and resistive sensor. That last sensor is pretty unique as it can measure both current and voltage at the same time, and it uses an I2C connection instead of the Arduino's ADC.
Here is what you'll find in today's video:
00:00 - Introduction
01:54 - DC Voltage Measurement Principles
05:35 - Basic DC Voltage Experiment
11:07 - Using an External Voltage Reference
14:49 - DC Current Measurement Principles
16:54 - Using the ACS712 Hall Effect Sensor
27:36 - Using the Adafruit INA219 Sensor
As always you can get the code I used and fined more information in the article on the DroneBot Workshop website at https://dbot.ws/dcvc
And in a few weeks I'll follow-up with a video about measuring AC voltage and current, so if you haven’t subscribed yet please join us so you don’t miss anything.
Hope you enjoy the video - now go out and measure something!
"Never trust a computer you can’t throw out a window." — Steve Wozniak
I am struggling with an application that I have in mind for the Hall effect sensor. What I want to do is build a simple detector that has a binary output which indicates whether or not current is flowing. I do not want to use a micro controller for this as that is overkill and takes up too many resources. My problem is that the zero-point on the sensor is 2.5V and not 0V. How do I detect if the output of the sensor is above that zero-point? I am totally out of my depth here with this one. Thanks.
Adafruit INA219 Sensor
Seems to be my lucky day. I had watched some videos on YouTube last night and today and was amazed by the "How they do it feeling" when I saw them displaying all of the details like Power, Current etc used by the LEDs on an LCD. Now I know.
And for the reference, I was watching the Nixie Clock video
Life is exploring and learning
I just read this on an Ebay sellers listing, could be handy for higher loads 🤔
"Advanced hackers can remove the 0.1 ohm current sense resistor and replace it with their own to change the range (say a 0.01 ohm to measure up 32 Amps with a resolution of 8mA)"
@melbul That sounds word-for-word from the description Adafruit has for the INA219, which I link to in my article. I also mentioned it as well in the article.
I think your eBay seller just copied the Adafruit text!!
😎
Bill
"Never trust a computer you can’t throw out a window." — Steve Wozniak
My problem is that the zero-point on the sensor is 2.5V and not 0V. How do I detect if the output of the sensor is above that zero-point?
Using a comparator chip comes to mind, just set it to trigger on a voltage above 2.5-volts. The LM339 is a pretty common one (it actually has four).
😎
Bill
"Never trust a computer you can’t throw out a window." — Steve Wozniak
Adafruit INA219 Sensor
Seems to be my lucky day. I had watched some videos on YouTube last night and today and was amazed by the "How they do it feeling" when I saw them displaying all of the details like Power, Current etc used by the LEDs on an LCD. Now I know.
And for the reference, I was watching the Nixie Clock video
Could you give the exact link to this particular Nixie Clock video?
I played with them when they first came out. I think mine were green or maybe blue and perhaps had a smoked plate in front of them so only the numbers could be seen.
I was curious as to what it was that enabled you to now know about Power, Current etc.
Thanks, Bill,
In the first section with DC voltage measurements, you added a precision external voltage reference to increase accuracy. What changed on the Arduino when you attached it to the AREF pin? Does this change the voltage limit felt on pin A0 from 5.0 down to 4.096 or can it still allow the sense voltage to go as high as 5.0V?
In your first example, let's try to measure a source of 25VDC. Using the voltage divider this will output exactly 5.0V to pin A0. The analogRead will assign 1023 to the float adc_value, then the math will reveal that the in_voltage is 25V.
But in the second example, with the AREF changes, does the maximum sense voltage drop to this new level of 4.096VDC? If so, then does the maximum in_voltage also drop to 20.46VDC? If we input anything above this 20.46V will it stay the same?
What changes did you need for the sketch to work using the external voltage reference since we are now using the AREF pin instead of the internal vRef?
Thanks for introducing me to the INA219, I now have a bunch of them on order. Does Adafruit have an example combining this module and an OLED display?
@robotbuilder Here is the video to the "Making of A Lixie Display" where at around 28:40 you would find an OLED Display displaying the test results of the WS LEDs.
I was trying to make one on my own, but had to stop because they won't ship those LEDs to India (from AliExpress) and the ones available in India are quite expensive. I would ideally have preferred the WS Leds to be the bare ones that are assembled on a very small pcb - just because I have no experience working with those bare bones SMD ones.
However, now I have a bunch of those LEDs (in strips) so maybe I can try them sometime (but for now, it is on hold). All I have is some home cut and drawn with a scalpel (better word - scratched :D) Acrylic sheets, if I define what I have.
Oh, I now realize that the "Lixie and Nixie" are actually different things (darn me). Here is a URL for the Nixie that I searched -
https://www.youtube.com/results?search_query=building+a+nixie+tube+clock
And if you are for the Build (and a long video) watch this one -
Life is exploring and learning
Just a caveat for those who make their own resistive voltage divider. make sure that the voltage at the junction of the resistors does not exceed 5V, and also that it idoes not go negative.
(those conditions may fry your Arduino)
HJ
hj
Does this change the voltage limit felt on pin A0 from 5.0 down to 4.096 or can it still allow the sense voltage to go as high as 5.0V?
It goes down to 4.096 volts maximum.
What changes did you need for the sketch to work using the external voltage reference since we are now using the AREF pin instead of the internal vRef?
See both the video and article for a description of the analogReference command, I'm surprised you missed that as I definitely went into detail about it on both.
😎
Bill
"Never trust a computer you can’t throw out a window." — Steve Wozniak
What changes did you need for the sketch to work using the external voltage reference since we are now using the AREF pin instead of the internal vRef?
See both the video and article for a description of the analogReference command, I'm surprised you missed that as I definitely went into detail about it on both.
😎
Bill
Excuse me, you showed me something that I had never seen before and I was genuinely interested (maybe not so much now). Sorry that I asked such a stupid question. I tell you what. I will revisit this site in a day and erase both of my posts, perhaps you can erase your response and I will never bother you again.
I have watched this section about measuring voltages many times and I fully understand the code you wrote for the original configuration. But after you added the precision reference to the Arduino you never mentioned that the maximum voltage it could measure dropped from 25 to just over 20VDC, nor did
you ever show any modified sketch on how to tell the Arduino to use the AREF pin.
I saw that during the current measurement section you mentioned that adding the precision reference would require changes to the code. In fact, at 21:50 you said, and I quote, "You could use the external AREF pin and put that voltage at the AREF voltage you're putting in. Of course, you'd have to modify the rest of the code over here to let the Arduino know it's using the external one". Silly me, that explains it all.
I posted a similar question on the YouTube channel and there were three others asking the same question. Maybe we all missed something.
You are correct, I filmed it but forgot to put it in the video.
However, I certainly have it in the article -
😎
Bill
"Never trust a computer you can’t throw out a window." — Steve Wozniak
Hello, i am curious about the commercial voltage divider — in particular, about the hookup for use. In the video. Bill states that the output + pin does not need to be connected, however the instructions for the devices state that it should be connected to the 5v power + line. If this is true, why does the system need a separate power connection?
Thanks
limnidytis
The recently seen YouTube video on this topic raised a question in my mind about how frequently the Arduino can measure voltage. It’s of particular interest to me because one of my current ‘tasks’ is to diagnose a 12VDC system device that’s cooking capacitors on a control board. Three failures so far.
The manufacturer suggests voltage spikes but none have been detected using a Fluke 87V or a Fluke 3000 FC using their maxmin functions. But those devices only show sustained voltages over 100 ms and 250 ms, respectively. The obvious tool is an oscilloscope with say a 15V trigger but I don’t have one.
Hence, my interest in your YouTube on voltage detection. I noted you had a 500 ms delay between readings but I assume that’s to avoid a massive data log file. If I could set the reading interval much shorter, say 1 ns, I might be able to write code to test for the highest voltage in some time period and write out only the maximum. That is, maybe with some programming do much the same as with an oscilloscope and trigger.
Does anyone know how frequently the Arduino could read voltages?