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!
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..
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;
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.