Pages: [1]   Go Down
Author Topic: Trouble controlling 5V motors using Adafruit motor sheild  (Read 292 times)
0 Members and 1 Guest are viewing this topic.
Northeast U.S.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, I have been doing some research to test out coding for two 5V hobby motors through a dual h-bridge Adafruit shield (connected to my Arduino Uno).  Eventually, I would like to control each one separately so that the vehicle can turn (one motor per side on a tracked vehicle).  While I have tried using different ways of coding from other posts, right now I am only getting one motor to run, but I'm not sure where I am going wrong.  Do any of you see where I am lost (besides everywhere  smiley-razz haha).

Code:
#include <AFMotor.h>

AF_DCMotor motor2(2);
AF_DCMotor motor4(4);

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");

  // turn on motor
  motor2.setSpeed(200);
  motor4.setSpeed(200);
 
  motor2.run(RELEASE);
  motor4.run(RELEASE);
}

void loop() {
  uint8_t i;
 
  Serial.print("tick");
 
  motor2.run(FORWARD);
  for (i=0; i<255; i++) {
    motor2.setSpeed(i); 
    motor4.setSpeed(i); 
    delay(10);
 }


  for (i=255; i!=0; i--) {
    motor2.setSpeed(i); 
    motor4.setSpeed(i); 
    delay(10);
 }


  Serial.print("tock");

  motor2.run(BACKWARD);
  motor4.run(BACKWARD);
  for (i=0; i<255; i++) {
    motor2.setSpeed(i); 
    motor4.setSpeed(i); 
    delay(10);
 }
 
 
  for (i=255; i!=0; i--) {
    motor2.setSpeed(i); 
    motor4.setSpeed(i); 
     delay(10);
 }
 


  Serial.print("tech");
  motor2.run(RELEASE);
  motor4.run(RELEASE);
  delay(1000);
}
Logged

~~~Freddie

0
Offline Offline
Shannon Member
****
Karma: 159
Posts: 10409
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You're not trying to power the motorshield from the Arduino 5V rail perchance?  Motors need a separate supply (and given that that shield uses the L293D it should be about 2V higher than you want to reach the motors).
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: