Shunt Resistors and Input Pins

I’m trying to measure the current going through a DC motor so that I can implement some kind of velocity control, but I’m a bit stuck as to how to implement the circuit.

I have a low resistance resistor in series with the motor which is powered by a motor shield on an Arduino Mega, and I’m trying to measure the voltage across the resistor. The motor shield provides a maximum of 12V and the motor draws up to 1.2A.

However, I’m not sure how to set this up with regards to input pins and grounds. The lowest resistance resistor I have available is 0.47 ohms, is it likely Ill need to go out and find something lower?
Thank you in advance!

Your resistor should drop just over half a volt at 1.2A.
You may want to look at using the internal Aref, which is around 1.2V, IIRC.

Good idea, I’ll use the internal Aref.

I was more stuck on how to wire up the resistor to the arduino however, any ideas?

Resistor to ground other end to the arduino analogue input and the -ve of the motor. Wire the +ve of the motor to the +12V power and the 0V of the power supply to the arduino ground..

Like this?

Yes.

You might like to put a bit of protection on the analogue input just in case you get a higher voltage on it. http://www.thebox.myzen.co.uk/Tutorial/Protection.html

Thanks a lot, this works really well.

However, I'm having some odd readings from the analogue inputs. They will often give a reading of 0 volts every other time they are read i.e. when the program is run they give something like 0 40 0 40 0 40 0 40.

Any ideas? This only happens when I use the voltage reading from the resistor for control, it seems fine when the voltage source is constant and I simply print the voltage over the resistor. The code for the loop loop is void loop() { VshuntR=analogRead(Ipin); error=r-VshuntR; Vin=error*K;

digitalWrite (dirA, HIGH); analogWrite (speedA, Vin);

delay(100); Serial.println(VshuntR);

}

Many thanks

Are you sampling the "LOW"s of your PWM?

Some offhand suggestions:

  • Add an idling diode across the motor (to catch the backlash from the inductive load) - best use a fast shottky

  • Measure the voltage over the shunt using a RC filter (e.g. 1K, 1..10uF, make RC time larger as PWM cycle). This kills the spikes and gives you nice average current, and protects the analog input.

If it is a std commutating DC motor, there will be agressive spikes during PWM switchovers. Connecting a scope can be very instructive..

1K + chip internal clamping diodes will handle most overvoltage spikes if any.

FWIW I connect all off-board wiring from the chip with at least 1K's - it gives the cpu a fighting chance against ESD. YMMV

Something also to note about shunts: Unless you are using an actual shunt resistor (specially made from a special allow, with very low resistance), your measurements can and will vary with temperature, run time, etc. It may not be enough to bother you or what you are doing, but it is something to be aware of, all the same.

That easy,let me find some information to you