I have a basic circuit connected to the Uno using a DC motor, a P2N2222A transistor, a 2k resistor with the motor protected by a diode.
The code is a basic HIGH/LOW switch on pin 9. I have tested the voltage output to the DC motor and it switches between 0v & 5v. But the motor doesn't spin - an LED in its place will flash, as expected.
Is this an issue with the motor trying to pull too much current? I've tested the motor on the breadboard power rails and it works fine.
Apologies for the very basic question - I'm new to this.
Please let me know what further info I should have provided to enable you to provide an opinion.
It is always a bad idea to power a motor from the Arduino 5V pin. It can't provide much current and how much it can provide depends on exactly how you are powering the Arduino. And that transistor is only good for fairly low currents too. It's a shame there are so many bad tutorials about.
So what motor are you using and how are you powering everything?
I got a small DC motor from Amazon ... it is one of these.
I figured the problem was that, once the transistor opened that circuit, there was insufficient power to drive the motor. Power is from the laptop USB. I do have a 2.5mm power supply - I'll try that too but it's still through the Uno.
How would I best change this? Do I put a power supply in between the resistor and transistor so that circuit has independent power?
Run the motor on a separate power supply. 4 x AA batteries in a battery holder will work. I prefer NiMH rechargeables but ordinary alkalines will do.
From your existing circuit take the motor wire off the Arduino 5V pin and instead connect it to battery + positive. Connect battery - negative to the Arduino GND pin. That should help. If it's not enough also try a smaller resistor between pin 9 and transistor base, maybe 1K.
I have a basic circuit connected to the Uno using a DC motor, a P2N2222A transistor, a 2k resistor with the motor protected by a diode.
2k is far too large, use 150 ohms or so for the base resistor. Where did you get that bad circuit from? Its
only capable of switching 40mA or so, not the 0.5A or more that a motor requires.