Projects / Temperature-controlled 12 V fan

Temperature-controlled 12 V fan

Intermediate1.3 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. UNOIRLZ44

    Place the MOSFET

    IRLZ44N with the label facing you: gate, drain, source from left to right.

  2. UNO

    Wire the switch

    Fan black to drain, source to GND, fan red to 12 V plus. 1N5819 across the fan with its stripe to plus.

  3. UNO

    Wire the gate

    D9 through 220 Ω to the gate, 10 kΩ from gate to GND.

  4. UNODS18B2025.1°C

    Wire the probe

    Yellow to D2 with 4.7 kΩ to 5V, red to 5V, black to GND.

  5. UNO12DC

    Power

    12 V adapter to the fan and to Uno VIN, with one common ground.

  6. UNODS18B2025.1°C

    Test

    Warm the probe in your hand and then in warm (not boiling) water.

In short

How do you build a temperature-controlled 12 V fan?

A DS18B20 reads the temperature and a logic-level MOSFET runs a 12 V fan faster as it gets warmer, and off when it is cool. You need Arduino Uno R3, DS18B20 waterproof probe, Resistor 4.7 kΩ, MOSFET IRLZ44N, Resistor 220 Ω, Resistor 10 kΩ, Schottky Diode 1N5819, 12 V DC fan 80 mm, 12 V 2 A DC adapter, DC barrel to screw terminal adapter (female), Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 75 minutes.

Level
Intermediate
Time
About 75 min
Parts
12

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
12 V adapter +Fan red wire and Uno VINFan and board power
Fan black wireIRLZ44N drain (middle leg)Low-side switch
IRLZ44N source (right leg)GNDGround for fan and Uno
Uno D9220 Ω to IRLZ44N gate (left leg), 10 kΩ gate to GNDPWM speed, off while the Uno boots
1N5819Across the fan, stripe to 12 V +Flyback protection
DS18B20 yellowUno D2, 4.7 kΩ to 5VTemperature (red 5V, black GND)

Code

Arduino IDE, board "Arduino Uno". Install OneWire and DallasTemperature. The first line of setup() changes the PWM frequency of pins 9 and 10 only.

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <OneWire.h>
#include <DallasTemperature.h>

OneWire bus(2);
DallasTemperature probe(&bus);
const int FAN = 9;
const float START = 30.0, FULL = 40.0;   // fan starts at 30 °C, full speed at 40 °C

void setup() {
  // Timer 1 at about 31 kHz on D9/D10: no audible whine from the fan
  TCCR1B = (TCCR1B & 0b11111000) | 0x01;
  pinMode(FAN, OUTPUT);
  probe.begin();
  Serial.begin(9600);
}

void loop() {
  probe.requestTemperatures();
  float t = probe.getTempCByIndex(0);
  int duty = 0;
  if (t >= START) duty = map(constrain(t * 10, START * 10, FULL * 10), START * 10, FULL * 10, 100, 255);  // 40 % minimum so it spins up
  analogWrite(FAN, duty);
  Serial.print(t, 1); Serial.print(" C  fan "); Serial.print(duty * 100 / 255); Serial.println(" %");
  delay(1000);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Uno with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

24.5 C  fan 0 %

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Probe at room temperature (below 30 °C)Fan off, "fan 0 %"
Probe held in your handAbout 32 to 34 °C, fan at 50 to 60 %
Probe in water at about 45 °CFan at 100 %
MOSFET temperature at full speedBarely warm (the fan draws under 0.3 A)

If it does not work

Fan always on full

The MOSFET is wired as drain and source swapped, or the gate pull-down is missing.

Fan never starts

Use a logic-level MOSFET (IRLZ44N, not IRFZ44N), and check the fan's black wire goes to the drain.

Fan clicks at low speed

Raise the 100 minimum in map() to 130.

The Uno resets

The flyback diode is missing or reversed.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the temperature-controlled 12 V fan?

Arduino Uno R3, DS18B20 waterproof probe, Resistor 4.7 kΩ, MOSFET IRLZ44N, Resistor 220 Ω, Resistor 10 kΩ, Schottky Diode 1N5819, 12 V DC fan 80 mm, 12 V 2 A DC adapter, DC barrel to screw terminal adapter (female), Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). Resistor 220 Ω: Gate resistor. Resistor 10 kΩ: Gate pull-down.

How long does the temperature-controlled 12 V fan take to build?

About 75 minutes for a intermediate maker, in 6 steps.

How do I know the temperature-controlled 12 V fan works?

Probe at room temperature (below 30 °C): Fan off, "fan 0 %". Probe held in your hand: About 32 to 34 °C, fan at 50 to 60 %. Probe in water at about 45 °C: Fan at 100 %.

Fan always on full: what should I check?

The MOSFET is wired as drain and source swapped, or the gate pull-down is missing.

Fan never starts: what should I check?

Use a logic-level MOSFET (IRLZ44N, not IRFZ44N), and check the fan's black wire goes to the drain.

Fan clicks at low speed: what should I check?

Raise the 100 minimum in map() to 130.

The Uno resets: what should I check?

The flyback diode is missing or reversed.