ExpertAutomation and Power
Temperature-Controlled 12 V Fan
Use a temperature sensor, MOSFET, and PWM control to vary a small 12 V fan's speed as temperature rises.
Parts from the database
- MCP9808-E/MS ร 1Digital temperature sensor breakout
- IRLB8721PBF ร 1Logic-level N-channel MOSFET
- ESP32-WROOM-32 ร 1Use on a development board
Other supplies
- 3.3 V MCP9808 breakoutCommon build supply
- small 12 V brushless fanCommon build supply
- 12 V current-limited supplyCommon build supply
- logic-level MOSFET gate resistor and pull-downCommon build supply
- flyback/suppression parts if required by the fanCommon build supply
- fuse and jumper wiresCommon build supply
Amazon links may be affiliate links. As an Amazon Associate, Electronics Hobby Hub earns from qualifying purchases.
Connections
- Power sensor from 3V3 and connect IยฒC SDA/SCL to the ESP32 bus.
- Switch fan low-side: fan positive to +12 V, fan negative to MOSFET drain, MOSFET source to supply ground.
- Connect ESP32 PWM through a small gate resistor to MOSFET gate and add a gate-to-ground pull-down; share ground between supplies.
- Add a fuse in the 12 V fan feed. Confirm the MOSFET is driven at 3.3 V gate and the fan accepts PWM switching.
Build steps
- Test the sensor reading without the fan and confirm plausible room temperature.
- Test fan on/off with the MOSFET at a low duty cycle before enabling temperature control.
- Set a start temperature and a separate stop temperature (hysteresis) to avoid rapid toggling.
- Use a thermometer to compare sensor placement, then tune PWM range and minimum fan speed.
Software and firmware setup
Firmware is required, but a complete ESP32 control sketch is not included yet. Run the MCP9808 library example first, then add a PWM output with separate turn-on/turn-off temperature thresholds (hysteresis). Test MOSFET switching with the fan supply fused and the fan clear of fingers; confirm your exact fan tolerates the chosen PWM method.
Test your build
The fan should remain off below the setpoint and ramp up above it without repeated chatter. A MOSFET's gate-threshold number alone does not guarantee low on-resistance; use the specified logic-drive ratings.
Troubleshooting
- If the ESP32 resets when the fan starts, improve supply separation and grounding.
- If fan speed control does not work, use a 4-wire PWM fan or check whether the 2-wire fan tolerates supply PWM.
- If the MOSFET gets hot, stop and verify gate voltage, current, switching rate, and heatsinking.
Safety and limitations
Use a small fused 12 V supply, not a vehicle or mains source. Keep fingers clear of fan blades and observe MOSFET thermal limits.
Manufacturer and platform documentation
Community Notes for This Project
These are unverified visitor contributions, separate from the build guide and manufacturer specifications. Verify technical advice against the linked datasheets before relying on it.
Set up the comments service to load community notes.