DIY Current Sensor - 2.0

26,668

142

17

Introduction: DIY Current Sensor - 2.0

About: Electronic hobbyist : Love to explore the field of applied electronics and embedded systems with a motive to contribute and share creative ideas. Green Energy enthusiast

Hello there! I hope you all are fine and in good health. This instructable is about making your own current sensor that is compatible with Arduino and most other widely popular microcontrollers. This project features a compact design and an all SMD component based circuit, making this sensor module very compact for it's range.

This current sensor can easily be used for measuring currents up to 15 Amps constant and can even handle about 20 Amps peak. I had previously built a shunt current measurement module using a home made shunt but it had a few limitations- The wire was quite long which may not be suitable for small devices. It also got rusted over time and one major drawback was heating at higher currents even at 10 amperes. Well, this module solves almost all of these problems in a more efficient design.

This was a great learning project for me and I hope it will be same for you as well!

Let's get started :)

As with previous tutorials, the detailed videos is attached here:

https://youtu.be/FzYkN5Y9bjc

Step 1: Gather Your Components

This build is a pretty simple build and does not require a whole lot of components. How ever a few essential things are required to make the PCB since it is a SMD based circuit.

Here are all the components you will need:

  1. LM358 general purpose dual OP-Amp IC (SMD version)
  2. 2.2 KiloOhm resistor (222- SMD code)
  3. 100 KiloOhm resistor (104-SMD code)
  4. 1uF SMD capacitor - 2
  5. 100nF or 0.1uF SMD capacitor - 1
  6. 5 MilliOhms shunt resistor (R005 SMD code)
  7. Screw terminal - 1
  8. 3 pin male header - 1
  9. Multimeter
  10. Small piece of copper clad board
  11. Ferric Chloride solution for etching
  12. Hand drill or a mini drill with bits of 1.2mm and 0.8 mm diameter
  13. A print out of your circuit on a glossy paper for toner transfer(I'll discuss this in detail in upcoming step)
  14. Pliers, tweezers and other accessories
  15. Small plastic container for performing the etching process
  16. Fine tip soldering iron
  17. Good quality solder and flux
  18. A bit of patience to solder SMD components!

Step 2: The Shunt Resistor

The main component and probably the most crucial one in this build is the shunt resistor. It is by this resistor that we measure a small voltage drop and then amplify to measurable limits for the arduino or any other microcontroller. It is important that the value of this resistor is small enough as to not create a significant voltage drop in the load circuit in which we are trying to measure current. Small resistance in the range of milliohm also ensures that the total power dissipated is very small and thus the resistor itself does not heat up. The voltage drop is quite small for a microcontroller to directly measure it, so we are using the OPAmp as an amplifier.

The shunt used in my circuit has the label -R005 which means it has a resistance of 5 MilliOhms- perfect for our use!

I got this out of an old laptop battery pack but you can easily get it online or from local electronics store.

Step 3: A Little Bit of Theory

The main concept of shunt based current measurement system to create a very small voltage drop across the shunt resistor and then to amplify if using suitable amplification techniques whose output can then be measured by a microcontroller or some other data acquisition system.

Considering that the resistance of the shunt remains fairly constant, it is safe to say that the voltage drop is directly proportional to the current through the load using the Ohm's Law concept (V= I * R).

This small voltage drop is then amplified by an Op-Amp configured as a non-inverting amplifier. As you can see from the figure that the gain is determined by two resistors Rf and Rin.

In my application Rf= 100K and Rin= 2.2K so we have a gain of approximately 46, as per the formula.

Note that out shunt resistor lies between the load and the round connection and the positive supply is directly connected to the load. This topology is called low side measurement. This has a good advantage of having the ground common to both the load and the measuring circuit so the small voltage drop across the shunt is directly measured with respect to ground.

Step 4: Designing the Circuit

With the theory in mind, it was now time to design a suitable schematic and then create a PCB layout for the same.

I have used the Easy EDA online software for designing this simple circuit and then exported the PDF of the layout which I will have to print for the toner transfer method.

I have attached the PF for your reference in case you want to use the same.

Step 5: Cutting the Copper Board to Shape

After completing the schematic and layout design, I exported the layout and printed it to scale such that the print size matches the actual PCB size as intended. This print was then my reference to cut out a small piece of copper board according to size. I marked the boundaries using permanent marker and then cut the copper board using a dremel tool. You can also use a hacksaw.

Step 6: Sanding Off the Oxide Layer

Copper when left exposed to air for a long time tends to form a oxide layer which can effect the overall conductivity. it is important that this oxide layer is removed using a very fie sand paper of a scrubber.

Gently use the sand paper to remove the oxide layer. Make sure to do it gently because applying too much pressure will cause the actual copper layer to deplete which is not what we want.

At the end we will have a shiny copper clad board as shown ready for toner transfer.

Step 7: Toner Transfer

For the toner transfer method, we actually need to mirror the PCB layout and then print the mirrored layout in a glossy paper. In the 1st image you can see the actual PCB layout and the corresponding mirrored version that we will use to flip and eventually transfer the toner ink onto the copper surface so that we again get out original layout on the board.

Keep the glossy paper faced down onto the copper board and using a iron apply constant heat and pressure so that all the toner ink gets transferred to the copper.

After that dip the board in water and after 10 minutes slowly peel off the paper leaving behind only the ink on copper. Do this very gently without using any pointed object.

Step 8: Etching the Board

Now with the toner set on the board, it is time to remove the unwanted copper off the board. For this I will be using the popular ferric chloride solution.

I used a small container and poured a little amount of the solution and then immersed the board into the solution and kept it in there for 10 minutes with occasional stirring to speed up the process. You can see that the unwanted copper is etched out in the last image.

Step 9: Cleaning the Board

After etching process, te ink needs to be removed from the copper layout for which I have used some acetone and using some cotton gently removed the ink, exposing the copper layout.

Step 10: Drilling Holes for THT Components

I have used a hand drill with a bit size of 0.8mm for the male header pins and 1.2 mm for the screw terminal.

Step 11: Soldering the Components

With our PCB now finally complete, let's move onto the soldering process. As you can see that I have placed all the components in their respective places for soldering.

Unfortunately I do not have a hot air station so I will have to do the soldering using an iron. This process is a bit tricky and required patience. The main thing here is to have a fine tip soldering iron so as to allow good contact with SMD pins but not have to much solder on the tip so as to short two pins together, basically, finer the tip the better results you'll get.

Step 12: And Done!

After about 15 minutes, the soldering process was complete for the SMD components. All that is left is to solder the Screw terminal and the header for which there are two possible orientations. one is to solder on the copper side where as the other option is to ass those components to the other side. This is more clear through images attached in this step. I went ahead and soldered them on the copper side itself. this requires some skill but keeps the overall form factor nice.

Step 13: Coding and Calibration

With our hardware potion complete it is now time for coding the microcontroller and calibrating the sensor values to give accurate readings.

To keep things simple I have used the Arduino Nano which I have programmed in the Arduino IDE itself to keep things simple. You can easily port this code to your favourite microcontroller environment.

Okay the main code can be broken down into the following steps:

  • Initialize the libraries for the OLED display(I have used the Adafruit library for this)
  • Configure analog pin 0 as input
  • Read the analog value from the output of the OP-Amp at analog pin 0
  • Multiply the analog value with the calibration factor to get the correct current reading in Amps(or milliamps)
  • Display the value in the OLED display

Now as we know that the OP-Amp acts as a non inverting amplifier in our circuit and produces a voltage that is proportional to the voltage drop across the shunt. This voltage is then measured using the Arduino's ADC which gives out a number between 0 and 1023 (10 bit resolution of the ADC in arduino). Well this number is certainly not equal to the actual current value so some mathematical manipulation must be done in software to get the accurate value. This is where a Multimeter comes to play. Most multimeters can accurately measure current upto 10 Amps so this can be used as a reference to determine our calibration factor.

The trick is to use a small load along with a power supply with a miltimeter and our current shunt in series with the load.

So here the multimeter can measure the actual current consumed by the load and from our current shunt module, we can get the corresponding analog value via arduino.

The calibration factor can this be calculated as:

Calibration factor = (reading in multimeter / analogRead value of Arduino )

We can re write this as:

current reading = analogRead value * calibration factor and this is exactly what I have done in my code!

Check this line:

float val=analogRead(A0);
float amp=val*0.015426; // this is the calibration factor

I hope this makes sense.

Step 14: Breadboard Testing-Measuring Phone Charging Current

With the hardware and software setup all completed, the final thing remaining is to test out the functionality and the accuracy of the current sensor module. For this I have used a 12 volt battery pack and a 5 volt buck converter module to charge my mobile phone and eventually measure the charging current with both- a multimeter and our current sensor to compare the values. The OLED screen displays the analogRead value as well s the actual current consumed by the load.As you can see in the final image that the values match up with that of a multimeter.

This project was a success!

I hope you guys like this project. Feel free to take the PCB layout and the code and use it for yourself. If you have any suggestions or doubts you can post in in the comment below and I will be happy to respond :)

