5v dc motor with atmega8

Can someone please tell me how do i control speed of a 5v dc motor using my atmega8??

If it is a very tiny motor that draws less than 30mA you can drive it directly from one of the PWM output pins. If it draws more current than that (and it probably does) you can drive it with a transistor acting as a switch. In this schematic diagram your motor would take the place of the relay coil:

For a motor that draws more than a quarter Amp or so you should NOT try to get power from the +5v pin of the Arduino. Use a separate 5v power supply for the motor. Hook it to "Relay Power V+" and "RELAY power GND" in the diagram.

thanks! but i used l293d and gave the pwm output to it...

So what happened? Did it get hot, did nothing turn? Did it only tun in one direction.
If you don't say what it does we can't tell where you are wrong.
How is it wired?
What software are you running?

Unless of course you just want us to say, you wired it up wrong and have the wrong software.

It worked quite fine. I used the 'Fade' program from the examples given in the adruino software. The digital pin 9 from the atmega8 goes to the input of the l293d. I took help from here
http://luckylarry.co.uk/arduino-projects/control-a-dc-motor-with-arduino-and-l293d-chip/
I didnt use any external power supply since my motor is only 5v.
so instead of the led brightness fading, the motor speed faded. :slight_smile: