Electronic – arduino – Controlling a DC motor speed with Arduino

arduinodc motor

I'm trying to follow this tutorial

But instead of the components specified in the tutorial, I'm using the following:
RS-360SH DC Motor
BD139 Transistor
1N4007 Diode
– 220 Ohm Resistor

I understand that the components are different than specified in the tutorial, but these components are specified in another (less clear tutorial with the same schematics.

And I have the following arduino code:

int MotorPin =  9;
void setup()
{
  pinMode(MotorPin, OUTPUT);
}

void loop()
{
  analogWrite(MotorPin, 200);
  delay(1000);
}

All I can get is a buzz in the motor. There doesn't seem to be enough current to power it on. Can anyone explain what I'm doing wrong?

Edit
This is my schematic (I put the 2N2222 transistor, because I tested with that one as well):

schematic

simulate this circuit – Schematic created using CircuitLab

And this is how I plugged everything onto the breadboard.

enter image description here

Best Answer

Your schematic is correct, basically.

Although it is not explicitly shown on your diagram, I assume you have the Arduino plugged into a USB port which supplies it with power?

What happens if you connect the 9V power supply directly to the motor? Of course the motor should spin constantly at full speed. This tests that the voltage of this power supply is appropriately matched to your motor, and the power supply can source enough current to run the motor.

Now, what happens with the wire disconnected from pin 9 on the Arduino and plugged into +5V on the Arduino? If the transistor and other parts are wired up correctly this should also cause the motor to spin up constantly at full speed.

If this doesn't work double check the pinout of the transistor.

Now, in your software, try turning the motor on with a single digitalWrite(MotorPin, HIGH) statement in the setup part of your program. Don't put anything inside the loop at this stage. This should just cause your motor to turn on and stay on all the time at full speed.

Now, if that works, try something like analogWrite(MotorPin, 128) executed once in the setup part of your program, with nothing in the loop. The motor should now turn on, and stay on constantly, at reduced speed.

Is the motor current too much for the 2N2222 to handle? (Once you know what the motor's actual specifications are for current draw, check the collector current in the 2N2222 datasheet.) You may need to consider substituting a different, higher-current transistor such as a TIP120 or BD675.