# measure current with microcontroller

Discussion in 'General Electronics Chat' started by Mad Professor, Sep 13, 2012.

Apr 15, 2009
133
1
Good day all.

As per the title name, I am looking to measure current with microcontroller.

My basic understanding of how to measure current with microcontroller, is that you use a shunt resistor in line of the load, and measure the voltage across the shunt.

Most of the shunt resistors I have seen on eBay at 75mv at max current.

Now the question is how would I use one of the 75mv shunt resistors so that I can measure current both ways (-10A to +10A) with microcontroller?

Thanks for time.

Best Regards.

2. ### MrChips Moderator

Oct 2, 2009
12,624
3,451
There is nothing special about a shunt resistor except that it is of extremely low resistance.

For example a current of 10A flowing through a resistance of 10mΩ will have a voltage drop of 100mV. This can be amplified and level shifted to suit the range of the ADC.

A simpler solution would be to buy a digital ammeter that has a serial output and interface that to the microcontroller.

A lot depends on what you are attempting to do. Can you tell us more about your application?

Apr 15, 2009
133
1
I am looking at building a datalogger for use with my solar system.

During the day I charge the deep cycle batteries, and at night I run lighting from the batteries.

So I want to monitor and log, battery voltage, charging current (at day) and load current (at night).

This is why I want to be able to read +current and -current with the microcontroller.

4. ### Dodgydave AAC Fanatic!

Jun 22, 2012
5,142
768
Only way i can see this working is with 2 shunt resistors with two current monitor circuits, one measuring DC charging, the other measuring DC discharging, using an op amp as the sensor on each shunt into the micro,

so the micro would have two inputs, one input would increase voltage in the charge cycle,
and the other input would increase in the discharge cycle.

So at the point at which neither input has any voltage , the batteries are neither in charge or discharge.

so your programme would keep polling the inputs to see which is active.

OR, use a current monitor
http://www.ce-transducer.com/CE-IZ04-E.asp

Last edited: Sep 15, 2012
5. ### ErnieM AAC Fanatic!

Apr 24, 2011
7,435
1,625
Shunt resistors are special resistors designed for very exact readings of large currents. They are a four terminal device that provide Kelvin connections such that the voltage measured is as an ideal measurement as possible. EBay has several pages of them.

I've been looking at solar chargers for a 150W panel / 300 AH storage battery system and am considering two systems from Morningstar. These systems (and all I have seen) keep charging current readings separate from load current. That's a good feature when you are using power during the daytime.

To read current from the shunts I would suggest a high side current monitor chip such as the Maxim MAX4080. These let you leave the shunts in the + legs in a common ground system and translate the current readings to a ground reference, which is just what a microcontroller needs for an A2D measurement.

Also, as has been mentioned separate currents are easier to measure.

PWM system.

MPPT system.

6. ### russ_hensel Distinguished Member

Jan 11, 2009
820
47
Use the shunt. Amplify the signal to +- 2 volts or so. Shift the level so 0 goes to 2v. ( use op amps for this, circuits are all over the Internet ). Then connect to the ADC of the controller. There are other methods, rectify the voltage and amplify to 0 to 4 volts or so, then use another circuit ( perhaps based on a comparator... could be another op amp ) and feed the polarity into a digital pin on the uC.

7. ### #12 Expert

Nov 30, 2010
16,665
7,310
Same thing, different words: add a dc level so your input senses 2 volts when no current is flowing. When current is flowing, the input will be more or less than 2 volts. That gives direction information and magnitude information with only one resistor and one input pin. This economy of resources is the reason why this is the best answer on this page.

Adding a DC level shift and increasing the sensed voltage from .75 volts to 2 volts is a simple job for an op-amp. The picky part is configuring the microcontroller so that it never mistakes a drift error in the 2 volt level as a current flow.

Oct 2, 2009
5,451
1,066
9. ### crutschow Expert

Mar 14, 2008
13,475
3,362
Here is a bidirectional, high-side current sensor with the zero point offset at 2.5V (with a 5V supply voltage).

Edit: Here is a bidirectional Zetex device that has a unipolor output with no offset, but uses a flag output to indicate current direction.

#12 likes this.
10. ### #12 Expert

Nov 30, 2010
16,665
7,310
Apparently somebody has done this before

IC's dedicated to centering an input for a 5 volt microprocessor...too cool!

11. ### ErnieM AAC Fanatic!

Apr 24, 2011
7,435
1,625
Awesome device... if it had an adjustable gain it would be perfect!

12. ### crutschow Expert

Mar 14, 2008
13,475
3,362
Why do you need adjustable gain? The gain is determined by the value of the shunt resistor.

13. ### panic mode Senior Member

Oct 10, 2011
1,328
305
absf likes this.

Apr 15, 2009
133
1
Thanks for eveyones replies, I do like the idea of an all-in-one chip so I will have to look into that some more.

15. ### ErnieM AAC Fanatic!

Apr 24, 2011
7,435
1,625
I would desire an adjustable gain because the only way to determine gain is by the value of the shunt resistor.

That means the shunt has constraints very possibly detrimental to the rest of the system: you may need a large value shunt to get a large voltage out, and thus loose a significant amount of power.

I've successfully used similar devices where you can set the gain where you need it and much prefer that option.