Electronic – arduino – How to use a 2n2222 transistor to pull a pin to ground

arduinodigital-logicfanmicrocontrollertransistors

I am trying to use a microcontroller (specifically attiny85) to "fake" a computer fan on a computer motherboard. For the computer to recognize a fan, the tachometer pin on the motherboard must be pulled low twice per revolution of the fan. Thus, I am generating a square wave of arbitrary frequency with the microcontroller and I want to use a transistor to pull the tach pin low whenever the microcontroller output is high. GND is shared by the microcontroller and the computer. The tach pin normally sits at approximately 2.5 v when not pulled down. I currently have the following circuit:

enter image description here

When this is hooked up, it seems to shutdown the microcontroller, and resets when I unhook any of the connections on the transistor. Can anyone tell me what I am doing wrong?

Best Answer

Three problems:

Transistor base current

You are murdering the transistor base. The connection between the base and emitter can be treated much like a diode. When you connect 5 V directly to it, you essentially short-circuit the CPU output pin and a huge amount of current will flow.

In your case it will be limited by the attiny's output current limit, which is only supposed to be used in "emergencies" like this. The circuit will still draw a lot of current through the CPU power supply pin, likely lower it intermittently to a voltage that is too low to function or trigger the brown out detection that reset the CPU.

All of this can be solved with a simple resistor:

schematic

simulate this circuit – Schematic created using CircuitLab

This limits the current to about 0.5 mA, which should be enough to drive your transistor in this case. Decrease it to something like 4.7k or 2k if it doesn't work, but it should.

CPU resetting

You may have too little decoupling capacitance on the CPU voltage input. Make sure there's at least 1 µF of capacitance between GND and VCC near the CPU VCC input pin, and this kinds of CPU resets should be less common.

Tachometer pull-up

You may need a 10k pull-up from the tachometer input to the fan +12 V supply. Right now you are measuring around 2.5 volts which suggests that it is may be floating. I'm not sure if it is necessary in this case, but try that if you can't get this to work. I'm getting some conflicting information when searching for details about this input, a comment by Spehro Pefhany suggests that this may even be harmful, and I agree. The pull-up should not be necessary.