Pages: [1]   Go Down
Author Topic: Arduino Motors not working  (Read 166 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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;

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

TYVM
Logged

Queens, New York
Online Online
Faraday Member
**
Karma: 99
Posts: 3618
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Saskatchewan, Canada
Offline Offline
Edison Member
*
Karma: 49
Posts: 1417
Coding Geezer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Code:
  //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:
#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.
Logged

There are 10 kinds of people in the world,
those who understand binary, and those who don't.

Pages: [1]   Go Up
Jump to: