I am working on a ping pong shooting machine.
I am using x2 12v 775 dc motors.
My power supply is 18,5v 6,5A and will be used in parallel between the two motor controllers.
I am using x2 BTS7960B 43A dc motor controllers.
My problem:
When I start the motors, only motor 1 is spinning. Motor 2 is getting no output voltage from its motor controller. I already checked the pin layouts. They are the same as indicated in the code. Did I do anything wrong in the code that could cause the motor not to spin?
// Motor1
int R_EN1 = 3;
int L_EN1 = 4;
int R_PWM1 = 6;
int L_PWM1 = 7;
// Motor2
int R_EN2 = 9;
int L_EN2 = 10;
int R_PWM2 = 11;
int L_PWM2 = 12;
char input;
int Motor1Speed = 0;
int Motor2Speed = 0;
void setup() {
// DC motor controller
// Motor1
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
digitalWrite(R_EN1, HIGH);
digitalWrite(L_EN1, HIGH);
// Motor2
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
digitalWrite(R_EN2, HIGH);
digitalWrite(L_EN2, HIGH);
Serial.begin(38400);
}
void checkSpeed() {
Serial.print(Motor1Speed);
Serial.print(" : ");
Serial.println(Motor2Speed);
}
void loop() {
input = 'q';
if (Serial.available() > 0) {
input = Serial.read();
}
switch (input) {
case 'b':
Motor1Speed = 80;
Motor2Speed = 80;
Serial.println("Motors started");
break;
case 's':
Motor1Speed = 0;
Motor2Speed = 0;
Serial.println("Motors stopped");
break;
case '1':
if (Motor1Speed < 230) {
Motor1Speed = Motor1Speed + 20;
checkSpeed();
}
break;
case '3':
if (Motor2Speed < 230) {
Motor2Speed = Motor2Speed + 20;
checkSpeed();
}
break;
case '2':
if (Motor1Speed > 30) {
Motor1Speed = Motor1Speed - 20;
checkSpeed();
}
break;
case '4':
if (Motor2Speed > 30) {
Motor2Speed = Motor2Speed - 20;
checkSpeed();
}
break;
}
analogWrite(R_PWM1, Motor1Speed);
analogWrite(L_PWM1, 0);
analogWrite(R_PWM2, Motor2Speed);
analogWrite(L_PWM2, 0);
}