1

`I have an Arduino Uno A000066 Board R3 that has an Arduino A000079 Motor Shield Rev3 attached to it. Also I have connected two DC Servo Motors to the Motor Shield and wrote the following sequence:

 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()
    {
      //Phase 1 - going to the wall
      //Motor A forward - Max 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 max speed

      //Motor B forward - Max 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 max speed

      delay(4000); // Adjust to correspond the distance



  //Phase 2 - getting back to initial point
  //Motor A backward - max speed
  digitalWrite(12, HIGH);  //Establishes backward direction of Channel A
  digitalWrite(9, LOW);    //Disengage the Brake for Channel A
  analogWrite(3, 255);     //Spins the motor on Channel A at max speed

  //Motor B backward - max speed
  digitalWrite(13, LOW);   //Establishes backward direction of Channel B
  digitalWrite(8, LOW);    //Disengage the Brake for Channel B
  analogWrite(11, 255);    //Spins the motor on Channel B at max speed

  delay(4000);



  //Phase 3 Stop for 7.5 seconds
  // Motor A stop
  digitalWrite(9, HIGH);   //Engage the Brake for Channel A
    //Motor B stop
  digitalWrite(8, HIGH);   //Engage the Brake for Channel B
  delay(7500);



  //Phase 4 Go to second point
  //Motor A forward - max 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

  //Motor B forward - max speed
  digitalWrite(13, HIGH);  //Establishes foward direction of Channel B
  digitalWrite(8, LOW);    //Disengage the Brake for Channel B
  analogWrite(11, 255);    //Spins the motor on Channel B at half speed

  delay(2000); // Adjust to correspond the distance



  //Phase 5 Final Stop
  //Motor A - stop
  digitalWrite(9, HIGH);   //Engage the brake for Channel A
  //Motor B - stop
  digitalWrite(8, HIGH);   //Engage the brake for Channel B

  delay(60000);        // 1 minute stop
}

While connected to USB, the device executes perfectly the sequence. As soon I run the sequence using the DC Source, the device does not respect any part of the coding. It started simply going forward while reversing the polarity randomly blocking the movement sometimes.

Looking forward to your suggestions.

  • 1
    What is your power source? – Majenko Feb 20 '17 at 16:45
  • 1
    If that stuff in the question is code, mark it as such. Click edit, and in the edit box, highlight the code and press ctrl-k. Or highlight the code and click the {} icon in the toolbar at the top of the editing box. To highlight text click-drag across it or use the arrow keys while holding the shift key. ¶ While colorful, the phrase “the device does not respect any part of the coding” does not have a well-defined or specific meaning that imparts any information about what actually happened. You could edit your question and tell what happens. – James Waldby - jwpat7 Feb 20 '17 at 17:02
  • Is your "DC Source" a 9V battery, or what? A stack of coin cells? Some AAA batteries? (Typically, none of those are good enough to keep the Arduino from resetting when the motors turn on.) – James Waldby - jwpat7 Feb 20 '17 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.