12v DC motor - Control of Speed through code

Hello,

I would like to control a DC motor of 12 volts with PWM by reducing the voltage provided.
Or is there any other better solution?
I saw the example in the Arduino playground where a potentionmeter is used.I need to do the same but using only code.
Can you provide a schematic?

Thanks in advance.

Spiros

There's no need to reduce the voltage: just connect the +12 to the motor, and use a transistor controlled by the PWM output to (dis)connect the ground side. By varying the on and off time, you vary the amount of power fed to the motor, which has pretty much the same effect as varying the voltage. Not exactly the same, but almost always close enough for speed control purposes (assuming the motor is rated to handle the maximum voltage).

Most of the motor speed control examples you'll see use some version of this.

Ran

http://www.google.dk/search?source=ig&hl=da&rlz=&q=arduino+dc+motor&btnG=Google-søgning&meta=lr%3D&aq=f