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);
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.
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.