Newbie. Unstable rpm of DC motor

Hi
I am trying to get a DC motor to run stable rpm at value “127” on pwm -9. I found that I had to place a capacitor to even out the voltage drops that I am experiencing but when I do, the capacitor gives too much power regardless of setting and hence destroys the purpose of the transistor which is to control the flow of power to the motor. Or it just doesn’t work and the rpm stay unstable with drops of 400+/-. I suspect that I have placed the cap wrong, but I can’t figure out what to do instead. Any help would be much appreciated!

External power: 5V , Current 0.10

NPN Transistor

Capacitance: 100nF

In case, the code is basicly just:
int speed = 0;

void setup() {
pinMode(9, OUTPUT);
}
void loop()
{
analogWrite(9, 127);
}

Where did that Fritzing disaster originate? It’s just wrong.

What part number transistor are you attempting to use?

The circuit looks completely wrong. Please draw a circuit diagram, not a wiring diagram... If you don't know the difference, I'd recommend a little research. Circuit diagrams convey meaning, wiring diagrams do not.

Yes, there are a few errors in your hook-up.

• The motor Black lead [assuming it's the Negative lead], should be connected directly to the Collector on the transistor.
• The Emitter should be connected directly to the Negative rail [e.i. the buss line that is connected to the black wire on your power Supply [again, assuming the Black lead is the Negative lead].
• The Motor's Red lead needs to go to the Positive side of the Power Supply.
• This will mean the Diode will need to be moved, so it is, once again, connected across the Motor [Anode to Black lead, and Cathode to Red lead].
• That looks like a 160Ω resistor going to the Base. That's overkill. 430Ω should be enough.
• Dispense with the capacitor, for now.

Give that a try. If that transistor is truly capable of driving that motor, then it should work. But, you might get to see the magic smoke! You claim that the pertinent current associated with that motor is "0.10" -- assuming you mean 0.10Amps, I'm guessing that is a non-loaded "Free Current". More than likely, your motor draws a bit more when it first starts. Your transistor will need to manage that, as well.
UPDATE:
I went back and re-read your post, and noticed that the "0.10" value is associated with the "External Power". I assume your referring to the external power supply depicted in your Friztzing drawing. If that Power Supply current limits at 100mA, that could also be an issue. Does the motor run the way you want it to, if you connect it directly to the Power Supply?

Probably wont change much of anything but don't forget to use a "fly-back" diode

LandonW:
Probably wont change much of anything but don't forget to use a "fly-back" diode

There is one.

I found that I had to place a capacitor to even out the voltage drops that I am experiencin

That is the wrong thing to do. You need to supply a PWM signal to the motor for speed regulation to take place. So you don’t want a capacitor destroying that waveform.

Voltage drops are caused by a poor supply plus the fact you are using that transistor in the emitter follower mode which limits the motor voltage to 4.3V if you supply a 5V signal to it. You want to use the transistor in the common emitter mode and get a better power supply. Any capacitor should be across the whole supply and not the motor.

Grumpy_Mike:
That is the wrong thing to do. You need to supply a PWM signal to the motor for speed regulation to take place. So you don’t want a capacitor destroying that waveform.

Isn't there a case where a capacitor across the motor winding can limit or suppress noise? I ask, because i literally don't know

Yes it can limit the noise but only a small capacitor. A large one will average the waveform to give an average voltage. Controlling a motor’s speed with a voltage is not so good. It is the peaks of the PWM that give the motor a kick and allow a wide range of speed control.

Circulus87:
I am trying to get a DC motor to run stable rpm at value "127" on pwm -9.

If you want the DC motor to run at a relatively stable RPM, then maybe a recommendation is to use a sensor of some sort --- like an incremental encoder --- and then you could apply a PID method to get a relatively stable angular speed. Just depends on what you want to do.

It also depends on the load on the motor. PWM works best on a medium to heavy loaded motor. On a lightly loaded or unloaded motor it is not so good.