Hi. I have followed this tutorial in order to control 2 DC motors. The only difference is that I have Arduino Mega 2560.
The connections are
enA = D9
IN1 = D5
IN2 = D6
IN3 = D7
IN4 = D8
enB = D10
VSS = 5V from Arduino
GND = GND from Arduino
MotorA = First motor
MotorB = Second motor
The problem is that there is no voltage so motors are not turning. At the same config without changing connections, when I changed enA = 11 (connection is 10), the motors are working separately. I have not been able to find explanation of the behavior. Thank you in advance.
My code is here:
// Motor A connections
const int enA = 9; // when it is 11 at the same config it is working separately
const int in1 = 5;
const int in2 = 6;
// Motor B connections
const int enB = 10;
const int in3 = 7;
const int in4 = 8;
// Set the speed (0 = off and 255 = max speed)
const int motorSpeed = 255;
void setup() {
Serial.begin(9600);
// Motor control pins are outputs
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
// Turn off motors - Initial state
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
// Set the motor speed
analogWrite(enA, motorSpeed);
analogWrite(enB, motorSpeed);
}
void loop() {
Serial.println("Main loop");
// Go forwards
go_forward();
delay(3000);
// Go backwards
go_backwards();
delay(3000);
// Go right
go_right();
delay(3000);
// Go left
go_left();
delay(3000);
// Stop
stop_all();
delay(3000);
}
/*
* Forwards, backwards, right, left, stop.
*/
void go_forward() {
Serial.println("Forward");
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}
void go_backwards() {
Serial.println("Backward");
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
}
void go_right() {
Serial.println("Right");
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
}
void go_left() {
Serial.println("Left");
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}
void stop_all() {
Serial.println("Stop All");
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}





