Shield-MD10A

LINIX Brushless, VEXTA Brushless, RC Servo, DC Geared, Linear, Stepper, Tamiya.....

Shield-MD10A

Postby Galiphat_1G » Mon Jun 29, 2015 7:13 pm

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);
}
Galiphat_1G
Greenhorn
 
Posts: 2
Joined: Mon Jun 29, 2015 7:01 pm

Re: Shield-MD10A

Postby Galiphat_1G » Mon Jun 29, 2015 8:44 pm

Found mistake, should have used "if else statement instead of second if statement.
Galiphat_1G
Greenhorn
 
Posts: 2
Joined: Mon Jun 29, 2015 7:01 pm

Re: Shield-MD10A

Postby ober » Tue Jun 30, 2015 5:47 pm

Good to hear that!
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1486
Joined: Wed Apr 15, 2009 1:03 pm


Return to DC Motor

Who is online

Users browsing this forum: No registered users and 4 guests

cron