How To Measure DC Current With A Microcontroller - Embedded Lab
How To Measure DC Current With A Microcontroller - Embedded Lab
| Embedded Lab
Microcontrollers usually don’t have specific ports for measuring currents, but they do have ADC
channels through which you can measure analog voltages of a certain range. This means a dc
current can be indirectly measured by a microcontroller’s ADC channel by first converting the
current into voltage. The simplest way of doing this is to place a resistance in series with the
current path and measure the voltage drop across it. But hold on, if you place an additional
resistance in the circuit, it will affect the original current. Therefore, we need to use a very small
value resistance so that it’s effect in the circuit current won’t be significant.
Resistors with values less than 1 ? are available in electronics stores. Depending upon the
amount of current in the circuit, you need to choose proper power rating for the resistor.
Suppose, if you pick 0.47 ?, and the maximum current in the circuit is about 2 A, then the
resistor should have the capacity of dissipating 4 x 0.47 ? 2 Watts of heat.
You can also make a small value resistance by yourself. Yes, by simply winding a copper wire
into coil. I have made one from a 5 ft long solid copper wire (22 AWG) with plastic insulation on
outer side, as shown below.
embedded-lab.com/blog/how-to-measure-dc-current-with-a-microcontroller/ 1/10
15/05/2020 How to measure dc current with a microcontroller? | Embedded Lab
Now lets measure its resistance. The resistance can be measured directly with a digital
multimeter. My digital meter shows its value equal to 0.3 ?. This measurement may have higher
uncertainty as it is very small and most multimeter does not show values beyond 1 decimal digit.
The resistance can also be measured using Ohm’s law. Connect a 47? ? resistor in series with the
coil resistance (Rs) and supply a 5V power as shown below. Next, measure the voltage across Rs
and current through it separately using the multimeter. In my case, I found the measured
voltage and current values to be 24.1 mV and 84.3 mA, respectively. This gives the resistance of
the coil is about 0.286 ?.
Now, suppose that the range of current to be measured using this coil resistance is from 0-2 A.
Then the voltage drop across the coil resistance will be somewhere from 0 – 0.57 V. Because of
its low dynamic range, this voltage signal may not be accurately measured with a
microcontroller’s ADC module. So this requires some sort of voltage scaling. One way to achieve
that is by using an operational amplifier circuit as shown below.
embedded-lab.com/blog/how-to-measure-dc-current-with-a-microcontroller/ 2/10
15/05/2020 How to measure dc current with a microcontroller? | Embedded Lab
In the circuit, Rs is the low value current sensing resistor (our coil resistor) which is connected in
series with the load resistor. Our objective is to derive the load current (I). The low voltage drop
across Rs is amplified by the non-inverting amplifier. The gain of the amplifier is set by Rf and Ri
resistors. For Rf = 10 K, and Ri = 1.3 K, the gain of the amplifier would be about 8.7. This is
enough to linearly scale Vs (0-0.57 V) to Vo (0- ?5 V). Now you have 0-5 V voltage signal that
corresponds to 0-2 A current through Rs. This voltage signal is now more appropriate for ADC
conversion with Vref = 5 V.
=> I = Vo/2.49.
For 10-bit ADC with Vref = 5 V, resolution = 5/1024 = 0.0049 V. For input signal Vo, the ADC
O/P will be Vo x 0.0049. Thus,
98 4 0
1346
embedded-lab.com/blog/how-to-measure-dc-current-with-a-microcontroller/ 3/10
15/05/2020 How to measure dc current with a microcontroller? | Embedded Lab
Related Posts
Tagged amp meter, current meter, Opamp, shunt
34 COMMENTS
I think there is a slight mistake in this statement “For input signal Vo, the ADC O/P
will be Vo x 0.0049”. ADC converts/measures analog value in terms of
steps(digitally coded) with each step size equal to its resolution (i.e. 0.0049V) so
for ADC output we need to calculate number of steps that would be contained in a
physical quantity. So instead of multiplying Vo we got to divide by ADC’s resolution
i.e Vo / 0.0049.
Reply
CAn u help me regarding making of true rms digital voltmeter using micro
controller measuring both ac and dc. with frequency 100 hz. and dc ranges from 0
to 200v levels for dc 0-10,0-50, 0-100?
Reply
hiiii i’m doing microcontroller.i have to sense the voltage and current from pv
panel.after that i shold give these voltage and currnet sensors to microcontroller.
can u please suggest me which model voltage and current sensors are best to use
and which port i conncet in AT MEGA 16 Microcontrooler
Reply
hii… i need to amplify my voltage across the resistor which is 20-30mV to 2-3V.
I’m using your above circuit as reference and i have used a 1K(Ri) and an 100K(Rf)
for getting an output voltage of 3. but i’m not able to achieve this. please help me
out.
Reply
Hi
Reply
Hey,
That’s a pretty nice post. A good one, describing the intricate details as well! Liked
it.
Reply
Thanks, Paul
Reply
Hi Paul,
The second schematic makes things easier because only one point of connection is required
to measure the voltage across Rs and therefore calculate the current.. this is because the
other pin of the resistor is connected to the common ground
Reply
embedded-lab.com/blog/how-to-measure-dc-current-with-a-microcontroller/ 5/10
15/05/2020 How to measure dc current with a microcontroller? | Embedded Lab
very helpful tutorials, what if we use opto-coupler instead of maybe a very small
resistor. The theory is: The LED will produce variable light to photo-transistor
depending on the current flowing, then voltage across the photo-transistor will be
proportional to the current flowing to the load. Does my proposal practical?
Reply
Take care of temperature as cooper wires is very sensitive and may false the
measument as the measured current warms the wire itself or ambient temperature
varies. That’s the reason you should use materials that have low coefficient of
resistance variation with temperature.
Reply
hi,
i want to measure car battery current 20 amp up to 200 amp ,plz give me a
complete solution
Reply
Hi,
I’d personally love to see a similar one to this, but measuring resistance, as in my
case I’m willing to measure it when my soldering iron is off, and current when it’s on.
Regards,
Reply
Hello, I wanted to ask you which opamp did you used to measure current
?. Because you conected it directly to VCC and ground. I use the TL072 and i need
to feed it with (+)Vcc and (-)Vcc.
Reply
embedded-lab.com/blog/how-to-measure-dc-current-with-a-microcontroller/ 6/10
15/05/2020 How to measure dc current with a microcontroller? | Embedded Lab
@Leandro,
I have used the similar current measuring technique in my power supply
project described here: http://embedded-lab.com/blog/?p=1953
I used LM324 in this project.
Reply
Reply
Hello your tutorials are very helpful. may you please guide me how to measure
current fro AC power supply using a microcontroller. Thanks in advance
Reply
Thanks a lot.
Reply
I found your article very helpful in an stepper motor application… But now I have
two questions.
1. I see your shunt made with two cables, one orange (primary) and a white. The
white was added to reach the 5ft long or is another feature made in?
2. How many feets would use for an 18 AWG cable? The reason is that’s the only I can buy in my
area.
Thanks
Reply
Tropero,
1. The two color wires are connected together in series to make the 5 ft long,
and no hidden features.
2. I can’t tell you exactly how long will you need for 18 AWG cable. I measured
the resistance with a digital multimeter, and you can do the same. I would
embedded-lab.com/blog/how-to-measure-dc-current-with-a-microcontroller/ 7/10
15/05/2020 How to measure dc current with a microcontroller? | Embedded Lab
rather suggest you to use a small value resistor (0.47 Ohm, 5 W) instead, if it is available in
your area. Please read the following articles (that uses this technique) and the comments
from other readers.
http://hackaday.com/2011/03/27/multi-function-bech-power-supply/
http://embedded-lab.com/blog/?p=1953
Reply
I understand the overall concept and I understand the op-amp architecture but I
am having trouble with the application of the solution.
I need to measure the load to a motor, this motor is driven via a L293. I have
inserted the 0.47ohm shunt into the 0v return line from the motor driver (the two
0v pins) but I am getting results that are not resprentative of the current.
I have the pic corrently returning ADC value that represent 0v-5v (ie 0 – 1024). The L293 and
the motor works as expected with my bench power supply showing 0.0 thru to 0.4 amps. I need
the pic to ensure I do not exceed 0.4 amps when fully assembled.
Reply
I understand the overall concept and I understand the op-amp architecture but I
am having trouble with the application of the solution.
I need to measure the load to a motor, this motor is driven via a L293. I have
inserted the 0.47ohm shunt into the 0v return line from the motor driver (the two
0v pins) but I am getting results that are not resprentative of the current.
I have the pic corrently returning ADC value that represent 0v-5v (ie 0 – 1024). The L293 and
the motor works as expected with my bench power supply showing 0.0 thru to 0.4 amps. I need
the pic to ensure I do not exceed 0.4 amps when fully assembled.
Reply
can i use MID 400 to measure the voltage level of ac mains?bcoz i have seen this ic mid 400 and
after seeing the application note i realised that it can be use determine whether ac is on or off
but i want to measure the exact ac voltage..i dont want to use a transformer.
reply soon
embedded-lab.com/blog/how-to-measure-dc-current-with-a-microcontroller/ 8/10
15/05/2020 How to measure dc current with a microcontroller? | Embedded Lab
Reply
Reply
its 24 v
Reply
Ok, you can use this technique. But here’s something you need to consider.
Suppose you have a shunt resistor, Rsh = 0.47 Ohm. The 10 A of current will
create a voltage drop of 4.7 V across Rsh. This means the available output
voltage will be only 24-4.7 = 19.3 V. If that’s ok for your load, then no
problem. If you don’t want the output to fall that low, you can consider using a
different value for Rsh.
Reply
Reply
Reply
hello,
your post is extremely helpful in my project.i have a doubt that if i want to sense
10 amp of current from power supply then would this circuit work???
embedded-lab.com/blog/how-to-measure-dc-current-with-a-microcontroller/ 9/10
15/05/2020 How to measure dc current with a microcontroller? | Embedded Lab
Reply
Nishu,
The technique is applicable to measure any current but there are few things to
be considered. First, the resistance used for current sensing must have enough
power rating to dissipate the heat developed due to the current. Suppose, if
you are using a .47 Ohm series resistor to sense current up to 10 A, it must be
able to dissipate 100 x 0.47 = 47 watts of heat. Similarly, the voltage drop across the resistor
for 10 A current is 4.7 V, which is close to 5V, and may not require additional amplification.
What is your source voltage for 10 A current? The voltage drop across the current sensing
resistor could significantly affect the output voltage in your case.
Reply
What is the correct op-amp to use? What IC is best for 5v and less than 1amp?
Most grateful.
Reply
embedded-lab.com/blog/how-to-measure-dc-current-with-a-microcontroller/ 10/10