Build it step by step
0 of 8 doneSet the buck converter
Connect the 12 V adapter to the LM2596 only and turn the screw until the output reads 5.0 V.
Wire the 5 V rail
LM2596 output to the Nano 5V and GND pins, with the Nano unplugged from USB.
Wire the sensor
DS18B20 to 5V, GND and D2 with the 4.7 k between D2 and 5V.
Wire the OLED
SDA to A4, SCL to A5, 5V and GND.
Wire the MOSFET stage
Gate to D3 through 220 ohms, 10 k from gate to source, source to ground, fans between 12 V and the drain, diode across them.
Upload the sketch
The screen shows the temperature and a fan speed.
Warm the probe in your hand
The fan percentage climbs as the reading rises.
Unplug the probe
The screen says NO PROBE and the fans go to full speed.
How do you build a PWM fan hub for a PC case?
A DS18B20 temperature probe and a MOSFET make four 12 V case fans quieter when the box is cool and faster as it warms up. The screen shows the temperature and fan speed, and the fans go to full speed if the probe is ever lost. You need Arduino Nano, 12 V DC fan 80 mm × 4, DS18B20 Temperature Sensor, Resistor 4.7 kΩ, MOSFET IRLZ44N, Resistor 220 Ω, Resistor 10 kΩ, Rectifier Diode 1N4007, SSD1306 OLED Display, 12 V 2 A DC adapter, DC barrel to screw terminal adapter (female), LM2596 Buck Module, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 8 steps and about 120 minutes.
- Level
- Beginner
- Time
- About 120 min
- Parts
- 14
Parts list
- Development BoardsBuyArduino Nano × 1
- Motors & ActuatorsBuy
- SensorsBuy
- PassivesBuyResistor 4.7 kΩ × 1
- SemiconductorsBuyMOSFET IRLZ44N × 1
- PassivesBuyResistor 220 Ω × 1
- PassivesBuyResistor 10 kΩ × 1
- SemiconductorsBuy
- DisplaysBuy
- PowerBuy
- 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 | Screw terminal adapter | The only 12 V supply |
| Terminal + and - | LM2596 IN+ and IN- | Set OUT to 5.0 V with no load before connecting the Nano |
| LM2596 OUT+ and OUT- | Nano 5V and GND | Powers the Nano and the OLED |
| Four fans, red wires | Terminal + | Fans run in parallel at 12 V |
| Four fans, black wires | MOSFET drain (middle leg) | The MOSFET switches the ground side |
| 1N4007 | Stripe to terminal +, other end to the drain | Absorbs spikes from the fan coils |
| MOSFET source | Terminal - and Nano GND | All grounds are joined |
| MOSFET gate | 220 ohm to Nano D3 | PWM pin |
| 10 k from gate to source | Gate to GND | Keeps the fans off while the Nano restarts |
| DS18B20 red, black and yellow | Nano 5V, GND and D2 | Put it in the case, away from the fans |
| 4.7 k | Between D2 and 5V | The pull-up the sensor needs |
| OLED SDA and SCL | Nano A4 and A5 | I2C data and clock |
| OLED VCC and GND | Nano 5V and GND | Power for a 0.96 inch module |
Code
The sketch reads the temperature once a second and turns it into a fan speed with a straight line. At 30 degrees or below the fans run at about 35 percent, at 55 degrees or above they run flat out, and in between the speed rises smoothly. That is called a fan curve, and every PC fan controller uses one. The slowest speed is not zero because a fan that is turned down too far stops turning and does not restart by itself. The MOSFET is the switch: the Nano pin D3 sends pulses, called PWM, to its gate, and the longer each pulse, the more power the fans get. The 10 k resistor from gate to ground keeps the fans off while the Nano is starting, the 220 ohm resistor protects the pin, and the 1N4007 diode soaks up the voltage spike that a spinning fan coil makes when the switch opens. The most important line is the fail-safe: if the probe wire comes loose the library returns -127, and the sketch then sets full speed instead of leaving the fans slow in a hot box. Install "OneWire", "DallasTemperature", "Adafruit SSD1306" and "Adafruit GFX" from the Library Manager. Set the LM2596 to 5.0 V with a multimeter before you connect the Nano. Four fans at 12 V draw roughly one amp, which a 2 A adapter handles. Try changing T_LOW and T_HIGH to suit your own box.
Runs on a virtual Arduino Nano 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).
// Libraries: OneWire, DallasTemperature, Adafruit SSD1306 and Adafruit GFX.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
const uint8_t FAN_PIN = 3; // PWM pin to the MOSFET gate
const float T_LOW = 30.0; // at or below this: slowest speed
const float T_HIGH = 55.0; // at or above this: full speed
const uint8_t DUTY_MIN = 90; // about 35 percent, so the fans never stall
const uint8_t DUTY_MAX = 255;
OneWire oneWire(2);
DallasTemperature probe(&oneWire);
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
void setup() {
pinMode(FAN_PIN, OUTPUT);
analogWrite(FAN_PIN, DUTY_MAX); // full speed until the first reading
Serial.begin(9600);
probe.begin();
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}
void loop() {
probe.requestTemperatures();
float t = probe.getTempCByIndex(0);
uint8_t duty;
bool lost = (t == DEVICE_DISCONNECTED_C || t < -40);
if (lost) {
duty = DUTY_MAX; // fail safe: no reading means full cooling
} else if (t <= T_LOW) {
duty = DUTY_MIN;
} else if (t >= T_HIGH) {
duty = DUTY_MAX;
} else {
duty = DUTY_MIN + (uint8_t)((t - T_LOW) * (DUTY_MAX - DUTY_MIN) / (T_HIGH - T_LOW));
}
analogWrite(FAN_PIN, duty);
int percent = duty * 100 / 255;
oled.clearDisplay();
oled.setTextColor(SSD1306_WHITE);
oled.setTextSize(2);
oled.setCursor(0, 0);
if (lost) oled.print(F("NO PROBE")); else { oled.print(t, 1); oled.print(F(" C")); }
oled.setCursor(0, 28);
oled.print(F("Fans "));
oled.print(percent);
oled.print(F("%"));
oled.fillRect(0, 54, map(percent, 0, 100, 0, 128), 8, SSD1306_WHITE);
oled.display();
Serial.print(F("Temp "));
Serial.print(t, 1);
Serial.print(F(" C, fans "));
Serial.print(percent);
Serial.println(F("%"));
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 Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
Temp 24.5 C, fans 35%
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 | The fans turn slowly at about 35 percent |
| Hold the probe in your hand | The temperature climbs and the percentage rises |
| Dip the probe in warm water | Fans reach 100 percent at 55 degrees |
| Unplug the probe wire | NO PROBE shows and the fans run at full speed |
| Unplug USB and power up from the adapter | The fans stay off until the Nano has started |
If it does not work
Fans stay at full speed
The probe reads -127, so check the 4.7 k resistor and the three probe wires.
Fans do not turn
Check the diode and the fan wires, and that the MOSFET legs are gate, drain, source from the left with the flat side facing you.
Nano resets when the fans start
Keep the 5 V converter separate from the fan wires and add a 100 uF capacitor across the Nano power.
Whining from the fans
PWM can make a hum on some fans, so raise DUTY_MIN or try a different T_LOW.
Screen blank
Check SDA and SCL and try address 0x3D.
Upload fails
Choose the Old Bootloader option for the Nano.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the PWM fan hub for a PC case?
Arduino Nano, 12 V DC fan 80 mm × 4, DS18B20 Temperature Sensor, Resistor 4.7 kΩ, MOSFET IRLZ44N, Resistor 220 Ω, Resistor 10 kΩ, Rectifier Diode 1N4007, SSD1306 OLED Display, 12 V 2 A DC adapter, DC barrel to screw terminal adapter (female), LM2596 Buck Module, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the PWM fan hub for a PC case take to build?
About 120 minutes for a beginner maker, in 8 steps.
How do I know the PWM fan hub for a PC case works?
Probe at room temperature: The fans turn slowly at about 35 percent. Hold the probe in your hand: The temperature climbs and the percentage rises. Dip the probe in warm water: Fans reach 100 percent at 55 degrees.
Fans stay at full speed: what should I check?
The probe reads -127, so check the 4.7 k resistor and the three probe wires.
Fans do not turn: what should I check?
Check the diode and the fan wires, and that the MOSFET legs are gate, drain, source from the left with the flat side facing you.
Nano resets when the fans start: what should I check?
Keep the 5 V converter separate from the fan wires and add a 100 uF capacitor across the Nano power.
Whining from the fans: what should I check?
PWM can make a hum on some fans, so raise DUTY_MIN or try a different T_LOW.