Do watch the entire tutorial video so that you get a much better understanding of the entire project and while you are there, consider subscribing to my Youtube channel as well :)

Till then see you in the next instructable!

1 Person Made This Project!

Recommendations

  • Big and Small Contest

    Big and Small Contest
  • Game Design: Student Design Challenge

    Game Design: Student Design Challenge
  • For the Home Contest

    For the Home Contest

17 Comments

0
skywiredvt
skywiredvt

Question 2 months ago

Nice Instructable! I have built this on a breadboard and it works great! I tried to solder it to a perf board, and it stopped working properly. It only gives out the raw data of "20.0" and sometimes spits random numbers out for a second, and then goes back to displaying 20. I have checked all wiring, and used same components, but to no luck.
Do you think you may know the reason why it is doing this?
Thank you

temp1.JPGWIN_20230117_18_05_16_Pro.jpgWIN_20230117_18_06_58_Pro.jpgWIN_20230117_18_07_00_Pro.jpgWIN_20230117_18_08_07_Pro.jpgWIN_20230117_18_08_17_Pro.jpg
0
altehetler
altehetler

2 years ago

Thanks for this great job, but I have a question ❔ How can this sensor be used outside of an Arduino? Thank you

0
Utsav_25
Utsav_25

Reply 2 years ago

