I have the 4WD Dagu 5 Rover with a Dagu 4 channel motor controller and I have got that working perfectly with an Arduino UNO and it runs very well.
I need to control 2 more DC motors however and so I went and got another motor controller and wired it the same using different outputs from my Arduino. I used very similar code for this DC motor as I did for the 4 wheels of the Rover.
HOWEVER, I can only seem to get the DC motor to rotate in 1 direction and not the other using "HIGH" and "LOW" outputs. The "High" output is the only one that the motor seems to respond to and if I use a "LOW" output the the motor does nothing.
Here is my code, if you see a problem then could you please let me know. It is in regards to the function "Lift_Forks" which does not seem to be responding.
//Car System-Motor controller 1
int pinPWM_fl = 3; //ch1
int pinPWM_bl = 5; //ch2
int pinPWM_fr = 6; //ch3
int pinPWM_br = 9; //ch4
int pinDIR_fl = 2; //ch1
int pinDIR_bl = 4; //ch2
int pinDIR_fr = 7; //ch3
int pinDIR_br = 8; //ch4
//Bridge System-Motor controller 2
int motPWM_f = 10; //ch1
int motPWM_b = 11; //ch2
int motDIR_f = 12; //ch1
int motDIR_b = 13; //ch2
void setup() {
Serial.begin(9600);
pinMode(pinPWM_fl,OUTPUT);
pinMode(pinPWM_bl,OUTPUT);
pinMode(pinPWM_fr,OUTPUT);
pinMode(pinPWM_br,OUTPUT);
pinMode(pinDIR_fl,OUTPUT);
pinMode(pinDIR_bl,OUTPUT);
pinMode(pinDIR_fr,OUTPUT);
pinMode(pinDIR_br,OUTPUT);
pinMode(motPWM_f,OUTPUT);
pinMode(motPWM_b,OUTPUT);
pinMode(motDIR_f,OUTPUT);
pinMode(motDIR_b,OUTPUT);
}
void loop() {
delay(4000);
Move_Forward(2500);
Pause(1000);
Turn_Right(720);
Pause(1000);
Move_Forward(1500);
Pause(1000);
Turn_Left(760);
Pause(1000);
Move_Forward(2200);
Pause(1000);
Put_Down(40);
Pause(1000);
Move_Backward(200);
Pause(1000);
Lift_Forks(1000);
Pause(1000);
Move_Forward(2200);
Drop_Forks(x);
Pause(3000);
Move_Backward(200);
Pick_Up(x)
Pause(5000);
Move_Forward(200);
Pause(1000);
Turn_Left(760);
Pause(1000);
Move_Forward(5000);
Shut_Down();
while(1) { }
}
void Move_Forward(int x) {
digitalWrite(pinDIR_fl,LOW);
digitalWrite(pinDIR_bl,HIGH);
digitalWrite(pinDIR_fr,LOW);
digitalWrite(pinDIR_br,HIGH);
analogWrite(pinPWM_fl,255);
analogWrite(pinPWM_bl,255);
analogWrite(pinPWM_fr,180);
analogWrite(pinPWM_br,180);
delay(x);
}
void Pause(int x) {
analogWrite(pinPWM_fl,0);
analogWrite(pinPWM_bl,0);
analogWrite(pinPWM_fr,0);
analogWrite(pinPWM_br,0);
delay(x);
}
void Turn_Right(int x) {
digitalWrite(pinDIR_fl,LOW);
digitalWrite(pinDIR_bl,HIGH);
digitalWrite(pinDIR_fr,HIGH);
digitalWrite(pinDIR_br,LOW);
analogWrite(pinPWM_fl,255);
analogWrite(pinPWM_bl,255);
analogWrite(pinPWM_fr,255);
analogWrite(pinPWM_br,255);
delay(x);
}
void Turn_Left(int x) {
digitalWrite(pinDIR_fl,HIGH);
digitalWrite(pinDIR_bl,LOW);
digitalWrite(pinDIR_fr,LOW);
digitalWrite(pinDIR_br,HIGH);
analogWrite(pinPWM_fl,255);
analogWrite(pinPWM_bl,255);
analogWrite(pinPWM_fr,255);
analogWrite(pinPWM_br,255);
delay(x);
}
void Move_Backward(int x) {
digitalWrite(pinDIR_fl,HIGH);
digitalWrite(pinDIR_bl,LOW);
digitalWrite(pinDIR_fr,HIGH);
digitalWrite(pinDIR_br,LOW);
analogWrite(pinPWM_fl,255);
analogWrite(pinPWM_bl,255);
analogWrite(pinPWM_fr,180);
analogWrite(pinPWM_br,180);
delay(x);
}
void Shut_Down() {
analogWrite(pinPWM_fl,0);
analogWrite(pinPWM_bl,0);
analogWrite(pinPWM_fr,0);
analogWrite(pinPWM_br,0);
}
void Put_Down(int x) {
digitalWrite(motPWM_f,HIGH);
analogWrite(motDIR_f,255);
delay(x);
}
void Lift_Forks(int x) {
digitalWrite(motPWM_f,LOW);
analogWrite(motDIR_f,255);
delay(x);
}
void Drop_Forks(int x) {
digitalWrite(motPWM_b,LOW);
analogWrite(motDIR_b,255);
delay(x);
}
void Pick_Up(int x) {
digitalWrite(motPWM_b,HIGH);
analogWrite(motDIR_b,255);
delay(x);
}