Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
81 views

How To Measure DC Current With A Microcontroller - Embedded Lab

This document discusses how to measure DC current with a microcontroller. It explains that a microcontroller's ADC can be used to measure the voltage across a low-value resistor placed in series with the current path. This converts the current to a voltage that can be read by the ADC. It provides details on selecting an appropriate sensing resistor and constructing one by winding copper wire. An op-amp circuit is also described to scale the voltage for more accurate ADC readings over a range of currents.

Uploaded by

JEOVADJ
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

How To Measure DC Current With A Microcontroller - Embedded Lab

This document discusses how to measure DC current with a microcontroller. It explains that a microcontroller's ADC can be used to measure the voltage across a low-value resistor placed in series with the current path. This converts the current to a voltage that can be read by the ADC. It provides details on selecting an appropriate sensing resistor and constructing one by winding copper wire. An op-amp circuit is also described to scale the voltage for more accurate ADC readings over a range of currents.

Uploaded by

JEOVADJ
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

15/05/2020 How to measure dc current with a microcontroller?

| Embedded Lab

HOW TO MEASURE DC CURRENT WITH A


MICROCONTROLLER?
Posted on March 1, 2011 by R-B 34 comments |

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.

Current sensing resistance

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

Opamp as a voltage scaler

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.

Vo = 8.7 x I x Rs = 2.49I (Rs = 0.286 ?)

=> 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,

I = ADC O/P x 0.0049/2.49 = 0.00197 x ADC O/P

The current resolution would be therefore 0.00197 A (? 2 mA).

Share on Facebook Share on Twitter Share on Google+

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

Tips and Tricks

34 COMMENTS

DAN March 8, 2016 2:11 pm

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.

Rest of the explanation is fine and very helping.

Reply

ans August 25, 2015 12:52 pm

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

ASHWINI February 5, 2015 2:11 am

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

pali December 11, 2013 5:11 am

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

Pingback: STM32 monitoring motor current | embedded experiments


embedded-lab.com/blog/how-to-measure-dc-current-with-a-microcontroller/ 4/10
15/05/2020 How to measure dc current with a microcontroller? | Embedded Lab

Max July 31, 2013 1:42 pm

Hi

I am required to design a power meter with an atmega8515 but i have no idea


how the adc pins work on it and also how to measure voltages from 2v to 6v and
currents ranging from 0-0.5A.. please help as to how a=the adc works and how to
implement this

Reply

Pingback: Measuring current with microcontroller - Do It Easy With ScienceProg

Mayank February 15, 2013 6:18 am

Hey,
That’s a pretty nice post. A good one, describing the intricate details as well! Liked
it.

Reply

Pingback: Blog J.Schweiss | AVR Tutorials

Paul Land July 14, 2012 7:15 am

I am a little confused why your computer generated schematic shows Rs


connected to Vcc but your hand drawn schematic shows Rs connected to GND
side. Please help!

Thanks, Paul

Reply

RashedKoutayni August 11, 2014 3:11 am

Hi Paul,

Actually no need to be confused as the computer generated schematic


demonstrates the abstract idea of measuring the voltage across the resistor Rs
while the hand drawn schematic shows the practical implementation of it.

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

Tobias May 1, 2012 10:06 am

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

Mario February 13, 2012 7:30 am

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

wajid January 1, 2012 3:57 pm

hi,
i want to measure car battery current 20 amp up to 200 amp ,plz give me a
complete solution

Reply

Eduardo October 28, 2011 6:17 am

Hi,

Very nice and well explained tutorial!

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

Leandro July 16, 2011 5:57 pm

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

R-B July 16, 2011 7:37 pm

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

ardiansyah May 9, 2011 1:49 am

absolutely, this is very help me. many thanks.

Reply

Matiko May 8, 2011 4:34 am

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

tropero April 22, 2011 9:11 am

Thanks a lot.

Reply

tropero April 21, 2011 8:28 pm

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

R-B April 21, 2011 8:46 pm

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

Anobium April 5, 2011 2:26 am

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.

Help please. I have Rl as the L293, Rs at 0.47ohm – where am I going wrong?

Reply

Anobium April 5, 2011 2:24 am

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.

Help please. I therefore have the Rl as the L293,

Reply

nishu March 28, 2011 8:40 am

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

nishu March 28, 2011 6:46 am

HI,I WANT TO MONITOR AC MAINS VOLTAGE THROUGH


ATMEGA16,WITHOUT USING A TRANSFORMER.CAN U PLEASE
SUGGEST ME SOMETHING.
THANX

Reply

nishu March 14, 2011 2:54 am

its 24 v

Reply

R-B March 16, 2011 11:39 am

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

nishu March 10, 2011 11:15 pm

my source of voltage is ac mains,i am converting it to dc using ac to dc converter


and then i have to measure the dc output current going to the load which is
connected after ac to dc converter.so what i hv thought is that i will connect a
current shunt along with current shunt monitor amplifier(ina193).would it work?

Reply

R-B March 11, 2011 1:34 pm

You still didn’t tell me the magnitude of your DC source voltage?

Reply

nishu March 10, 2011 6:16 am

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

R-B March 10, 2011 10:12 am

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

Anobium March 8, 2011 3:02 am

Very good. It was the research I was looking for.

Do you have to use a rail-to-rail op amp?

What is the correct op-amp to use? What IC is best for 5v and less than 1amp?

Most grateful.

Reply

R-B March 8, 2011 8:23 am

Rail-to-rail opamp is preferable. These days I am designing a power supply unit


with voltmeter and ammeter features. I am using the same current sensing
technique for measuring current up to 1 A. I am using LM324 (powered from 5
V) which does not provide rail-to-rail output but you can set the gain such as
the output is around 3 V for 1 amp current and program your A/D conversion
accordingly. I will post it soon.

embedded-lab.com/blog/how-to-measure-dc-current-with-a-microcontroller/ 10/10

You might also like