Introduction: 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.
- Arduino Uno or equivalent and programming wire
- OP- Amp LM358
- Jumper wires
- 100 KOhm resistor
- 220 KOhm resistor
- 10 Kohm resistor
- Veroboard or Zero PCB board
- Shunt(8 to 10 milliohms)
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.