Hey, thanks for your feedback! Yes this sensor can definitely be used outside of Arduino.Any microcontroller having an ADC feature can be used with this sensor.

1
Mic100
Mic100

2 years ago

good job thank you :)

0
Utsav_25
Utsav_25

Reply 2 years ago

Thanks a lot :)

1
StephanvanB
StephanvanB

2 years ago

great job. I love the fact that you even did the board yourself.

0
Utsav_25
Utsav_25

Reply 2 years ago

Thanks a lot for your feedback!

1
RomasP
RomasP

2 years ago

Great instructable. Only there is one not very good thing in schematic. Unused operation amplifier in any case can not be left unconnected. Usually not needed amplifier is connected as voltage follower, output connected to -IN (inverted input) and +IN (not inverted input) connected to GND. In your case this unused operation amplifier part can be used as voltage follower for separating main amplifier from arduino input. If amplifier is left unconnected as in your chematic in some cases it can start to oscillate ant make some interference to measurement part. This oscillation can start at some moisture, light, surrounding electrical field values so it is absolutely unpredictable. This oscillation can depends even on how good board is washed after etching:)

0
Utsav_25
Utsav_25

Reply 2 years ago

Hello Romas! This was some great piece of information that you shared, thanks! Now that I think about it, it can surely make a difference while working with audio or RF applications.Will definately take this into consideration for any upcoming projects :)

1
privatier
privatier

2 years ago

The shunt resistor needs to dissipate more than 1 Watt when 15 Amps are flowing through. The larger SMD resistors 12x6mm have a typical power rating of 0.125 Watt; thus the resistor will get very hot, and its temperature dependence affects the accuracy of the result.
The LM358 has a maximum offset of 7 milliVolt, which causes an error in the measurement of 1.4 Amp, for a resistor of 5 milliOhm.
I suggest using a resistor with much higher wattage and a low temperature coefficient, and an opamp with much lower offset, or even better a current sense amplifier, which is designed for such an application.

0
Utsav_25
Utsav_25

Reply 2 years ago

Hello, thanks a lot for sharing this information. Yes there is slight offset in measurement of current when no load is attached. Initially I measured the no load output of the OP-Amp and subtracted the same in the Arduino code to get results which were pretty close and probably for experimentation it worked just fine. I will try and improve the circuit. Regarding the heat dissipation and power rating I had momentarily used the module for 15 Amps and the resistor just becomes a tad warm when 10 Amps are flowing through the module. I have crosschecked the reading with a multi meter and the readings are pretty close. I am not targetting very accurate readings here so for me a couple of milliamps here and there is okay.
Thanks again for letting me know!

1
ssadh
ssadh

2 years ago

Great Project!!!

0
Utsav_25
Utsav_25

Reply 2 years ago

Thanks a lot!

1
westjessie
westjessie

2 years ago

I love this clearly delineated project. It’s way beyond me right now but I hope to learn how to do all the wonderful Arduino projects such as this eventually.

Meanwhile, I am a professional communicator and I noticed a typo where typos most often occur... in the heading! See attached photo. “Shut” (in bold) should be “shunt.” I’d be interested to know if you can edit an instructable after you create it.

PS: Years ago I was working in a corporate job and I spent a huge part of my budget on a fancy four-color brochure. The whole thing had to be tossed and re-done when my boss discovered a typo in my title! That’s when I learned that headings and subject lines and titles are the most vulnerable to being overlooked when one proofs a piece of any kind of writing.

😏Please forgive any typos in this comment. Sadly, instructor balls (lolol Siri! You should be ashamed!) INSTRUCTABLES does not play well with the iPhone’s Dynamic Type feature. So my old eyes are trying to type in a font so small this whole comment could be etched on the head of a pin!

0FE5EE05-A24D-4A9C-BA90-B390F8CFE978.jpeg
0
Utsav_25
Utsav_25

Reply 2 years ago

Thank you so much westjessie! Thanks a lot for bring so kind to point out this typo! At a quick glance it was so easy to ignore this and now when I saw that it really looked pretty stupid.
Thanks for your help! I jave corrected it

0
randofo
randofo

2 years ago

Nice project!

0
Utsav_25
Utsav_25

Reply 2 years ago

Thanks a lot!