Arduino based DC Motor Controller based on PWM.
The process is simple. We use buttons to take input from arduino interrupt pins and create a virtual parameter called speed(0-9) which is mapped to an analog value(0-255) and this analog voltage is written on motor pin where a npn transistor awaits for conduction through motor. I have added an external plug to point out that a separate power supply for motor be used although for small dc motors (5v/6v), you can use arduino vcc. Also the transistor being used depends upon application and motor load. For bigger motors use tip122(max 5A), for small toy motors(5v/6v) bc547(max 100mA) or 2n2222(max 500mA)can be used. The diode also depends upon the load on motor so choose carefully-for small applications in4001(1A). I've use a Common Cathode 7-Segment Display. Do remember to put a 220ohm resistor to connect cathode to ground.(You only need this resistor)