Pages: [1]   Go Down
Author Topic: Programming two motors  (Read 436 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Im relatively new to Arduino so would greatly appreciate some code advice. I posted a similar message the other day but have now had to switch to the Arduino Motor Shield R3.

I need to run two DC Motors using the Arduino motor shield. I need to run one motor forward on Motor A for 2450, then run another motor on Motor B after Motor A for 2600, then stop both of them for 30000, then repeat again.

I have managed to work out some of the code but cant get them delay at the right times, motor B seems to come on for too long.

Code:
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(){

 
  //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

  delay(2450);

  digitalWrite(9, HIGH);  //Engage the Brake for Channel A

 
  //Motor B forward @ full speed
  digitalWrite(13, HIGH); //Establishes forward direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 255);   //Spins the motor on Channel B at full speed
 
  delay(2600);
 

  digitalWrite(9, HIGH);  //Engage the Brake for Channel B
 
 
  delay(30000);
 
}


Many thanks!!  smiley
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 34478
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You seem to be engaging the break while still powering the motor!
Logged

Pages: [1]   Go Up
Jump to: