• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

Arduino motor shield rev3 : the first approach running a dc-motor (without a library)

Question

tarifa    0

hello dear experts good day .

 

 

well first of all - i want to express that i am not 100% sure if this belongs to this forum - or to the hardware forum. (as it covers a arduino-question)

 

I have buyes a arduino motor shield rev3 (revision 3) see the page where it is being sold:  https://store.arduino.cc/arduino-motor-shield-rev3 When I follow the link for "Getting Started section" the page lists a lot of shields but not the motor shield. I am looking for a library for the motor board - or at least for an first approach to get the thing up and running. 
What is aimed: I'm trying to drive 2 DC motors - for a rc-car.  Therefore 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
    }


and afterwards we have the following piece of code: 

 

 

    void loop()
    {
      //Phase 1 - going to the wall
      //Motor A forward - Max Speed
      digitalWrite(12, LOW);   //this should try to establishes forward direction of Channel A
      digitalWrite(9, LOW);    //this is for the Disengage of the Brake for Channel A
      analogWrite(3, 255);     //this should help to spin the motor on Channel A at max speed

      //Motor B forward - Max Speed
      digitalWrite(13, HIGH);  //this is to establish forward direction of Channel B
      digitalWrite(8, LOW);    //this should help to disengage the brake for Channel B
      analogWrite(11, 255);    //this 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);  // this should establish backward direction of Channel A
  digitalWrite(9, LOW);    //now we need to disengage the Brake for Channel A
  analogWrite(3, 255);     //at this point i want to spins the motor on Channel A at max speed

  //Motor B backward - max speed
  digitalWrite(13, LOW);   // right now i try to establishes backward direction of Channel B
  digitalWrite(8, LOW);    //and now we want to disengage the Brake for Channel B
  analogWrite(11, 255);    //finally we want to spins the motor on Channel B at max speed

  delay(4000);

  //Phase 3 Stop for 7.5 seconds
  // Motor A stop
  digitalWrite(9, HIGH);   // here we try to engage the Brake for Channel A
    //Motor B 


 

 

what happens now While connected to USB, the device executes perfectly the sequence.

but wait: whein i run the sequence using the DC Source, the device does not respect any part of the coding. 
It started simply going forward while then it wante to  reverse the polarity randomly blocking the movement sometimes.


i afterwards tried another approach as a library-replacement i have tried this code is simple enough:

 

 

void setup() {

  //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A pin

}

void loop(){

  //forward @ full speed
  digitalWrite(12, HIGH); //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(3000);

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

 

conclusio: Well - what is very very funny - with the second code-example it runs like a charme.

 

Looking forward to your suggestions.

Edited by tarifa

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.