Measuring current is simple. Right? You just take a multimeter, connect it to
the two cables, and read the value. If you want to do the same with a Microcontroller
like an Arduino or an ESP, things get a little more complicated. Let’s dig into it to see how it works! And which is the best sensor for our projects. Grüezi YouTubers. Here is the guy with the Swiss accent. With a new episode and fresh ideas around
sensors and microcontrollers. Remember: If you subscribe, you will always
sit in the first row. In this video, we will:
- Look at the different methods to measure current, its advantages, and disadvantages
- We will see where we have to pay attention - We will look at some of the most popular
boards - We will build an example with each board
to see how they can be used - In the end, you should know which module
is best for your project and how to use it As said before: Measuring current is simple. Not as simple as voltage or resistance, because
we have to think about changing one cable to a different connector. And then, usually, we have the choice like
here: mA/uA or 10A. The first question is: Why do we have to change
the connector? And the second question: Why do we need two
different connectors? The first answer is: These multimeters cannot
really measure current, they can only measure voltage. This is why we use Ohm’s law I=U/R.
These meters have a resistor between the left and the right connectors. And they measure the voltage across this resistor,
use Ohm’s law, and show you the current. Simple. But why do we need two connectors? It is because of the “burden voltage.” If you want to know more, you can watch the
video, which is now appearing in the top right corner. It deals with measuring minimal currents like
the deep-sleep currents. In a nutshell: If we draw the full diagram
of our current meter, including a power source like a battery and a load like an ESP8266,
which consumes 100 mA, we can do some calculations. If we want to make it simple for our meter,
we use a 1 Ohm resistor. 100mA leads to a voltage of 100mV, which easily
can be measured by the built-in meter. Unfortunately, this 100mV is lost in this
resistor. If this resistor would be bigger, the ESP
would no more get enough voltage and crash. At 1A, we already lose one volt and at 10A
10 volts, which is, of course, not acceptable. This is the reason for the second connector. Here a much smaller resistor is between the
connectors. Which leads to a lower “burden” voltage. We also have to keep the power dissipation
in mind. If we used a 0.1 Ohm resistor for the 10A
range, it would dissipate: P=R*i2= 10Watt. Quite a junky resistor. Here I have a different multimeter without
these additional connectors for current measurement. But with this clamp. This meter uses so-called “hall sensors”
to measure the magnetic fields. It measures the current contactless and without
the burden voltage. It is essential that you only feed one wire
through the clamp. If you feed both, it shows zero because the
forward and reverse current are the same and cancel each out. How does it work? Current creates a magnetic field around the
cable, and this clamp picks it up. You do not believe me?. If I feed a cable through the clamp, it shows
its current. And if I wind the cable two times through
the clamp, the current doubles. But also if I place a magnet near the clamp,
it shows current from nothing. So, pay attention with magnets. The current range is high, up to 600 A. It
can measure current in both directions, and also AC. But the accuracy is low as we see here. We now saw two ways of measuring current with
multimeters. And here, we have some corresponding sensors
for our MCU projects. To begin with: We can measure currents on
the “low” or on the “high” side. Now you could argue: why do we need an additional
sensor? We can insert a resistor and measure the voltage
across it with one of our analog inputs. Let’s try it on the “low” side first. We insert the resistor, and really, we can
measure a voltage. Now we could connect the analog input of the
Arduino to the resistor. The first question is: On which side? The analog input of the MCU measures the voltage
in relation to the ground. If we connect the input to this side, for
sure, we get zero volts all the time. So we have to choose the other side. If I check with my multimeter, we see that
this voltage is negative compared with the ground. And, unfortunately, analog inputs are destroyed
if they get too much negative voltage. Good I checked before with my multimeter. Now you can say: Add an inverting op-amp,
and you get a positive voltage. This is true. But only if the op-amp has a + and – 5 volts
supply. We would need an additional negative voltage. Not very convenient. So, I would say: We abandon this side and
try the “high” side. This should work better. I insert the same resistor on the high side
and measure precisely the same voltage. The same question here: Where to connect the
input? We remember: The analog input measures voltages
in relation to the ground. So here, it always measures VCC of the MCU. And here, the voltage is higher than VCC. Which, again, cannot be measured by the analog
input. You can say: Easy. Add a voltage divider. Yes, I can add one, and it works. I can add an analog input to the voltage divider
and subtract the two values without a sensor. Victory! We replaced a current sensor with two cheap
resistors! Unfortunately, there is a drawback: The voltage
across the resistor is the “burden” voltage and, as we saw before, it has to be small. Let’s assume a 0.1 Ohm resistor, 100ma consumption,
and 5 volts: The analog input will measure 5.01 /2 volts = 2.505 volts because of the
voltage divider. This results in 512 or 513 in the Arduino
because of the 10 bit ADC. The other will measure the maximum value because
it measures VCC: 1023. We multiply the first times two and subtract
the second value. The difference is 1. If we would increase the load to 200 mA, we
would measure 2.51volts. Which would result in 513 or 514. The difference are two digits for a doubling
of the current. Very insensitive. Again, you can say: Add an op-amp! Yes, here you are right. But let’s look at the selection of sensors
I have here and see how they deal with those problems. The first category, the ones with resistors,
are: - MAX4080
- INA169 - INA219
- INA3321 The second category, the ones with hall sensors
are: - ACS712
- ACS758 - WCS1800
And a last one which somehow fits in-between: The LTC4150 Coulomb counter. Most of the sensors of both categories have
an analog output, and you need an analog input for measurement. The usual MCUs have built-in analog inputs,
and you can use one of those if you are ok with the resolution. If not, you have to add an external ADC. If you create an analog circuit, you are fine
without an ADC, of course. Two of the sensors come with a built-in ADC
and an I2C interface. This is quite handy for MCU projects. Let’s look at the sensors of the first category:
The analog part of all the sensors with resistors are very similar: They insert a small “shunt”
resistor into the top side and contain more or less an op-amp. It is not a standard op-amp, though. Let’s look at the diagram of the INA169. It can handle voltages up to 60 volts. For ease of use, and because it is allowed,
I connect V+ to the input voltage. And, because it only measures the voltage
difference across the small resistor, its Common-mode rejection and its offset voltage
errors have to be very small. For the INA169, we can change two resistor
values: Rs and Rl. Both influence the sensitivity of the chip. The board I have here has Rs= 0.1 Ohm and
Rl=10k. Which leads to a sensitivity of 1 V/A.
Let’s check it out. I connect it to my R6006 power supply to create
some current. The load is an IT8512A. If we get very close to 1 volt for 1 Ampere. At 4A, we only get 3.6 volts. So this configuration is suitable for up to
around 3A. One thing, however, is vital: You have to
connect the ground of the load to the ground of your sensor and your MCU! Otherwise, you do not get correct values and,
if you are out of luck, you destroy your sensor. If we increase the voltage, it does not matter. The reading stays the same. This op-amp is really quite precise! The minimum voltage depends on the current
measured. It goes down to about 3 volts if you remain
below 1A. So it can be used for a single cell Li- Ion
MCU setup. Let’s try the MAX4080. You only have one resistor to play with: Rsense. Instead of changing Rl, you get different
versions of the chip. I have here the T version, which has a sensitivity
of 20 V/V. I did not find a breakout board for this chip. This is why I have it on a breadboard. I use 2 1 Ohm resistors in parallel as Rsense,
which results in 0.5 ohms. 1 A should create 0.5 volts. Multiplied with the sensitivity of 20 is 10
volts. You see, this is a very sensitive chip, and
in this setup, I only can measure up to around 400mA. With a 0.1 Ohm resistor, I could measure around
2A. Its range is from around 3 volts up to 76
volts. Both chips are therefore suitable for small
solar panel projects, for example. Otherwise, I have no preference. Let’s have a look at the INA219. It has a so-called “programmable gain amplifier. Which is comparable with our op-amps from
before. There are two differences: As the name says:
Its gain can be changed, and, as we can see here, its input also can be switched. In addition to the former two chips, it has
a built-in ADC and an I2C interface. This seems to be a neat chip! Let’s look at how we can connect it to our
project. As before, we add a resistor into the “hot”
side, here called “Rshunt” and connect Vin+ and Vin- to this resistor. All as before. Fortunately, we get a ready-made library for
the chip, and we can start it up. It not only shows the current. It also shows a voltage. This is because of this switch: If switched,
the ADC measures the voltage of Vin- to ground. Cool. With these values, we can also calculate power. Just to rant a little: The sketch mixes the
bus voltage and the load voltage. The load voltage obviously has to be lower
than the bus voltage. The breakout board also has a 0.1-ohm resistor,
and the Adafruit sketch offers these three “ranges”:
- 32V, 2A (default) - 32V, 1A
- 16V,400mA So perfect to measure the current produced
by a solar panel or the current used from the battery. Or both using 2 INA219. I also like the I2C interface because we can
put the sensitive analog stuff close to the “action” and use longer digital wires
to our MCUs if needed. This leads us to the INA3221 board. This chip has three sensors like the INA219
on one chip. Which, in principle, would be perfect for
a solar project where, as we saw before, need 2 INA219. Unfortunately, the designer of the board had
a different scenario in mind and connected all Vin+ pins together. Like that, we only can use it in such a configuration:
One battery with three loads. Not very intelligent. This one here seems to be better designed. But I do not have it right now. Before you order, look at the difference here:
The better one has two ground pin, the other one three different pins. BTW: You also find boards with the INA226,
which is very similar to the INA219. It has a slightly higher maximum voltage and
an additional alert pin for overcurrent protection. All five sensors cannot measure reverse currents. Now we come to the sensors which use hall
elements. As we saw before, they have three significant
advantages: 1. The measuring circuit is electrically not
connected to your supply cable. So they work on the “low” side as well
as on the “high” side 2. They should not create a “burden voltage”
because they just use the magnetic field. But two of the three sensors in the test still
have to be inserted inline. So, presumably, they also create a small burden
voltage 3. They usually measure in both directions, and
because of that, sometimes they also can be used to measure AC
If we look at their specs, we see that they are designed for high currents. Which also means that they are not as precise
for small currents. And they can be influenced by magnets, as
I showed with my clamp meter. Let’s start with the smallest chip: The
ACS712. It comes in 3 versions: 5, 20, and 30A. It is only a tiny chip and 30A seems to be
quite a lot for this device, even if it uses 2 pins each for the connections to the load
and the battery. I probably would stick to the 5A version. Also because of the sensitivity of the “stronger”
ones is smaller. Theoretically, you can connect it to mains
because the pins involved in the measuring are isolated from the pins connected to your
MCU. However, I would not trust such a small chip
and small distances. Anyway, I do not like too much working with
mains. Let’ hook it up. The first thing we see is that we get 2.5
volts out at zero amperes, which is half of the 5-volt input voltage. If we increase the current, it adds around
0.18mV per ampere and ends at 3.4 volts. The full swing is about 0.9 volts. If I reverse the direction, the voltage goes
down and ends at around 1.6 volts, also a 0.9-volt difference. So it seems to work. The same company produces a bigger brother. Or is it a bigger sister? The ACS758. You get them for even higher currents up to
200 A. I have the +/-50A type. It should create 40mA/A. Let’s check. Really: 2.5 volts with 0A and 2.7volts at
5A. I really need a more potent Power supply to
test this beast. While I go and dig for a stronger power supply,
you can hit the thumbs-up button, or subscribe, if not done yet. And really, I found one which is good for
20A. So we can continue. The result is as expected: Around 3.3 volts
at 20A. So the sensor seems to work. And the distances are also much bigger. So if you want something for mains, this is
probably the better choice. The last one, the WCS1800, looks a little
like my clamp meter. It can be “sleeved” into a mains cable
without cutting it. Its range is 35A. It shows 2.45 volts at 0A and 3.7V at 20A. So the sensitivity is around 60mV/A. For a
mains scenario, I would use this one. Also because I do not need to cut a wire,
which legally is not allowed everywhere. The last board is a little special. They call the LTC4150 a Coulomb counter. It is a simple device which is attached to
a battery. The chip counts the “charges” which go
into and come out of the battery. It can be used to calculate the charging status
of a cell in %. The chip simply generates an interrupt signal for each charge. According to another pin, the MCU gets the
direction of the charge. If the battery is charged, it adds it, and
if the battery is discharged, it subtracts it from the actual percentage. So it is a combination of two current sensors
and one voltage sensor. Summarized:
- Today we tested two types of current sensors: The “shunt” type which measures a voltage
across a small resistor and hall sensors which are electrically isolated from the power cable
- The “shunt” types only work on the “high” side and create a “burden voltage”
- They are electrically connected to the power source and do not work for mains
- They also only can measure current in one direction
- Their range is adjustable, but usually only up to a very few amperes
- Because of this small range, their precision is higher
- You also get them with a built-in ADC and an I2C interface. An ideal combination for low-power microcontroller
projects like solar power. These chips can also measure the voltage
- You even get the INA3221 with three built-in channels. Perfect if you want to measure more than one
current. Pay attention to which version you order! - The “hall” sensors are made for higher
currents and therefore less sensitive and less precise
- You get them for very high ampere ranges up to 200A
- They can be used on the high as well as on the low side, and they also can measure
currents in both directions - Most of them still have to be electrically
looped into the power line. I would not trust the smaller ones for mains
applications - The WCS1800 works with a completely isolated
hall sensor What are my favorites? Definitively the INA219 or, if I need more
than one of them, the INA3221. For analog projects, I would probably use
either the INA169 or the MAX4080. For the ACS712 and the ACS758, I do not see
a lot of needs, because I have no projects with big motors. For Mains projects, I probably would use the
WCS1800 because of its strict separation. That was all for today. As always, you find all the relevant links
in the description. I hope, this video was useful or at least
interesting for you. If true, please consider supporting the channel
to secure its future existence. Thank you! Bye