1

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: enter image description here

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!

5
  • 1
    Leave a specific question and use the circuit tool to draw a circuit, you'll get better answers
    – laptop2d
    Jul 2, 2018 at 1:32
  • The first thing I saw was a cartoon pretending to be a schematic! Closing and moving on.
    – Olin Lathrop
    Jul 2, 2018 at 11:53
  • The transistor in the Fritzing pictorial is connected backwards (E and C swapped) . Please supply a schematic. Jul 2, 2018 at 13:42
  • Please add a proper schematic. Fritzing is extremely difficult to read, even for simple circuits.
    – Felthry
    Jul 2, 2018 at 18:06
  • I did something similar with a S8050MD, which is similar to the 2N2222 but with higher gain. I also concur with @CrossRoads in his diode recommendation.
    – mongo
    Jan 2, 2019 at 13:43

4 Answers 4

2

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.

11
  • 1
    Thank you for the quick answer! I did actually read the 2N2222 datasheet, but confess that I'm finding the learning curve very steep, so I'm not sure I understand it all correctly. At any rate, from what I could understand, the circuit should work, unless as you say, my Arduino has some other MCU. It's entirely possible, as I bought these cheaply on eBay. I'll try with a logic-level MOSFET and see if that works...
    – artocignus
    Jul 1, 2018 at 18:38
  • What manner of Arduino are they? Jul 1, 2018 at 18:43
  • I have a couple. Both have UNO printed on the PCB, but they have slightly different layouts. One says "Mega328P AU 1722" on the chip. The chip on the other one is so small, I can hardly read the print on it.
    – artocignus
    Jul 1, 2018 at 18:53
  • The print on the second one looks like "ATMEL M328P U-CN 5473D 1805PWJ"
    – artocignus
    Jul 1, 2018 at 19:04
  • Then it should work. My assumption now is that you have E and C swapped on the transistor. Jul 1, 2018 at 19:30
1

I seem to have solved the problem. As mentioned in the question, I was using a button wired into an LCD shield. As the LCD shield occupies all the header pins on the Arduino, the LCD shield helpfully provides circuit connections for the unused Arduino pins. It seems that the LCD shield I was using has some fault which only allowed limited current to flow from the corresponding Arduino pins. This would explain the anomaly that only the LED lit up as expected, but the fan failed to work: presumably the weak current into the transistor's Base created sufficient gain to power the LED, but not the fan. Eventually, after many attempts at getting the circuit to work, even the LED stopped working and that's when I realised that there must be a continuity problem with the header connections. So, removing the LCD shield and wiring everything directly into the Arduino with a separate push button, everything started working as expected. Many thanks for all the helpful replies. I've got a much better handle on how BJTs work now!

1

Based on the description of your circuit, it sounds like you might not have connected the Arduino's ground to the "negative rail", the same part of the circuit where the transistor's emitter is connected. You must make that connection in order to properly bias the base-emitter junction of the transistor.

I recommend you draw a schematic for this sort of question, that would be helpful.

3
  • Thanks for the feedback. I've edited the question to include a schematic...
    – artocignus
    Jul 2, 2018 at 11:40
  • Sorry, yes my description of the circuit was incomplete. I did in fact have the Arduino's ground connected to the negative rail as shown in the schematic. The circuit works in principle, as the LED behaves as expected. The problem seems to be that the transistor does not let enough current through to power the fan. I suspect it's due to the base not being fully saturated by the digital pin.
    – artocignus
    Jul 2, 2018 at 11:49
  • A fritzing image is not considered to be a proper schematic on this site. It's hard to read the resistor values, and your image shows a transistor in a plastic package rather than a metal can, and you have swapped the emitter and collector connections.
    – Elliot Alderson
    Jul 2, 2018 at 11:50
0

You should also have a diode across the motor, cathode to 5V and anode to the transistor. When the transistor turns off, the motor will try and keep the 200mA current flowing. The diode lets that current dissipate. Without it, you can get a high voltage spike at the transistor which can damage it.

1
  • Thank you! This is actually one of the questions I had. I did put a flyback diode in the final circuit, just in case. Good to know that it isn't superfluous!
    – artocignus
    Oct 19, 2018 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.