user54506: 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
 

user54083: Two things to test:

Have you tried to put an LED (and resistor to protect it) in the motor's place? If the brightness changes, your setup (Arduino+transistor) is working. If not, maybe you've killed your 2N2222 by giving it a wrong diode or something else is wrong.
Have you tried reducing the PWM frequency? An LED can follow a fast change, but a motor can't. Also, by turning on-off the motor less frequently you dissipate less power on your transistor and diode. A quick search gave me this: this.


user38721: Referring to this datasheet you have connected the transistor the wrong way around. Also, 1M resistor at the base is way too high. Bipolar transistors are current amplifiers (amplification at about 50-100 in your case) and with 1MOhm at the base there will be no current through the base at all. I would try with 2k for a beginning. 
I hope you have another transistor because this one seems to be broken and I'm pretty sure that it's not a fault in the analog output. If the output stage of the uC was broke there would be no reaction (at least in a correct circuit)

54506: <p>I'm trying to control the speed of DC Motor using </p>

<ol>
<li>Arduino R3</li>
<li>NPN Transistor (2N2222A331)</li>
<li>10k potentiometer</li>
<li>2M ohm resistor</li>
<li>Diode</li>
</ol>

<p>I'm not using L298N and I'm also not using L293D.</p>

<p>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.</p>

<p>The code is as follows</p>

<pre><code>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); 
}
</code></pre>

<p>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. </p>

<p>Things that I tried</p>

<ol>
<li>tried different combinations of resistors(100,1k,10k,1M,2M ohm) so as to vary voltage that goes to DC Motor</li>
<li>tried to check with different Output pins like 3,5,9  </li>
</ol>

<p>Nothing works, DC motor speed isn't changing.</p>

<p><strong>this leads me - to believe that, my analogwrite isn't working. 
please help me understand as to what i'm i doing wrong?</strong></p>

<p>The Circuit is as follows</p>

<p><a href="https://i.stack.imgur.com/D1djr.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D1djr.jpg" alt="Circuit"></a> </p>
 54083: <p>Two things to test:</p>

<ol>
<li>Have you tried to put an LED (and resistor to protect it) in the motor's place? If the brightness changes, your setup (Arduino+transistor) is working. If not, maybe you've killed your 2N2222 by giving it a wrong diode or something else is wrong.</li>
<li>Have you tried reducing the PWM frequency? An LED can follow a fast change, but a motor can't. Also, by turning on-off the motor less frequently you dissipate less power on your transistor and diode. A quick search gave me this: <a href="https://playground.arduino.cc/Code/PwmFrequency" rel="nofollow noreferrer">this</a>.</li>
</ol>
 38721: <p>Referring to <a href="https://www.google.com/url?sa=t&amp;source=web&amp;rct=j&amp;url=http://www.next.gr/components-datasheets/2N2222.pdf&amp;ved=2ahUKEwix_suovvDgAhUJJVAKHScsAS0QFjAMegQIBRAB&amp;usg=AOvVaw1xklGtj-dT4MeQx-P3bZ0e" rel="nofollow noreferrer" title="this datasheet">this datasheet</a> you have connected the transistor the wrong way around. Also, 1M resistor at the base is way too high. Bipolar transistors are <strong>current amplifiers</strong> (amplification at about 50-100 in your case) and with 1MOhm at the base there will be no current through the base at all. I would try with 2k for a beginning. 
I hope you have another transistor because this one seems to be broken and I'm pretty sure that it's not a fault in the analog output. If the output stage of the uC was broke there would be no reaction (at least in a correct circuit)</p>
