Hi,
I have written a sketch to measure the motor current that is attached to a Arduino motor shield V3. I think I have the code right.
the datasheet says it is calibrated to read 2A at 3.3V. I notice that the values were not steady, is this because we are giving it a PWM signal and the current is also like a PWM signal?
So in the code I did the following:
// Arduino UNO Motor Shield V3 Test
const int motorCurrentInAPin = A0; // Analog input pin that the current sensing A is attached to
const int motorCurrentInBPin = A1; // Analog input pin that the current sensing B is attached to
int motorCurrentA = 0; // Variable for motor current A
int motorCurrentB = 0; // Variable for motor current B
void setup() {
Serial.begin(9600); // Initialize Serial Communications
}
void loop() {
motorCurrentA = analogRead(motorCurrentInAPin); // Read motor current A
motorCurrentB = analogRead(motorCurrentInAPin); // Read motor current B
Serial.print("Pin A0 = " ); // Print the value at Pin A0
Serial.print(motorCurrentA); // Print the value at Pin A0
Serial.print("\t Pin A1 = "); // Print the value at Pin A1
Serial.print(motorCurrentB); // Print the value at Pin A1
motorCurrentA = map(motorCurrentA, 0, 675, 0, 2000); // Scale motor current A, 0 = 0V = 0 ma, 675 = 3.3V = 2000 mA
motorCurrentB = map(motorCurrentB, 0, 675, 0, 2000); // Scale motor current B, 0 = 0V = 0 ma, 675 = 3.3V = 2000 mA
Serial.print("\t Current A = "); // Print the actual motor current A value
Serial.print(motorCurrentA); // Print the actual motor current A value
Serial.print(" mA"); // Print the actual motor current A value
Serial.print("\t Current B = "); // Print the actual motor current B value
Serial.print(motorCurrentB); // Print the actual motor current B value
Serial.print(" mA"); // Print the actual motor current B value
delay(2); // Delay 2 ms
}