# How to measure current through H-bridge and geared DC motor using Arduino?

Hi there, what is the best way to measure the current through a gear-motor driven by an H-bridge, using an Arduino analog Input pin?

I have a 12V 1.5A power supply, regulated to 5V using an LM7805 voltage regulator feeding pin#8 (VCC2) of a SN754410 Quadruple Half-H driver.

The direction of the motor is controlled by an Arduino. And I am not using PWM.

I have a 6V gear-motor (DC) attached to the H-bridge.

I have read that you can measure either side of a shunt resistor, but did not know if this was a smart thing to do with this setup? And where would I place this resistor (ie. between the voltage regulator and the H-bridge?) or attached to one of the other pins of the H-bridge?
What size resistor?

My end goal is to stop the motor should it encounter any situations which would cause it to strain.
Like hair getting caught on the motor shaft etc etc. or obstacle which prevents it from turning.

Regards
Scott

Best place for the current sense resistor is between +12volt and 7805 input. 7volt is available there.
Google "Arduino high side current sensor" for suitable breakout boards.
e.g. this one.

The 7805 must be getting very hot. 7volt difference @ 1-1.5A = ~10watt. Did you use a heatsink.

Supply could have been 8- or 9volt, since the motor driver drops a few volts.
And 8- or 9volt is ok on Arduino's Vin.
Leo..

Working on a similar project myself. In my case I wanted to log current from a handful of servos.

Hall effect current sensors are widely available:

Inline resistance is in the milliohms.

They will output an analog signal of up to 5 volts, so you may need to chop that down if you are using a 3V Arduino.

Most of the Hall Effect current sensors I have looked at, return the current as a voltage difference from half of their supply voltage. So if you have 5V, you will get millivolts above or below 2.5V. But if you have three volts, you will get millivolts above or below 1.5V. I don't think you will get a 5V answer from the sensor when its supply voltage is only 3 V.

Most hall effect sensors like that are high current sensors.
Useless for 1Amp.
Leo…

Thanks Wawa,

I was hoping to use a shunt resistor, but what I am worried about is the possibility of destroying the Analog pin.
So if I put the resistor between the power supply and the LM7805, does this mean that 7V will be sent to the Analog Pin??? I did not think that the pin could handle more than 5V? Also,what size resistor would you suggest to get a good reading?

Thank you for the links to the current sensor breakout modules, but I am trying to get my head around this idea of using a shunt resistor and how this method of measuring current works. Still a bit confused.

And yes - I know the power supply was probably not the right one to use, heat sink was definitely needed.
But am just experimenting at the moment with the parts that I have.

Thank you very much for your help so far.

Reading high-side (positive wire) between +12volt and 7805-in without extra active hardware should be possible if accuracy is not a big issue.

You could try a 1ohm (1-2watt) shunt resistor (drops 1volt@1Amp).

One voltage divider from the 12volt side of the resistor to one analogue pin.
And another divider from the 7805 side to another analogue pin.

e.g. 18k from 12volt to analogue pin, and 10k from analogue pin to ground.

That will give you ~4.3volt on each analogue pin if no significant current is used.
And a lower voltage on one, depending on the current draw.

Read the two pins, and subtract the values.
Stop the motor is the resulting value is too high.
Leo..

Thank you Wawa - that makes sense. I will try it and report my findings.

michinyon:
Most of the Hall Effect current sensors I have looked at, return the current as a voltage difference from half of their supply voltage. So if you have 5V, you will get millivolts above or below 2.5V. But if you have three volts, you will get millivolts above or below 1.5V. I don't think you will get a 5V answer from the sensor when its supply voltage is only 3 V.

The sensors I've looked at are 5V. I have these on the way:

http://www.allegromicro.com/~/Media/Files/Datasheets/ACS712-Datasheet.ashx

They have the supply speced at 4.5V min to 5.5 V max. What they will do at 3V I don't know, but it would save a handful of voltage divider resistors if it ran on 3.3V.

I hadn't considered the halfway point as neutral, so thanks for the heads up. +1 to you.

Wawa:
Most hall effect sensors like that are high current sensors.
Useless for 1Amp.
Leo..

