Go Down

Topic: [ URGENT!!]How to control two motors by Arduino + H Bridge Motor Shield? (Read 1 time) previous topic - next topic

SuperBruce

Dear Arduino Forum

I m doing this project that needs to be ready by next Thursday. The problem I encountered was that I failed to control more than one DC Motor. I m using Arduino language to program the script. When it was only one DC Motor, it worked all right. However, I don't know how to control two DC Motors.

Oh yeah, and, my DC Motor can't be going backwards for some reason....what could be the cause?? The motor was labelled as reversible. lol


Hope to get a reply soon!!!!!!

You guys are the best!!!!!

=D

C-F-K


I m doing this project that needs to be ready by next Thursday. The problem I encountered was that I failed to control more than one DC Motor. I m using Arduino language to program the script. When it was only one DC Motor, it worked all right. However, I don't know how to control two DC Motors.

Oh yeah, and, my DC Motor can't be going backwards for some reason....what could be the cause?? The motor was labelled as reversible.


On the risk of sounding like my mom: You started to late if you're in a hurry now...

We need a bit more info on your project. Like: What type of motor, which shield, which arduino and most important: Your code!
Evil Base of Operations: Holland

SuperBruce

#include <AFMotor.h>

AF_DCMotor motor(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");
 
  motor.setSpeed(200);     // set the speed to 200/255
}

void loop() {
  Serial.print("tick");
 
  motor.run(BACKWARD);      // turn it on going forward
  delay(7890);

  Serial.print("tock");
  motor.run(RELEASE);     // the other way
  delay(5000);
 
  //Serial.print("tack");
  //motor.run(FORWARD);      // stopped
  //delay(1000);
}


My Motor was bought from Jaycar in melbourne, this is the link of the motor
http://www.jaycar.com.au/productView.asp?ID=YG2734


12V DC Reversible Gearhead Motors - 36RPM

Only slightly larger than the YG-2732, but with a massive increase in torque at 36rpm. Ideal for driving wheels or other traction devices.

Specifications:
• Torque: 12.0kg.cm
• Rated Voltage: 12.0V
• Operating: 4.5 - 18V max
• Current - No load: 70mA
• Current - Full load: 1380mA
• Gear Ratio:  244:1
• Shaft Speed: 36rpm

The H bridge shield had two stepper motors, 2 servos and 4DC motor ports. 

The major problem had now was that I don't know how to control two motors with only one .ino file

Thanks for the quick reply!! You are the best!!!

Regards


SuperBruce


SuperBruce

Yeah, so the code I just posted was used to control one motor linked to port 3 only. I copied it from adafruit...I can't figure out what to add to control, lets say, an additional motor linked to port 2 


rmetzner49

I don't see how it works at all with that library, since looking at it that library is for a PIC32, not an Atmel AVR. It runs the motor via hardware timer which is PWM controlling it at 64KHz.  Why go that fast?  Any cheapie H-bridge driver you buy will not run efficiently at that speed. 

Go Up