check this, if it helps so good, if not then sorry
if u want to increase and decrease speed of your 12V DC motor in one direction, u should have 12V DC supply and any of the 5 Volt NPN transistor..
so u can do it in 2 ways, according to your needs.. if u want to control it by yourself at anytime so u can use potentiometer connected to analog pin 0 i-e (A0), otherwise if u want to control it according to time or some sensor so instead of potentiometer u may give input according to that, so after this connect PWM pin 10 to NPN transistor base and connect motor and 12V battery in series in between collector and emitter of transistor..
if u r new, so in program i have also explained everything..
Motor Speed Controller
First Declare an integer variable "potentiometer" for
saving the input value of potentiometer.
The speed of the Motor will depends on the value obtained by analogRead(). */
intsensorPin = A0; // select the input pin for the potentiometer
intmotorPin = 10; // select the pin for the Motor
intsensorValue = 0; // variable to store the value coming from the sensor
pinMode(motorPin, OUTPUT); // declare the motorPin as an OUTPUT
// Range of Analog Value(Potentiometer) is in b/w
// "0" & "1023" as we have 10 bit ADC in Arduino.
sensorValue = analogRead(sensorPin);
// PWM is 8-bit so we can write from 0 to 255 not from 0 to 1023.
// So using map function we will write sensorValue on output.
int mapped = map(sensorValue, 0 , 1023 , 0 , 255);
analogWrite(motorPin, mapped); }