ACS 712 will give .1V for 1A. The same as using a .1 ohm resistor, but for virtually no voltage drop. Not so important for 1A but for 2 or 3 A or so, a big deal.

Firstly get rid of the LM7805 completely, its just pointless and generating waste heat.
If the motor is only 6V then simply limit the maximum PWM value to the H-bridge rather
than trying to use a linear regulator to reduce the voltage. The SN754410 is rated to
36V so use the 12V direct into it.

The easiest way to measure the current is a shunt to ground from the SN754410's ground pin,
so long as the voltage across the shunt peaks at 0.5V or less you won't affect circuit function
and you'll have a voltage output you can directly monitor with no extra hardware (although
an opamp would increase the resolution). 0.33 ohm shunt gives about 0.5V at 1.5A.

A high side shunt requires a high-side current monitoring IC to work well, or a hall sensor
chip (but they aren't great for low currents like 1A).

Thank you for all the replies so far.

I have tried a few permutations and combinations so far, and the one I like the best is the one suggested by MarkT - with regard to putting the resistor between the H bridge and ground.
I did not have a 0.33ohm resistor, so I used a 1 ohm instead. This 1 ohm resistor did not provide much variation in readings... the only other lowish value resistor I had hanging around was a 47 ohm resistor. I did not think it was going to work, however, the motor was still able to turn without much loss in performance, and I got a much larger difference in analog readings compared to the 1 ohm resistor.
This allowed me to set a threshold value to stop the motor when the motor strained.

If there is anything wrong with using the larger resistor, please let me know... but otherwise it does seem to be working ??

BTW: putting the 1 ohm resistor between the 12V power supply and the 5V regulator also worked to some extent (i.e I also needed to use a voltage divider to the analog pins), however I noticed a larger variation in readings during normal operation of the motor (i.e no strain). This made it harder to set a threshold value... maybe I needed a different value resistor for this set up also... but I did not try any other resistor values..

I also tried the suggestion to remove the voltage regulator and use PWM to control the motor... this worked quite well, however, later on I will be powering the motor and the Arduino with a power adapter. I just need to get the right one for this circuit, and maybe use the Arduino's onboard voltage regulator (for the control side of the circuit).

I don't see any indication of what Arduino the OP is using. The Arduinos that don't use the Atmega 328 (which is what the Uno uses, unfortunately) can measure differential voltages and include an amplifier which would help with the very low voltage across a shunt resistor.

...R

10 Sep 2015, Edit to clarify that it is the Atmega 328 which has the limitation.

Using an Arduino Nano.

Robin2: do you have any links that show how to do this ? or if you could explain the best way to measure differential voltages ?

ScottC:
Using an Arduino Nano.

Sorry. You're out of luck. The Nano uses the Atmega 328 same as the Uno.

And apologies for not making that clear in my earlier Post - I will edit it.

This YouTube video explains the process.

...R

ScottC:
I like the best is the one suggested by MarkT - with regard to putting the resistor between the H bridge and ground.
I did not have a 0.33ohm resistor, so I used a 1 ohm instead. This 1 ohm resistor did not provide much variation in readings… the only other lowish value resistor I had hanging around was a 47 ohm resistor. I did not think it was going to work, however, the motor was still able to turn without much loss in performance, and I got a much larger difference in analog readings compared to the 1 ohm resistor.
This allowed me to set a threshold value to stop the motor when the motor strained.

If there is anything wrong with using the larger resistor, please let me know… but otherwise it does seem to be working ??

There is some danger in using a large value resistor in the ground line.
In your case, if you keep it <1ohm, it’s probably ok.
You could measure the voltage across the resistor with 1.1volt Aref enabled.
That simple line in the code will give you ~5x the default sensitivity.
100mA motor current will give a digital value of ~100.
Has to be sampled often ofcourse.
Leo…

I suspect that 1 ohm would be far too much resistance for a current-measuring shunt.

I have some 0.005 ohm resistors for shunts to measure the current from some solar panels. But from a measuring point of view the problem is that the voltage drop across them is very small and would need to be amplified for an Arduino.

I have never taken the trouble to use an Arduino with my shunts. I just use my multimeter occasionally.

...R