#321 7 Sensors tested: Measuring Current with Microcontrollers (Arduino, ESP32, ESP8266)

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 bit more complicated let's stick into it to see how it works and which is the best sensor for our project great see you tubers 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 port we will build an example with each port to see how they can be used and in the end you should know which module is best for your project and how to use it I 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 milli ampere micro ampere or 10 ampere the first question is why do we have to change the collector and the second question why do we need two different connectors the first answer is these multimeters can not really measure current they only measure voltage this is why they use Ohm's law for the current measurement these meters have a resistor between the left and the right connector 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 Burton 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 around 100 milli ampere we can do some calculations if we want to make it simpler for our meter we use a 1 ohm resistor 100 milliampere leads to a voltage of 100 millivolts which easily can be measured by the built in meter unfortunately this 100 millivolt is lost in this resistor if the resistor would be bigger the ESP would no more get enough voltage and crash 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 zero point 1 ohm resistor for the 10 ampere range it would dissipate 10 watts it would need quite a chunky 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 the reverse current are the same and cancel each out how does it work current creates a magnetic fields around the cable and this clamp picks it up and if I wind the cable 2 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 ampere it can measure current in both direction 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 project 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 at an inverting op-amp and you get a positive voltage this is true of course but only if the op-amp has a plus and minus 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 at a voltage divider yes I can add one and it works I can add an analog input to the which 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 zero point 1 ohm resistor 100 milliampere consumption and 5 volts the analog input will measure 5.0 1/2 equals 2.5 or 5 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 milli ampere we would measure 2.5 1 volts which would result in 513 or 514 the difference are two digits for a doubling of the current very insensitive again you can say at an op-amp yes here you're right but let's look at the selection of the sensors I have here and see how they deal with those problems the first category the ones with the resistors are max 40 80 and I n a 169 and I and a 219 and and I n a 3 3 2 1 the second category the ones with all sensors are the ACS 712 the ACS 758 and the WCS 1,800 and a last one which somehow fits in between the LTC 4150 coolant counter most of the sensors of both categories have an analog output and you need an analog input measurement the usual mcs have built-in analog inputs and you can use one of those if you are okay 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 I square C interface this is quite handy for MCU project let's look at the sensors of the first category the analog part of the sensors where the resistors are very similar they insert a small shunt resistor into the topside and contain more or less an op-amp it is not a standard op-amp though let's look at the diagram of the ia 169 it can handle voltages up to 60 volts and because it only measures the voltage difference across the smaller resistor it's common mode rejection and it's offset voltage errors have to be very small for the i na 169 we can change to resistor values RS and RL both influence the sensitivity of the chip the board I have here has RS 0.1 ohms and RL 10k which leads to a sensitivity of 1 volt per ampere let's check it out I connected to my are 600 6 power supply to create some current the load is an IT 85:12 a we get very close to 1 volt for 1 ampere at 4 ampere we only get three point six volts so this configuration is suitable for up to around 3 ampere 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 1 ampere so it can be used for a single cell like own MCU setup let's try the max 4080 you only have one resistor to play with our sense instead of changing RL you get different versions of the chip I have here the t version which has a sensitivity of 20 volt per volt I did not find a breakout port for this chip this is why I have it on a breadboard I use 2 1 ohm resistors in parallel as our sins which results in 0.5 ohms 1 ampere should create 0.5 volts multiply it with the sensitivity of 20 it is 10 volts you see this is a very sensitive chip and in this setup I only can measure up to around 400 milli ampere with a 0.1 own resistor I could measure around 2 ampere both chips are therefore suitable for small solar projects for example otherwise I have no preference let's have a look at the eye n/a 219 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 analog to digital and an I square see 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 site here called our shunt and connect the in + + V in – 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 V in – to grant cool with these values we can also calculate power just to rant a little the sketch mixes the bus voltage add the load voltage the load voltage obviously have to be lower than the bus voltage the breakout port also has a zero point 1 ohm resistor and the Adafruit sketch offers these three ranges so it is perfect to measure the current produced by a solar panel or the current used from a battery or both using two I na 219 I also like the I square C interface because we can put the sensitive analog stuff close to the action and use longer digital wires to our MC use if needed this leads us to the iin a three to two one board this chip has three sensors like the i na 219 on one chip which in principle would be perfect for a solar project where as we saw before need to I n a 219 unfortunately the designer of the board had a different scenario in mind and connected all be in + 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 badly designed but I do not have it right now before you order look at the difference here the bet one has two ground pins and the other one three different pins by the way you also find boards with the I and a 2 2 6 which is very similar to the I and 8 to 19 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 whole elements as we saw before they have three significant advantages 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 they should not create a burden voltage because they just use the magnetic fields but two of the three sensors in the test still have to be inserted in line so presumably they also create a small burden voltage they usually measure in both directions and because of that sometimes they also can't 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 precise for small currents and they can be influenced by magnets as I showed with my clamp meter let's start with a small chip the ACS 712 it comes in three versions five twenty and thirty ampere it is only a tiny chip and 30 amps seems to be quite a lot for this device even if it uses two pins each for the connection to the load on the battery I probably would stick to the 5 ampere 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 our MCU however I would not trust such a small chip and small distances anyway I do not like too much working with means let's 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.18 milli volts per ampere and ends at 3 point 4 volts the full swing is about 0.9 volts if I reverse the direction the voltage goes down and ends at around 1 point 6 volts also 8.9 volt difference so it seems to work the same company produces a bigger brother or is it a bigger sister the ACS 758 you get them for even higher currents up to two hundred amperes I have the plus minus 50 amp ere type it should create 40 milli ampere per ampere let's check really 2.5 volts with zero ampere and 2 point 7 volts at 5 ampere I really need a more potent power supply to test this beast while I go and take 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 20 ampere so we can continue the result is as expected around 3.3 volts at 20 ampere 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 WCS 1800 looks a little like my clamp meter it can be sleeved into a mains cable without cutting it its range is 35 ampere if we hook it up to the 20 ampere I chose to 0.45 volts at 0 ampere and 3.7 volts at 20 ampere so the sensitivity is around 60 millivolt per ampere for a mains scenario I would use this one also because I do not need to cut a wire which is legally not allowed everywhere the last part is a little special they call the LTC 4150 a Coulomb printer 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 percentage the chip simply generates a interrupt signal for each charge according to another pin the MCU gets the direction of the charge if the battery is charged it adds and if the battery is discharged is subtracted 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 whole 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 means they also only can measure current in one direction their range is adjustable but usually only up to a few amperes because of this small range their precision is higher you also get them with a built-in ADC and an I square C interface a ideal combination for low-power microcontroller projects like solar power these chips can also measure the voltage you even get the eye and a three two to one with three built-in channels perfect if you want to measure more than one current pay attention to which version you order the whole sensors are made for higher currents and therefore less sensitive and less precise you get them for very high ampere ranges up to 200 ampere 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 powerline I would not trust the smaller ones for mains applications the WCS 1800 worked with a completely isolated whole sensor what are my favorites definitely the eye and a 219 or if I need more than one of them the eye and a three-to-two one for analog projects I would probably use either the I n/a 169 or the Max 40 80 for the ACS 712 and the ACS 758 I do not see a lot of needs because I have no project with big motors for mains projects I probably would use the WCS 1,800 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

You May Also Like