(Stby pin should be connected to Vcc . Schematic is wrong)
I used potentiometer to vary the PWM output of Arduino pin and control speed of DC motor.
const int transistorPin = 9; // connected to the base of the transistor
void setup() {
// set the transistor pin as output:
pinMode(transistorPin, OUTPUT);
}
void loop() {
// read the potentiometer:
int sensorValue = analogRead(A0);
// map the sensor value to a range from 0 - 255:
int outputValue = map(sensorValue, 0, 1023, 0, 255);
// use that to control the transistor:
analogWrite(transistorPin, outputValue);
}
1650FB31-734B-4CD1-8022-ACD313641E43.mov
I used H bridge to control the direction of motor motion.