Go Down

Topic: Arduino Motors not working (Read 299 times) previous topic - next topic


When I try to run the motors for my obstacle avoidance RC car I get nothing but a steady "clicking" sound. I tried plugging in different motors to my shield (using motor shield) and the same problem Occurs.

I used this code as a test;

//test 2

void setup() {
  //establish motor direction toggle pins
  pinMode(12, OUTPUT); //drive motor -- HIGH = forwards and LOW = backwards
  pinMode(13, OUTPUT); //turn motor -- HIGH = left and LOW = right
  //establish motor brake pins
  pinMode(9, OUTPUT); //brake (disable) the drive motor
  pinMode(8, OUTPUT); //brake (disable) the turn motor

  //Turns brake off for drive motor
  digitalWrite(9, LOW);

  //Turns brake on for turn motor
  digitalWrite(8, HIGH);

  //Sets initial speed of drive motor
  analogWrite(3, 200);
  //Sets initial direction of drive motor
  digitalWrite(12, HIGH);

void loop()
   //turn off brake for turn motor
    digitalWrite(9, LOW);

    //set turn motor direction
    digitalWrite(12, HIGH);

    //activate turn motor
    analogWrite(3, 200);

any ideas?



Pin 13 is connected to a resistor and Led so it may be giving you problems, however I don't see a pinMode for pin 3, and that could be the actual issue.
My GitHub:


Code: [Select]
  //establish motor brake pins
  pinMode(9, OUTPUT); //brake (disable) the drive motor

   //turn off brake for turn motor
    digitalWrite(9, LOW);

any ideas?

Yes. Your comments do not match with the code. You say pin 8 is to disable the turn motor, then later you use pin 9 for that job. Programmers call these numbers "magic numbers". The problem with using them is that you have to remember what they do every time you use them, and as you can see, you misremembered which was the one you wanted.

Make meaningful names for pins. Make meaningful names for actions. Ensure that the level to brake the turn motor and to brake the drive motor are the same. Avoid magic numbers whenever possible. Long names for variables do not cost you memory usage, as they compile to whatever the compiler thinks is best anyway.

Code: [Select]

#define BRAKE_ON 1
#define BRAKE_OFF 0

const byte TurnBrakePin = 8;
const byte DriveBrakePin = 9;

You would not have made this error if you had done these things.
There are 10 kinds of people in the world,
those who understand binary, and those who don't.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131