All these modules are used to measure current with the Arduino.
Today we will go over all of them and check an example of each.
I will share with you the connections and the code for each example so if you want to
use the same module, just download the files from my website.
Depending on the project, I sometimes use one or another option and that’s why I want
to show you each. So let’s get started.
What's up my friends, welcome back!
The first option to measure current is to directly
use the Arduino to do that, using one of its ADCs on pins A0 to A5.
Let’s say that our testing load will be this DC motor.
By Ohm’s Law, the current is voltage divided by resistance, so let’s add a resistance
to our load.
In order to not dissipate too much power, let’s use a low value resistor, such as
0.5 ohm so I will put two of these resistors in parallel for that.
The circuit that we need to make is something like this with the DC motor in series with
the resistor.
So the current will pass through the load and out resistor and all we have to do is
to measure the voltage drop on that resistor.
Since current is voltage divided by the resistance value, and we know this value to be 0.5 ohms,
getting the current is very easy.
We measure the voltage drop with the Arduino ADC connected on pin A0.
The code is very simple.
We measure the voltage drop with analogRead and divide it by 0.5 ohms and we get the current
value.
We multiply that by 1000 in order to get mA instead of amps.
I upload this code and let’s give it a test.
We have the load in series with the resistor and we supply let’s say 12V to the circuit.
To compare results, we also add a multimeter in series.
As you can see the multimeter shows a current value of almost 300 mA.
When I run the monitor of the Arduino, we get this value.
So the measurement is pretty decent.
The measurement precision is based on the Arduino ADC precision, which is only 10 bits,
which is not that much.
To get a way higher precision, we could use the same setup but with an external ADC such
as the ADS 11 15.
This one has 16 bits resolution, which is a lot higher than the Arduino internal ADCs.
We connect this module like this to the Arduino on pins A4 and A5 for SDA and SCL since this
module is using and i2c communication.
In the code, to use this module we need to install this library so download it from below
and install it to your Arduino IDE.
We start the i2c communication with the module and using this function we can read the voltage
on the resistor.
Then, again we divide it by 0.5 ohms and we get the current but this time with a lot more
precision.
I run the code and I get again a decent current value, the same as my commercial multimeter
and this time we have a lot more precision.
Look, when I increase the load, both values are increasing the same.
But you see, 0.5 ohms is quite a lot for high current values.
Imagine you measure 5 amps for example.
That equals to a voltage drop of 2.5V over the 0.5 ohms resistor.
And that equals toa wasted power of 12.5 watts and we don’t want that.
That’s why usually, shunt resistors are very small, around 0.1 ohms or even lower.
This for example is a high power resistor I’ve used for my power meter tutorial and
this is of 0.01 ohms, which is a very low value.
And this one here is another shunt resistor that I’ve used with my full sine inverter.
Is just a piece of metal with a known resistance of only 10 milliohms.
So using lower value shunt resistors equals to a different problem, the voltage drop will
also be smaller and the Arduino ADCs might not be able to read such low values.
That’s why is a great idea to use the 16 bits ADC in order to measure voltage values
of only a few mV with decent precision.
And that was the second option for measuring current with Arduino.
Now if you don’t want to make your own circuit with a shunt resistor, use external ADCs and
so on, you can use a module like this one that already has everything you need.
It has a resistor of 0.1 ohms and this IC.
This is the IN A2 19 power monitor.
This IC already has inside it a gain amplifier and an ADC.
It can measure the current at the load, the supply voltage and the voltage at the load,
so with those values it could also measure the power.
It could measure up to 26V and 3.2 amps of current and with an internal ADC of 12 bits,
the resolution is of 0.8mA.
To use it we have to connect it to the load like this, in series and respecting the positive
polarity.
Then go to the Arduino IDE and open the library manager.
Search for the INA 219 and install this library from adafruit.
Open from examples the get current code.
As you can see, we have 4 functions to obtain the shunt voltage, the bus voltage, the current
and the ower.
And we also calculate the load voltage.
Upload the code to the Arduino and we make another test.
As you can see, I run the monitor and we get all the values.
This is such a simple way of measuring current but is limited to values below 3.2 amps.
You could use multiple modules like this one at the same time.
To change their i2c address, we can use these pads here.
And that was the third option to measure current.
Now this module has a big brother, the INA 32 21.
This one is the same but it has 3 channels.
Basically you can read the current of 3 channels at the same time, for example the current
of a brushless motor.
In my case, I’ve bought this module because I want to make some tests with it for my FOC
driver.
This driver PCB is controlling a triple phase motor and this IC would be great for measuring
the current of each phase.
The connections would be something like this.
And for the code, just go to the library manager and install the INA 32 21 library.
Go to examples and open this code, and is quite of the same.
We use the get current function or the get voltage function to measure the values for
channel 1, 2 and 3.
And that’s it.
You have the schematic and code on electronoobs.com The next option is probably the easiest one.
We use a hall effect sensor such as the ACS 712.
I use this module all the time but it also has some downsides.
The ACS 712 comes in 3 models.
The 5 amps one, 20 amps and 30 amps and depending on that value, the resolution is different.
For example, the 5 amps module will output 185mV for each amp of current.
All we have to do is to measure that output with the Arduino ADC.
So we would connect it like this in series with the load and the output is connected
to the Arduino ADC on A0.
The code is very simple.
We measure the voltage from the module and subtract 2.5V because this IC could measure
both positive and negative current and the middle point of 2.5V is for 0 amps.
Then we divide it by the resolution, which in this case is 185mA.
And that’s it.
I run the code and give it a test.
As you can see I run the monitor and we get the current value the same as on my multimeter.
And this module works with high voltage as well as for example 230V from the home outlet
since is based on hall effect so is insulated from the Arduino.
One thing to have in mind, this module is affected by magnetic fields because is based
on hall effect.
For example, if I place a magnet on top, the current readings are way different.
Is also affected by the magnetic field of the motor so maybe is not a good option for
highly magnetic projects, for example, the FOC project that uses magnets and brushless
motors with also powerful magnets.
But the IC is so easy to use, that’s why I’ve used it all the time for my PCBs.
For example, my arduino based multimeter is using that chip to measure current.
I've also used it for my MPPT controller and a lot of other projects.
Now the module is big but you could use directly the IC and look how small it is.
And you don’t need a shunt resistor or anything else, just the hall effect IC and a small
filtering capacitor of 1nF.
The resolution is decent and again, it would get better by using an external ADC of 16
bits instead of the default Arduino ADC.
But this one could measure up to only 30A.
What if we want more?
Well that’s why we have the ACS 758.
This could measure 200 amps.
For example, this module is for 50A but we would also have the 100 amps and 200 amps.
And the B stands for bidirectional, so it could measure both negative and positive values.
The rest is the same.
This would be the connection to the load and Arduino.
And this would be the code.
We define once again the resolution, which for the 50 amps module is 40 and these other
values are for the rest of the models in case that you use a different one.
Then we get the raw voltage and we calculate the current.
That’s it.
I run this code and again, we can see the current value on the monitor but the value
is a bit off because this is for 50 amps but I only use 300mA.
But it works.
Now for the 200 amps model, the only part I don’t like are the connectors.
They are a bit too small to handle such a high current value.
So if you make your own PCB, consider making these pads bigger.
And the last method I want to show you for measuring current is the non-invasive one.
This doesn’t have to be connected in series with the circuit.
We can place this one on top of the wire that we want to measure.
I’ve made a full tutorial on a non-invasive probe and how to make a homemade one with
Arduino.
Basically, we have a ferrite core inside and a coil.
The passing AC current through the measured wire is inducing current into that coil.
We measure the voltage drop and by knowing the ratio, we get the current value.
For example this one gives 1 volt for each 15A of current.
And if you search on AliExpress for example, you can find different sizes and shapes.
You could even make a homemade one using a ferrite core and some copper wire.
Or you could even use a ferrite core and a hall sensor as I’ve used for my homemade
non invasive probe for the oscilloscope.
But if you don’t use a hall sensor, this only works for AC current.
So check my previous tutorial on the homemade current clamp and learn how to use this with
Arduino.
There are a lot of other options for measuring current but pretty much all options are based
on a shunt resistor method, hall effect method or non invasive transformer.
Those are the main 3 methods to measure current and the rest are only versions of amplifications,
ADC reading, gain, size, shunt value, etc.
You have each example and more, on electronoobs.com so check the links below.
I hope that you have learned something new and if so consider giving me a like or comment
below.
Thanks again and see you alter guys.