I've set up a DC motor connected to my Arduino Uno with the following layout. I'm using a 1.5V - 3V DC motor that was purchased from RadioShack.
Here is my code:
int controlPin = 9;
void setup(){
pinMode(controlPin, OUTPUT);
Serial.begin(9600);
while(!Serial);
Serial.println("Ready");
}
void loop(){
if(Serial.available()){
int s = Serial.parseInt();
if(s >= 0 && s <= 255){
Serial.println(s);
analogWrite(controlPin, s);
}
}
}
If I connect the motor through the Arduino 5V pin it only hums until I set the speed s
to 200 or greater. This seems odd because I'm supplying 5V.
As a next step I decided to try a 9V battery (I don't really care if I fry the motor, I just wanted to experiment). Of course this is over the recommended voltage, but I assumed if I sent a low enough signal (s
) through pin 9 it might not destroy the motor. However, to my surprise, when I connected the 9V battery (as illustrated below) the motor immediately starts spinning. I measured the current and it seems to be ~150mA when connected to the 9V battery. It seems like the circuit is connected even though I'm not sending any signal from pin 9 to the transistor. If I removed any of the wires connected to ground, the motor, obviously, stops spinning. My expectation, which is apparently wrong, was that the motor wouldn't spin until I sent a signal from pin 9 to the transistor. What am I not grasping here?
Here's a picture as my diagram may be wrong based on comments below. This shows the diode reversed as suggested by Chris.
I also moved the jumper going from pin 9 to the breadboard out of the Vcc column and directly into the row with the resistor. I'm not sure if that resolves the short mentioned in comments.