Go Down

Topic: Arduino Motor Sheild & DC Motor (Read 504 times) previous topic - next topic

pjkelly3

I can not find anything on the WEB about using the Arduino Motor Sheild to control a DC Motor.  My understanding is that it can control 2 DC Motors.  I asume the motor would be connected to either the A or B two screw downs on the blue block.  If not correct then how?

After I plug the Arduino Motor Sheild into the Arduino, how do I program the Arduino then.

thanks...pat
pjk3(at)pdq.net

JimboZA

Repeal Ohm's Law

No PMs for help please

pjkelly3

Yes it did help.  Thanks.  Based on it I was able to get variable speed from the motors.  Simplified code follows:



#define DIRA            12                  // Direction motor pin
#define DIRB            13                  // Direction motor pin
#define PWMA            3                   // PWM motor pin
#define PWMB            11                  // PWM motor pin
#define BREAKA          9                   // Break A
#define BREAKA          1                   // Break B
#define CURRENTA        A0                  // Current Sensing A
#define CURRENTB        A1                  // Current Sensing B


int PWM_val = 0;                                // (25% = 64; 50% = 127; 75% = 191; 100% = 255)


void setup()
{
  analogReference(EXTERNAL);                            // Current external ref is 3.3V
//  Serial.begin(115600);
  Serial.begin(9600);
  pinMode(DIRA, OUTPUT);
  pinMode(DIRB, OUTPUT);
  pinMode(PWMA, OUTPUT);
  pinMode(PWMB, OUTPUT);
  pinMode(CURRENTA, INPUT);
  pinMode(CURRENTB, INPUT);
  digitalWrite(CURRENTA, HIGH);                     
  digitalWrite(CURRENTB, HIGH);

  analogWrite(PWMA, PWM_val);
  analogWrite(PWMB, PWM_val);
  digitalWrite(DIRA, HIGH);
  digitalWrite(DIRB, HIGH);
  delay(5000);
} /* setup */

void loop() {

  for (PWM_val = 0; PWM_val <= 255; PWM_val = PWM_val +10)
  {
    analogWrite(PWMA, PWM_val);                                               // send PWM to motor
    analogWrite(PWMB, PWM_val); 
    Serial.print("PWM:");          Serial.print(PWM_val);  Serial.print("\n");
   delay(2000);
  } /* for */

} /* loop */


Go Up