Problem using pn2222a transistor to run computer fan

As the title states I am trying to run a computer fan with an arduino and a pn2222a transistor. The fan is a 12V .16A 120mm fan produced by "Cooler Master". This power rating seems to me to be well withing the restraints of the 2222a, but correct me if I'm wrong. Based on the maximum amperage draw of the fan the base input into the transistor should be 1/10th of the flow from collector to emitter according to the spec sheet, so .016A. With the arduino driving 5v from one of its PWM pins I calculated the necessary resistor at a maximum of 312 Ohms ( 5V/.016A = 312.5 Ohms ), and the minimum resistance at 250 Ohms without damaging the arduino. In the diagram attached I showed how I used 2, 560 Ohm resistors in parrallel to create an equivalent resistance of 280 Ohms. The power supply shown is a 12v adjustable supply and the arduino is wired to its ground. My code is as follows

int pin = 12;
void setup() {
  // put your setup code here, to run once:
  pinMode(pin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  analogWrite(pin, 123);
}

Unfortunately, when I try to initiate the program the fan does nothing. Any help would be greatly appreciated as I am not very familiar with transistors and the math behind them.

Have you tried analogWrite 255?

Pin 12 is not a PWM pin, try 11, 3, 5, 6, 9, or 10. And you should have a reverse biased diode across the motor lines to protect the transistor from inductive kickback.

Thank you, I will try to use a different pin when I get a chance and post the results. What is the correct way to wire the diode because I have heard mixed opinions on different forums.

Use a 1 amp diode like 1N4003 and connect the cathode (end with stripe) toward + and anode toward - (transistor collector). Substitute the 12V on the drawing for the voltage you are using.
NPNMot-2.png

So connecting it like this? I color coded all the other wires for ease of reading.

NO! Not to the 3V3 pin, take the motor power from the power bus (red and blue lines), like your first pic.
Connect the diode cathode to the + (red) power bus, anode to transistor collector, H - 46.
How are you powering Arduino?

You've shorted the motor output to the A2 pin and the battery pack to the 3V3 pin - both mistakes will destroy your Arduino instantly.

Hi,
The 3.3V pin on the Aduino is a current output pin, NOT an input pin.

Tom... :slight_smile:

Whoops, I accidentally drew my diagram wrong, i meant to just connect the diode across the motor but i placed it in a clip that would connect to the arduino. I will definitely not try that.

Tested it and it works great! Thanks to edgemoron for the suggestions.