Page 1 of 1

Shield-MD10A

PostPosted: Mon Jun 29, 2015 7:13 pm
by Galiphat_1G
Hello,
I am having some trouble with trying to get my motor to run off two push button switches. I want it to run in one direction when one is pushed and in the other direction when the other one is pushed. I am using an Arduino Uno along with the MD10A motor shield (http://www.cytron.com.my/p-shield-md10).

The problem I am encountering is that the motor will run fine in one direction, but when I push the other button the motor runs extremely slowly (Less than 1rpm). I have switch the push buttons both manually and by changing the pin call outs. Below is the code I am using, the motor is a 9v electric motor.

//This is the test code:
const int switchPin = 5;
const int pinPwm = 3;
const int pinDir = 2;
const int limitCounter = 4;

int switchState = 0;
int counterState = 0;
void setup() {
pinMode(pinPwm,OUTPUT);
pinMode(switchPin,INPUT);
pinMode(pinDir,OUTPUT);
pinMode(limitCounter,INPUT);
Serial.begin(9600);
}
void loop() {
switchState = digitalRead(switchPin);
if (switchState == 1) {
digitalWrite(pinDir,LOW);
analogWrite(pinPwm, 50);
Serial.println("fwd");
}
else {
digitalWrite(pinDir,HIGH);
analogWrite(pinPwm, 0);
}

counterState = digitalRead(limitCounter);
if (counterState == 1) {
digitalWrite(pinDir,LOW);
analogWrite(pinPwm, 50);
Serial.println("rev");
}
else {
digitalWrite(pinDir,LOW);
analogWrite(pinPwm, 0);
}
delay(10);
}

Re: Shield-MD10A

PostPosted: Mon Jun 29, 2015 8:44 pm
by Galiphat_1G
Found mistake, should have used "if else statement instead of second if statement.

Re: Shield-MD10A

PostPosted: Tue Jun 30, 2015 5:47 pm
by ober
Good to hear that!