Temperature-controlled 12 V fan
Build it step by step
0 of 6 donePlace the MOSFET
IRLZ44N with the label facing you: gate, drain, source from left to right.
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.
Wire the gate
D9 through 220 Ω to the gate, 10 kΩ from gate to GND.
Wire the probe
Yellow to D2 with 4.7 kΩ to 5V, red to 5V, black to GND.
Power
12 V adapter to the fan and to Uno VIN, with one common ground.
Test
Warm the probe in your hand and then in warm (not boiling) water.
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
- Development BoardsBuyArduino Uno R3 × 1
- SensorsBuy
- PassivesBuyResistor 4.7 kΩ × 1
- SemiconductorsBuyMOSFET IRLZ44N × 1
- PassivesBuyResistor 220 Ω × 1Gate resistor
- PassivesBuyResistor 10 kΩ × 1Gate pull-down
- SemiconductorsBuy
- Motors & ActuatorsBuy
- PowerBuy
- PowerBuy
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| 12 V adapter + | Fan red wire and Uno VIN | Fan and board power |
| Fan black wire | IRLZ44N drain (middle leg) | Low-side switch |
| IRLZ44N source (right leg) | GND | Ground for fan and Uno |
| Uno D9 | 220 Ω to IRLZ44N gate (left leg), 10 kΩ gate to GND | PWM speed, off while the Uno boots |
| 1N5819 | Across the fan, stripe to 12 V + | Flyback protection |
| DS18B20 yellow | Uno D2, 4.7 kΩ to 5V | Temperature (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.
| Check | Expected |
|---|---|
| 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 % |
| MOSFET temperature at full speed | Barely 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 →
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.
