0

I would like both the motors to spin the attached wheels forward when I push the joystick forward and vice versa. When the joystick is still, the motors should stop spinning. At the moment, when I push the joystick on x-axis and my x variable increases both motors spin, but when I push it in the opposite direction and x decreases, only motor A spins. Additionaly when I connect the arduino to the power (usb cable to my pc), motor B spins for approx 1 second and then stops.

This is the circuit I have (sorry for a lack of schematic, let's hope this wonderful drawing is enough): Text

The code:

int MotorAA = 7;
int MotorAB = 8;

int MotorBA = 11;
int MotorBB = 12;

int x = 0;

void setup() {
  Serial.begin(9600);
  
  
  pinMode(MotorAA, OUTPUT);
  pinMode(MotorAB, OUTPUT);

  pinMode(MotorBA, OUTPUT);
  pinMode(MotorBB, OUTPUT);


  digitalWrite(MotorAA, LOW);
  digitalWrite(MotorAB, LOW);

  digitalWrite(MotorBA, LOW);
  digitalWrite(MotorBB, LOW);
}

void loop() {
  x = analogRead(A0);
  Move();
  Serial.println(x);
}

void Move() {
  if (x == 0){
    return;
  }
  
  if (x > 520)
  {
    digitalWrite(MotorAA, HIGH);
    digitalWrite(MotorAB, LOW);

    digitalWrite(MotorBA, HIGH);
    digitalWrite(MotorBB, LOW);
  }
  else if (x < 480)
  {
    digitalWrite(MotorAA, LOW);
    digitalWrite(MotorAB, HIGH);
    
    digitalWrite(MotorBA, LOW);
    digitalWrite(MotorBB, HIGH);
  }
  else{
    digitalWrite(MotorAA, LOW);
    digitalWrite(MotorAB, LOW);

    digitalWrite(MotorBA, LOW);
    digitalWrite(MotorBB, LOW);
  }
}
  • 3
    How much current are the motor pulling? Powering DC motors off the Arduino board is usually a recipe for smoke. The 5V pin is not there to power your project. You need to power the motors separately. – Delta_G Jun 23 at 19:27
  • @Delta_G Thank you for answering. I've connected the motor driver module to the usb charger with 5V and still the same. When I connected the meter between the motor driver and the motor it showed ~0,12A. – Magalek Jun 23 at 19:57
  • @jsotola Good point, I'll update the post. I would like the motors to spin the attached wheels forward when I push the joystick forward and vice versa. When the joystick is still, the motors should stop spinning. – Magalek Jun 23 at 20:19
  • isolate the area of failure ... swap the A lines with the B lines ... does the problem stay with the motor? ... does it move ? .... switch the motors ... does the problem follow the motor? .... that kind of testing will allow you to determine where the failure is occuring – jsotola Jun 23 at 20:28
  • @jsotola Strangely enough, when I left only the ground and power connected to the driver, motor B acts the same. I thought that without powering the motor a and b pins on the driver, it shouldn't move. – Magalek Jun 23 at 20:56
0

The Arduino can definitely not power that many motors. The Arduino's max output current is 0.1A and you might be drawing around 0.5A. Use an external battery like a LiPo battery for the motor controller.

NOTE: Please watch out! Drawing that many amps from Arduino can kill it! So please use the LiPo or normal batteries!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.