This is actually controlling speed of DC motor with potentiometer using Arduino, where DC motor is supplied by PWM output of Arduino.
|One thing to be kept in mind, Never connect any thing above 5V to any digital output of Arduino, you might damage the Arduino as it is not capable of feeding it. Because Arduino is made just for producing signals but not to bear any loads.
So for that you have to use a transistor as a switch and hook up the DC motor in it’s emitter and supply the external voltage to the Collector and PWM output is given to the base along with a Kohm resistor.
To be serious, this d313 transistor is not that good for carrying out a switching process for a DC motor, you better use 2N2222A transistor in place of this D313 transistor.
I hope you must have expected a longer code :p Well for both LED and DC motor the code is same.
int potentioValue = 0; //Value of Potentiometer
pinMode(9, OUTPUT); // we select any PWM pin the ones with this sign “~”
potentioValue = analogRead(0); //0 means Read Value from Analog A0
potentioValue = map(potentioValue, 0,1023,0,255); //as we know LED’s brightness ranges from 0 – 255
analogWrite(9, potentioValue); //Show output at 9 pin according to potentio’s value