Arduino - USB Power + DC Motor 9V Battery

I'm working on a project to learn more about Arduino and electronics in general.

The project involves:

(1) a small DC motor to act as a fan
(2) an element to boil water to create steam
(3) a pump to suck air out of a sealed container to create a vacuum

At this stage, I'm just testing the motor and my components on the breadboard are:

(1) PN2222 NPN BJT transistor
(2) 1N4048 diode
(3) 1K Ohm resistor

(see attached diagram - note the picture shows 2 AA batteries, but I'm using a 9V battery)

My UNO is connected to PC with the USB port and I'm using a 9V battery to power the motor. I've tested the battery which is fine.

When I run the sketch, the transistor gets quite hot and the motor hums, but it doesn't spin UNLESS I give it a helping flick, and then it spins quite fast.

Why does the motor not spin unless I give it a helping hand?

My basic code is as follows:

int MOTOR = 3;

void setup()
{
pinMode(MOTOR, OUTPUT);
...
}

void loop()
{
for (int i = 50; i < 256; i++)
{
analogWrite(MOTOR, i);
delay(20);
}
delay(3000);
for (int i = 255; i >= 0; i--)
{
analogWrite(MOTOR, i);
delay(20);
}
delay(5000);
}

UPDATE:

I'm still not sure why my previous setup did not work well, but I decided to do some research on the H-Bridge IC - how they function, what the IC pins do, etc.

I have managed to wire the IC up correctly and now my motor spins as it should with forward, reverse and brake :slight_smile: