DIY Current Sensor for Arduino

31K2918

Intro: DIY Current Sensor for Arduino

Hello there, hope you are doing good and in this tutorial I will be showing you how i made a current sensor for Arduino using some very basic electronic components and a home-made shunt. This shunt can easily handle large magnitude of current, around 10-15 Amps. The accuracy is also pretty good and I was able to get very decent results while measuring low currents around 100mA.

STEP 1: Gathering the Required Parts

The main parts you would need for this build is a Shunt along with the operational amplifier IC. For my application I am using the IC LM358 which is a dual OP-AMP 8 pin DIP IC of which I am using only one of the operational amplifier. You will also be needing resistors for the Non-inverting amplifier circuit. I have chosen 320K and 10K as my resistances. The choice of your resistance completely depends upon the amount of gain you want to have.Now the OP-AMP is being powered by the 5 volt of the Arduino. So we need to make sure that the output voltage from the OP-AMP when the full current is passing through the shunt should be less than 5 volts, preferably 4 volts to keep some margin of error. If we choose a gain which is very high enough then for a lower value of current, the OP-AMP will go into saturation region and only give 5 volts beyond any current value.So be sure to choose the value of amplifier gain appropriately. You would also require a prototyping PCB or breadboard to try this circuit. For the micro controller I am using the Arduino UNO to acquire the input from the amplifier output. You can choose any equivalent Arduino board you want.

STEP 2: Making Your Own Shunt Resistor

The main heart of the project is the shunt resistor used to provide the small voltage drop. You can easily make this shunt without much of a hassle. If you have a thick solid steel wire then you can cut a reasonable length of that wire and can use as a shunt. Another alternative to this is to salvage shunt resistors from old or damaged multi meters just like shown over here.The current range you want to measure largely depends upon the value of the shunt resistor. Typically you can use shunts in the order of 8 to 10 milliohms.

STEP 3: Circuit Diagram of the Project

Here is the entire theory as a summery and also the circuit diagram of the current sensor module showing the implementation of the non inverting configuration of the OP-AMP providing the necessary gain. I've also attached a 0.1uF capacitor at the output of the OP-AMP to smooth out the output voltage and reduce any high frequency noise if it may occur.

STEP 4: Bringing It All Together...

Now its finally time to make the current sensor module out these components. For this I cut out a small piece of veroboard and arranged my components in such a way that I could avoid the use of any jumper wires or connectors and the entire circuit could be connected using direct solder joints. For connection of the load through the shunt, I used screw terminals, which makes the connections much more neat and at the same time makes it much more easy to switch/replace different loads for which i want to measure current. Make sure you select the screw terminals of good quality which are capable of handling large currents. I've attached some pictures of the soldering process and as you can see the solder traces came out pretty well without use of any jumper or wire connector. This made my module even more durable. To give you a perspective of how small this module is I kept it along with an Indian 2 rupee coin and the size is almost comparable. This small size enables you to fit this module in your projects easily. If you can use SMD components, the size can even be reduced.

STEP 5: Calibrating the Sensor to Give Correct Readings.

After construction of the entire module here comes a slight tricky part, calibrating or rather coming up with the necessary code to measure the correct value of the current. Now essentially we are multiplying the voltage drop of the shunt to give us an amplified voltage, high enough for the Arduino analogRead() function to register. Now the resistance being constant, the output voltage is linear with respect to the magnitude of current passing through the shunt. The easy way to calibrate this module is to use an actual multimeter to calculate the value of current passing through a given circuit.Note this value of current, using the arduino and the serial monitor function, see what is the analog value that is coming( ranging from 0 to 1023.Use the variable as float data type to get better values ). Now we can multiply this analog value with a constant to get our desired current value and since the relation between the voltage and current is linear, this constant will be almost the same for the entire range of current, though you might have to do some minor adjustments later on. You can try with 4-5 known current values to get your constant value. I will be mentioning the code I used for this demonstration.

STEP 6: Final Conclusions


This current sensor works pretty well in most DC powered applications and has an error of less than 70 mA if calibrated properly. How ever there are some limitations of this design, at very low or very high currents, the deviation from the actual value becomes significant. So some modification of the code is necessary for the boundary cases. One alternative is to use an Instrumentation amplifier, which has precise circuitry to amplify very small voltages and can also be used in the high side of the circuit. Also the circuit can be improved by using a better, low noise OP-AMP. For my appliation it works well and gives repeatable output. I am planning to make a wattmeter, where I would be using this shunt current measurement system. Hope you guys enjoyed this build.

13 Comments

Hello,
I just have a quick question, in your code you have "amp=val*0.015426". What does "0.015426" represent?
Also, do you have the code for SPI display?

Thank you in advance
Hello there, thanks for the knowledge.
Could the same design apply for AC current measurement using shunts
thanks.
I think the ideal diagram goes like this?
bro i made this circuit according to your diagram.but after connecting my multimeter from output pin to ground im getting a unstable voltage spikes from 1v to 20v and it cannot im unable to stable it even after connection 100nf cap .please help me
make sure connection are proper and grounds are respective grounds.ie 5v and 5v's grounds to capacitor and opamp (not the source ground), also ensure load is connected in between shunt and source properly,an alternate diagram given below.
Dont understand the shematic:LM 358 has 8 pin ,in shematic only 4.
Where is the another 4?
Total 5 pins are shown, 2 pins are for power( Vcc and Gnd). The remaining 3 pins are of the OpAmp: inverting input, non inverting input and output. The remaining pins are not used here
Hey first of all thanks for this such a great tutorial but I want to ask how accurate and precise this sensor is, regards with the real and calibrated current meters
Hey, thanks for sharing your feedback! Since I have used a shunt made of a steel wire,even I was unaware of the resistance of that. So what I did was that I powered a load with this current sensor in the circuit and also I attached a multimeter with it, so basically the current shunt and multimeter both were in series with the load. In this way I can measure the output voltage of OpAmp and the actual current flow from Multimeter and I noted those values and did the same test for a couple of different load. In this way I got a relationship between output voltage and actual current .I used this relationship in the Arduino code. So the reading will be almost similar to that of the multimeter :)
Nice clear presentation. Simple and usefuf when the need arises. Thanks for sharing
Interesting, thank you for sharing your process!