Hi!
I'm working on a project where I want to sense the current of a DC-motor to know when it has reached it's end points.
I'm using the Aduino Motor Shield, reading the value on A0. The problem is that this value is unchanged when the motor is stopped, running or running with high load. It always reads the same, 850 when using channel A and 1018 when using channel B.
I don't know if I have a broken shield or if there's some other problem.
Any help would be greatly appriciated.
// Motor A
const int dirA = 12;
const int pwmA = 3;
const int brakeA = 9;
const int currentA = A0;
// Buttons
const int leftBtn = 7;
const int rightBtn = 4;
// Globals
int currentLow = 2000;
int currentHigh = 0;
void setup() {
// put your setup code here, to run once:
pinMode(dirA, OUTPUT);
pinMode(pwmA, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(leftBtn, INPUT_PULLUP);
pinMode(rightBtn, INPUT_PULLUP);
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
if (!digitalRead(leftBtn)) {
digitalWrite(brakeA, LOW);
digitalWrite(dirA, HIGH);
digitalWrite(pwmA, HIGH);
} else if (!digitalRead(rightBtn)) {
digitalWrite(brakeA, LOW);
digitalWrite(dirA, LOW);
digitalWrite(pwmA, HIGH);
} else {
digitalWrite(brakeA, HIGH);
delay(100);
digitalWrite(brakeA, LOW);
digitalWrite(pwmA, LOW);
digitalWrite(dirA, LOW);
}
int current = analogRead(currentA);
if (current < currentLow) {
currentLow = current;
}
if (current > currentHigh) {
currentHigh = current;
}
Serial.print(current);
Serial.print(' ');
Serial.print(currentLow);
Serial.print(' ');
Serial.println(currentHigh);
}