# Controlling 2-pin 12V fans intermittently

**URL:** <https://forum.arduino.cc/t/controlling-2-pin-12v-fans-intermittently/1126602>\
**Category:** General Guidance\
**Created:** [May 13, 2023, 5:53pm UTC](https://forum.arduino.cc/t/controlling-2-pin-12v-fans-intermittently/1126602 "2023-05-13T17:53:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Calado](https://avatars.discourse-cdn.com/v4/letter/c/67e7ee/32.png) [@Calado](https://forum.arduino.cc/u/Calado)\
**Post date:** [May 13, 2023, 5:53pm UTC](https://forum.arduino.cc/t/controlling-2-pin-12v-fans-intermittently/1126602/1 "2023-05-13T17:53:50Z")

</div>

Hi there,

I have what seems to be a simple project, but I can't get it to work. I have 12V fans hat will be powered every x hours for x minutes. The fans have only 2 pins and the project is being powered with an external power supply.  
The code itself should be pretty straight forward

```arduino
const int TRANSISTOR_PIN = 9; 
const unsigned long START_DELAY = 5000;
const unsigned long FAN_ON_TIME = 10000;
const unsigned long FAN_OFF_TIME = 10000; 
void setup() {
  pinMode(TRANSISTOR_PIN, OUTPUT); 
  delay(START_DELAY); 
}

void loop() {
  digitalWrite(TRANSISTOR_PIN, HIGH); 
  delay(10); 
  delay(FAN_ON_TIME); 
  digitalWrite(TRANSISTOR_PIN, LOW); 
  delay(FAN_OFF_TIME);
}

```

Now begins the problem, the wiring. I have FAN+, FAN-, Pin9, 12V+ and 12V-, using a transistor (IRLZ44N) as the switch.

The wiring is:

- 12V+ to FAN+
- 12V- to Drain
- FAN- to Source
- Pin9 to Gate

The fans spin, but Pin9 is redundant. Any other configuration, either limits the power to 5V as the output comes from the arduino, or doesn't work at all.

Any help is appreciated.

Cheers.

---

<div class="post-metadata">

**Author:** ![PaulRB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paulrb/32/216330_2.png) [@PaulRB](https://forum.arduino.cc/u/PaulRB)\
**Post date:** [May 13, 2023, 6:45pm UTC](https://forum.arduino.cc/t/controlling-2-pin-12v-fans-intermittently/1126602/2 "2023-05-13T18:45:41Z")

</div>

> [@Calado](#):
>
> - 12V- to Drain
> - FAN- to Source

Wrong way around!

Also you do not mention a flyback diode. Without this, you are playing Russian roulette.

A resistor (e.g. ~330R) between the Arduino pin and the Gate, and a 10K pulldown on the Arduino pin is also wise.

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [May 13, 2023, 7:36pm UTC](https://forum.arduino.cc/t/controlling-2-pin-12v-fans-intermittently/1126602/3 "2023-05-13T19:36:52Z")

</div>

Please grab pen and paper and make schematics showing the fan driver.  
That transistor is good.

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [May 13, 2023, 8:34pm UTC](https://forum.arduino.cc/t/controlling-2-pin-12v-fans-intermittently/1126602/4 "2023-05-13T20:34:43Z")

</div>

MOSFET motor driver. MOSFET and motor power supply must be able to handle motor stall current.

 ![mosfet motor driver](https://europe1.discourse-cdn.com/arduino/original/4X/c/b/5/cb567db03a08477481ed667a6b1d3d3e9bab6f2d.jpeg)

---

<div class="post-metadata">

**Author:** ![gilshultz](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gilshultz](https://forum.arduino.cc/u/gilshultz)\
**Post date:** [May 14, 2023, 1:00am UTC](https://forum.arduino.cc/t/controlling-2-pin-12v-fans-intermittently/1126602/5 "2023-05-14T01:00:26Z")

</div>

The diode must be able to take the motor current during flyback. If you have an avalanche rated MOSFET this diode will not be needed as the MOSFET will conduct at a lower voltage. Check the MOSFET data this information is now appearing on many of them.

---

<div class="post-metadata">

**Author:** ![Calado](https://avatars.discourse-cdn.com/v4/letter/c/67e7ee/32.png) [@Calado](https://forum.arduino.cc/u/Calado)\
**Post date:** [May 14, 2023, 7:26pm UTC](https://forum.arduino.cc/t/controlling-2-pin-12v-fans-intermittently/1126602/6 "2023-05-14T19:26:29Z")

</div>

Thanks for your replies, I got it working without a hiccup.

My only question resides with the flyback diode. I researched what it does and it's pretty simple to understand it's function, but where does it go? Can I just solder it to the fan leads, stripe to + and the other side to -? That's what I took from the schematic posted, but I'm not entirely sure that's what it shows.

Cheers

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [May 14, 2023, 7:32pm UTC](https://forum.arduino.cc/t/controlling-2-pin-12v-fans-intermittently/1126602/7 "2023-05-14T19:32:08Z")

</div>

I usually solder the diode and cap (if used) right to the motor terminals along with the power wires as you describe. Diode band to motor + and other end to motor -.

---

<div class="post-metadata">

**Author:** ![gilshultz](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gilshultz](https://forum.arduino.cc/u/gilshultz)\
**Post date:** [May 14, 2023, 8:09pm UTC](https://forum.arduino.cc/t/controlling-2-pin-12v-fans-intermittently/1126602/8 "2023-05-14T20:09:51Z")

</div>

It will not do anything if there is no inductance in the circuit. However if there is an inductor when you apply power it charges up forming a magnetic field. When you disconnect the power the inductor needs to discharge. To do this the polarity reverses and the voltage rises (no limit) until it is dissipated by something. This can be by a resistor, maybe the insulation failing, or whatever is in the circuit. In this case it is the MOSFET so if it is rated at a given drain source voltage and when that is exceeded the MOSFET is destroyed or at least damaged. This will dissipate the energy from the inductor and it will quit discharging.

Remember the polarity is reversed so when you turn it off the positive and negative switch polarity on the inductor, this in turn forward biases the flyback diode causing it to conduct. If there is no flyback diode the "avalanche" diode in the MOSFET conducts and dissipates the energy. This will also cause the MOSFET to dissipate the energy as heat. For calculations I use 2X the RDSon as the resistance value for the avalanche diode in the MOSFET. This needs to be taken into account when driving a inductive load. Switching such as PWM will make it get warmer as will other things.

This inductive flyback is the basic principle of switch mode power supplies including buck and boost modules. Also the "avalanche diode" is part of the structure of the MOSFET and not a separate entity.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [November 10, 2023, 8:10pm UTC](https://forum.arduino.cc/t/controlling-2-pin-12v-fans-intermittently/1126602/9 "2023-11-10T20:10:50Z")

</div>

Closed on November 10, 2023, 8:10pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
