Go Down

Topic: How to make 2 dc motors move together using motorshield? (Read 4238 times) previous topic - next topic

timlee

Hi I am using an arduino uno stacked with a motorshield. Problem is I couldn't get both motors to work together. Example forward right or backwards left. It also gives off a buzzing sound when I programmed it to move 2 dc motors at the same time. Why?
It doesn't complain when only 1 DC motor is rotating. please advise.

Code: [Select]
/*************************************************************
Motor Shield 2-Channel DC Motor Demo
by Randy Sarafan

For more information see:
http://www.instructables.com/id/Arduino-Motor-Shield-Tutorial/

*************************************************************/

void setup() {
 
  //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A pin

  //Setup Channel B
  pinMode(13, OUTPUT); //Initiates Motor Channel A pin
  pinMode(8, OUTPUT);  //Initiates Brake Channel A pin
 
}

void loop(){

  forward();
 
  delay(1000);
 
  stopping();

  delay(1000);
 
  revright();
//  reverse();
 
  delay(5000);
 
  stopping();
 
  delay(1000);
 
}

void forward()  {
  //Motor A forward @ full speed
  digitalWrite(12, HIGH); //Establishes forward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 255);   //Spins the motor on Channel A at full speed
}
void stopping()  {
   
  digitalWrite(9, HIGH);  //Engage the Brake for Channel A
  digitalWrite(8, HIGH);  //Engage the Brake for Channel B
}
void revright()  {
  digitalWrite(13, HIGH);  //Establishes backward direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 200);    //Spins the motor on Channel B at half speed
  digitalWrite(12, LOW); //Establishes forward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 55);   //Spins the motor on Channel A at full speed
}
void reverse()  {
  //Motor A forward @ full speed
  digitalWrite(12, LOW); //Establishes forward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 255);   //Spins the motor on Channel A at full speed
}

timlee

i realized it is due to the speed, if i tune it to 255, it doesn't complain. However the front motor is always underperforming than the rear motor, meaning the front only turned 1/3 to maximum right/left angle while the rear wheels always seemed to have more power. why?
I need both wheels specially the front to work together.

drewdavis

Quote
Hi I am using an arduino uno stacked with a motorshield.


It would help if we knew which one!

timlee


It would help if we knew which one!


Hi Davis, I'm using an Arduino Uno Rev3, on top of it is a Motorshield. Basically, yeah I'm using motorshield to control the DC motors.


Grumpy_Mike

He meant which motor shield the arduino is irrelevant here.

It sounds to me like you power supply can not supply enough current for two motors.

drewdavis

Quote
It sounds to me like you power supply can not supply enough current for two motors.


Or his motor driver is not able to handle the load and is starting to act up. Perhaps one of the motor uses up more current do to some mechanic flaw in his robot/car and the motor driver is not able to handle it. He said the motor driver is buzzing, not the motors. Then again it could be the power supply. Who knows when we have no specs.

@ timlee we need to know what motor driver, motor, and power supply your using.

Best of luck!

JimboZA

It might also be that the motor you're trying to run at PWM of 55 in your code, just won't start up at that speed. Have you checked that it will actually run? That's 55/255 of max might be too low a voltage to fire the motor up.

Also, depending on what shield you have, it may have significant voltage drop through its controller chip. If it's a 298 for example you'll lose a handful of volts (check datasheet), and if you only use 1/5 of what's left you'll have very little to turn the motor.

Get your meter out and measure some voltages....
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

Go Up