DC Motor speed control

Hey guys,
I am working on a small project where I have to control a DC motor.
The motor is connected to my arduino using a MOSFET and a 9V battery,
while I was trying to control the motor's speed by changing the output of the digital pin the motor kept operating at the same speed and when i entered a value lower than 128 it stopped completley.

My question is how do I control the motor's speed?
Thank you

Which pin did you use? You must use one of the PWM pins if you want to use analogWrite().
If its not that simple we will need more information ( part numbers, schematic, etc) to make any more guesses.

alka:
Which pin did you use? You must use one of the PWM pins if you want to use analogWrite().
If its not that simple we will need more information ( part numbers, schematic, etc) to make any more guesses.

I changed the output to one of the PWM pins and now it works.
thank you, just a newbie mistake by me ...