Hi, welcome to an Arduino tutorial from Robojax. In this video we are going
to see how we can use this Allegro ACS 712 current sensor that can measure
AC or DC current using Arduino. You can get the code for this project by
clicking on the link below the video in the description which will take you to robojax.com/learn/arduino
Let's get started with this.
My Nam is Ahamd Shamshiri and I am presenting this tutorial from Canada.
using this Allegro ACS712 chip you can measure AC or DC current.
and that is the main important characteristics
Hardware Explained
this is the the module and that's a chip you can buy this as a independent chip
or maybe bite of this module that if sold on eBay. And it has only three pins
it works with 5 volts. You can connect the 5 volts here and then it has just an
output so depending on amount of the current on this side if you look here
the current passes through and there is a howl effect sensor detects the current
and converts it to voltage so proportionally you get voltage from 66
mV per ampere up to 185 millivolts per ampere so for every
ampere that passes through this you get a voltage here and you can even convert
that voltage to a value that you can read it this way this can be used of a
current sensor. This module is offered in 5 10 and 30 ampere. this is a 30 amp per
version that we are going to use. the worth of this module is 13mm and the
length is 31.2mm the height or depth is determined by this
connector with the pin on the other side it will be 13.2 millimeters.
Datasheet viewed (sorry for the wrong title)
now let's have a look at the datasheet this is a low-resistance
and that means that if 2.1 kilo volts or 2100 Vols passes through this is
isolating your circuit from that voltage that you're measuring. The rise time
that it can respond is 5 microseconds and the total output error is 1.5%
at 25 degrees that's very important to know. 1.2 mΩ is internally conductor
conductor resistance current passes here and that resistance here is 1.2 milliohm
pin 1 and 2 is one pin of the connection and 3 & 4 is the other pin of
the connection and this is the chip and this is a pin 1 on their side so pin 1
& 2 is the one terminal & 3 & 4 is the other terminal. so it would be connected and passes
through this. As you can see it there so let me put it accordingly and then this
is a VCC 5 volts will be connected to this pin and there is another filter
between pin 6 and ground with 1 nF so they put also that
capacitor here and for the VCC 5 volts also there is zero point 1 micro farad
capacitor so that's a chip so all the capacitors the two capacitors are here
and then because there is also an LED a power LED when you connect it it will
turn on so they put a resistor for that and that's already there is nothing else
on this module. this module is offered in 5 so this is 5 amperes 20 ampere or 30
ampere and the module is number is the same except the last portion which
is 05 B and 20A and there's 30 and here are the rating that I mentioned
plus minus 5 plus minus 20 which means it has no polarity in any way you can
connect it because it can measure AC or DC and here are the sensitivities
have 185 millivolts per ampere at 5 volts so this is more sensitive
as I current increases we get hundred millivolts per ampere and 30A
ampere it's 66 mV per ampere and here are the formula on how to calculate the current.
and some characteristics and I've collected all these information and
based on those I've written the code so We can measure the current and display it for us
you need further details of this I will provide the link for this and you can
Wiring Explained
download and read it.
And here is the wiring.
supply the positive and negative positive enters(red wire) into the current sensor
and the black wire exists these two goes to the load. because I wanted to
test that with 30 ampere I put thick wire I still this is not thick enough for 30A
should be at least 12 gauge wire but this is 14 gauge I put it and still be
in series with your load. Here is explanation how you measure the current. let's say
this is a battery or power source and this is the load for example in in DC
this is a positive is connected to the load and from this side it comes to the
negative and the circuit is completed. to measure the current you can put the
ammeter either on that side or on this side just cut one of the wire and then
put it so the current passes through the load and then goes through the ammeter
and parameter will measure so this is called for the ammeter and series and
then we put this module in series and a set of ammeter this is our meter so the
current goes here and enters. we can put this on the top the same way. so this is
how you can put this in series with the load to measure the current. here we have
VCC this will be connected to five volts and then grounded this side I've
connected the VCC which is a red one to five volts and then the ground the brown
one is connected here to the ground and then the middle one which is out is
connected to analog zero (A0)
Code explained
let me explain now the code that I've written. we have defined that VIN as analog
zero A0 I will connect this to analog zero the V out or the out pin of the module
will be connected here voltage that you are connecting for power supply is 5
volts in case it varies you have to enter it here. and then we have the model
the model is the determining the characteristic as I mentioned we have 5
ampere 20 ampere version and 20 ampere and each has different
sensitivity so this is the array and we are using the model and I have explained
it as a comment here if you are using 5 ampere version use 0 just enter here 0
and if you have 20 and third one and if you are using 30 ampere use 2 - because
the voltage is drived from the datasheet this is we are getting the
quiescent output voltage QOV as I called it and 0.5 multiplied by VCC that you
entered and this is a float voltage this variable that use internally and then
inside the setup we don't do anything except plant this text initialize the
serial monitor with 9600 baud if you want to see the serial monitor click on
tools -> monitor because this is now not connected showing error. so now it's connected monitor
and make sure that you are setting this accordingly because if you don't
set this properly you will not be able to read the text. after that inside the
loop() there are some calculations so this is a formula we are reading the A0 pin and
then because the input range is 5 volts comparing it to 1023, 1024 steps we are
dividing this and multiplying by the voltage that you are getting so we are
getting the raw voltage and then the raw voltage you are subtracting the
quiescent output voltage. This is the quiescent output
voltage that we calculated here and then plus some error variation offset so you
can experiment with your own module and change this or maybe just set at zero
until you get the proper value and then this is the current. The current is
calculated voltage divided by sensitivity of the model the model that
you entered this is coming from this array so you do not change this array
you do not change anything beyond this point and then we say absolute value of
the current because if it's positive or negative in depending on the polarity
or in terms of AC you see if the current is bigger than current limit I
forgot to mention here I've set the current limit because if you're working
let's say with 30 ampere or 10 amperes sometimes 0.5A or 1A will
be neglected or it would not be your interest. value let's say above one
ampere of 2 or 3 or 5 whatever so you set that one here and we are
checking if absolute value of the current if the current is bigger than
the current limit let's say you set it for one amp if when it's greater than
one amp then we get the current but all in the meantime I'm trying also to print
the voltage that is coming out of this pin subtracted from the supply voltage
this is the voltage you don't need this it's just for reference purpose but this
is the main one you get a current and we set it at two decimal place and on the
screen and we plan the A at the end. if there is if this is not true then we just say no
current and we wait five hundred millisecond and it continues like that
Demonstration
here is now the demonstration of this the power supply to this device is now
three volts and in order to reduce the power I'm trying to use a lower voltage
but the current is our concern so I'm gonna show you the three 3.2 volts
and the current is now zero let me just change here and make it 5 ampere and
then if I turn this on there's a serial monitor for 4.98 and this is the current
that is showing through this device now. now let me just change it to 10A
ampere. Let's go to 6 now it's 6 so that's the amount we can compensate for
that because here is a 6 I'm just incrementing it with hand that
is 7, 6.85 so you can see that the amount of compensation is that's 85
that's 150 milli ampere difference because with within 30 amperes
that's very minimal but we still we can fix it. and where we can fix that is this
and here so we can add some voltage in terms of fixing that
so experimenting with different value I got at 0.12 so that's around 7 ampere so
we are reading now let me just increase it to 8 see if we are getting that's
very good eight and then pay attention here that's
a current and this is what the serial monitor shows this is the current from
the from the sensors. now let me incremented to nine so now it's around
40 milli ampere difference now that's 10 ampere it's very good 11 12 13 14 15 so
that's 15 ampere 14.8 1 now still we are getting some deviation 43 watts
I'm increasing the voltage the voltage should not affect it but on five volts
now let me increase it to 16A. At 16 we are getting 300 less 17 18 19 20 now
it's 20 ampere so around 400 milli ampere and now let me go for 23 so
now this is at 23 ampere. now it's this is big difference now we are reading 21
let me see now the device is very hot because all of the current is passing
through this. and this is too hot this is not made for 30 ampere. the module the
chip is good for that purpose but the module the way they designed it cannot
handle it it was extremely hot I shut it down now
letting the module to cool down and then we will continue it from 23 and we will
see if it can handle 30 ampere. we can set the amount of current that we will not
look at let's say less than 1 ampere will be ignored 1.10 now it shows
no current and I will ignore all those small values
the device has the module is cooled down let me just turn it on what 23 ampere
now that's very close to 23 still 450 or 500
milli ampere so I'm going now for 24 25 26 27 28 29 so 30 ampere we are reading
almost, UFF very hot I just touched it it's extremely hot oh device become hot
it reads incorrect value almost 700mA difference. tell you see it's correcting
itself as soon as it gets cooler the correction goes and it goes towards 11
so now it's 11 enter the device is still a little hot but cooling down you see
when I hold it in my hand the temperature drops and as you can see
it's correcting itself meaning that this module needs to be cooled down or maybe
designed better for the path of current for that reason it cannot be trusted
above 20A thank you for watching this was introduction to Allegro ACS712
currents in search please subscribe so you can get updates of my upcoming
videos and also if you have question or comment please posted at the description
below I try to answer and reply
Ahmad Shamshiri from Canada is thanking you for thumb up the video and clicking on subscribe .
This is the least hat you can do for me. Thank you.
you