I'm trying to control the speed of DC Motor using
- Arduino R3
- NPN Transistor (2N2222A331)
- 10k potentiometer
- 2M ohm resistor
- Diode
I'm not using L298N and I'm also not using L293D.
DC motor is running, but the speed of DC motor doesn't seem to change with changes in potentiometer. Circuit seems to be alright as DC motor is running.
The code is as follows
int potPin = A0;
int motorPin = 9;
int potValue = 0;
int motorValue = 0;
void setup()
{
Serial.begin(9600);
pinMode(motorPin,OUTPUT);
}
void loop()
{
potValue = analogRead(potPin);
motorValue = map(potValue, 0, 1023, 0, 255);
analogWrite(motorPin, motorValue);
delay(2);
Serial.print("potentiometer = " );
Serial.print(potValue);
Serial.print("t motor = ");
Serial.println(motorValue);
}
Whenever I tweak the Potentiometer, I can see the relative changes from Arduino "Serial Monitor" (both Potentiometer values and Motor values), but the speed doesnt seem to change physically.
Things that I tried
- tried different combinations of resistors(100,1k,10k,1M,2M ohm) so as to vary voltage that goes to DC Motor
- tried to check with different Output pins like 3,5,9
Nothing works, DC motor speed isn't changing.
this leads me - to believe that, my analogwrite isn't working. please help me understand as to what i'm i doing wrong?
The Circuit is as follows