Controlling the speed of a dc motor?

dc42:
2N3904 is far too puny to control a motor...

Thank you that's the kind of answer I've been looking for. So why will it click on with full PWM duty cycle though? And if it matters its a tiny DC motor, from one of those Zip-Zaps RC cars.

I'm confusimicated here

As I said the problem isn't in the code. Instead of using a potentiometer to get an analog value I'm using a stereo remote and infrared receiver on the arduino. Each time the "up" button is pushed, it adds 15 to the value that gets set to the PWM. So each button push should make the motor run a little faster.

What happens though is it does nothing until the value reaches 255(%100 duty cycle) and then it will click on.