Your motor will generate spikes because of this PWM (it will generate spikes anyway), so protect your electronics (the diode across the transistor in the schematics).If you need more info, ask specific questions.

The schematics you saw at the playground are wrong (there is a warning about that directly above it).The box with an X in it and connected to 12 volts and pin 11 (this is the error), is supposed to be the relay used to invert direction.As you have no use for that, you can remove it and forget all about pin 3 and the relay in your sketch.Connect one side of your motor to 12 volts, and the other side to your transistor.If the motor runs in the wrong direction, exchange these two wires.

[edit]Another error in those schematics: the pot to analog pin 0 is also wrong.Analog pin 0 is supposed to be connected to the 1 K resistor and 5 volts to where Analog 0 is now (so these two are to be exchanged).[/edit]

Yes, that is exactly the same but without the direction control and without potentiometer.Be sure to get all polarities correct and also be sure you have the right components.If you do not hve the exact same components as described in those schematics (either one of them), report back here to ask about differences.Ofcourse you will have to tell us what parts you do have.

The resistor on the base limits current. The idea is to select a base resistor, given the motor current, such that the transistor will be driven into saturation. That's a fancy way of saying that the transistor is really, really on and can't get any more on if it tried.

At the same time you don't want to try and draw more than the max per-pin current out of the MCU drive pin.

So i set up everything as that example, but with a 2k resistor, a 9v battery, a 2N3904 transistor(also an NPN so it shouldn't matter) and instead of a potentiometer for PWM I'm using a button that increases the value by 15 each time it's pushed.

Nothing happens until the value gets to 255 then it kicks on. Any thoughts that may help me?

and i believe i followed it correctly, however there are a few differences

Perhaps the undisclosed changes messed the design up. You could touch the pin end of the resistor to the arduino +5v pin to see if the motor runs. If not touch the same end of the resistor to the +9v battery terminal and see if the motor runs. There may be issues with using 5v to control 9v thru the transistor.

Google forum search: Use Google Search box in upper right side of this page. Why I like my 2005 Rio Yellow Honda S2000 https://www.youtube.com/watch?v=pWjMvrkUqX0

2N3904 is far too puny to control a motor, it's designed to switch currents of 10mA or so. For small motors, you can use a medium-current transistor such as BC337 or 2N2222A, with a base resistor of between 100 and 220 ohms. For larger motors, use a mosfet instead of a bipolar transistor.

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

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.

Quote

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.