Switching external power supply to 5V cooling fan with an Arduino and 2N2222 transistor I'm using a 2N2222 transistor as a low-side switch to turn a 5V computer fan on and off with an Arduino digital pin, which responds programmatically to a button press - i.e. the relevant digital pin is switched from LOW to HIGH for a determined time in response to a button press recorded on A0.

My circuit looks like this:


And here's my code:

#define btnPin A0
#define signalPin 6

void setup() {
  pinMode(btnPin, INPUT_PULLUP);
  pinMode(signalPin, OUTPUT);
  digitalWrite(signalPin, LOW);
}

void loop() {
  if(digitalRead(btnPin) == LOW){
  digitalWrite(signalPin, HIGH);
  delay(5000);
  digitalWrite(signalPin, LOW);
  } 
}


For simplicity, I'm showing a separate button component in the diagram, but I'm actually using a button that's wired into an LCD shield.

My expectation is that, when I press the button, the digital pin wired to the transistor's base will cause the transistor to close the circuit and turn the fan (and LED) on for five seconds.

The problem that I have is that the Arduino's digital pin doesn't seem to be able to saturate the base, so not enough current passes through the transistor to power the fan. It does turn the LED on and off as expected, but the fan needs much more current than the LED. If I take a wire directly from VIN or the 5V pin and touch it to base (through a resistor, of course), it does succeed in saturating the base, and the fan turns on. Measuring the current from VIN (or the 5V pin) to base, I get 4mA, so my assumption is that 4mA is sufficient to saturate the base. My understanding is that an Arduino digital pin should easily supply this. But in my case, the current from the relevant digital pin to the transistor's base never goes higher than 1.4mA. I've tried different pins on the board, but always get the same result.

So the question is, why does the circuit work as expected for the LED, but not for the fan? Any help/suggestions will be greatly appreciated!
To fully turn the transistor on you should give the base somewhere around 1/10 to 1/20 of the collector current. If you read the datasheet for the PN2222 (a highly recommended activity) you will see that Vce(sat) is specified with Ic/Ib = 10. 

Now, the Microchip ATMega328 MCU chip in many (but not all) Arduinos is capable of sourcing 10mA or 15mA with minimal drop (assuming a 5V supply), again this information is available in the MCU datasheet (Figure 31-71 on page 355). 

So it appears you are using an "Arduino" with some other MCU. In which case you can either use another transistor to boost the current or substitute a logic-level MOSFET.