Controlling 12 V fan with Arduino digital pin

I spent one day trying to figure out how to trigger a DC 12 V computer fan (Brushless motor, two wires: black and red) to work with and Arduino. I tried relays, opto-couplers, mosfets with and without external power, until I found a solution. Here we go.

I suppose there are many ways to do it, but I think we lack just the right relays for relatively low power devices. They switch on 24v or 220V devices, and I just couldn’t get them work. So finally I found this tutorial which does exactly what I wanted.

Equipment needed:

Arduino
12 V DC (brushless) motor  / fan
TIP 102 transistor
1 Diode (e.g. 1N4004)
2.2 KOhm Resistor
12 V Power Supply

I don’t think it makes sense for me to redraw the schematic from the Bildr.org page so here it is:

combining arduino and 12 V motor

The red and black wires coming from the left are from an external power supply. The diode protects your transistor (and Arduino) from electrical voltage backslash that happens when motors are shut down. The resistor makes sure the current which goes to the Base of the transistor is correct (Emitter Cut-off current with 5V is 2 mA; I = U/R; Current = Voltage / Resistance).

After wiring this (breadboard or solder everything together) , you can write code that turns pin 9 on or off (high or low in Arduino programming). Alternatively, you can use the same pin with AnalogWrite (PWM) to make the fan rotate slower or faster, but at least the motor I was using was making a whiny noise when trying that.

Since you are using a 12 V power supply, adding a 5 V (or 3.3 V for mini)  regulator gives you power also for the Arduino. Use 2x 10uF 35v Capacitor (or 1x 10uf on output and 1x 100uf on input) ro protect from peaks.

Be careful to use a TIP102 or make sure you have the legs (b,c,e) of the transistor lined up in the same way. Also works for solenoids!