Learn & build · Electronics · Part II · Chapter 23
Design your own: a thermostat fan
Six builds ago you were told where every leg goes. This chapter asks you to do the two things a designer does without being told. First, read someone else's schematic and find what's wrong with it, which is also how you'll catch your own mistakes. Then design a whole project from a one-paragraph spec, choosing every part yourself, with the answers folded away so you can check each decision after you've made it.
1. The design review
Each of these six schematics has one mistake, of the kind every chapter of Part II warned about. Some of them still simulate happily: a simulator only knows what its models tell it, which is part of the lesson. Click the part that's wrong, or its button. Hover the live ones for voltages: the evidence is often right there.
🎯 Challenge: find all six. 0 of 6 found.
A design review is the same checks you'd run on your own design: every part's job, every value against its datasheet, every input with a defined voltage, every coil with a path for its current, every address and every limit.
2. The spec
A thermostat fan. A 12 V computer fan (about 0.2 A) runs when the room is warmer than a temperature you set, and stops when it's cooler, without chattering around the threshold. The temperature can be read out (on a display or over Wi-Fi). Everything runs from one 12 V adapter.
From here on, every step is yours. Each question below is one decision; think it through (better: write it down), then open the answer. The answers are one good design, not the only one.
Step 1: the goal, as something you could test
Rewrite the spec as one sentence you could check with a thermometer and a stopwatch.
Step 2: the blocks
Chapter 20's dusk light did "sensor, threshold, switch" with a comparator and no code. Why would you use a microcontroller here instead?
- A comparator can't switch a fan
- The spec wants the temperature read out (a display or Wi-Fi), and a setpoint you can change: that's a computer's job
- A microcontroller is cheaper than a comparator
Step 3: the supply
The ESP32 board takes 5 V on its 5V pin and bursts to about a quarter of an amp on Wi-Fi. From 12 V, which regulator?
- An MCP1700
- A 7805, no heatsink
- A buck module set to 5 V
Step 4: the sensor
BME280 on I²C, or an NTC thermistor in a divider on an analog pin? What decides it?
Step 5: the fan switch
The ESP32 pin gives 3.3 V. Chapter 20 switched an amp with an IRLZ44N. Will it do here?
- Yes: it's logic-level, and the fan is only 0.2 A
- Not reliably: its datasheet only promises its on-resistance from 4 V up; pick a MOSFET specified at 2.5 V, like the AO3400A
- No MOSFET can be switched by 3.3 V
Three small parts go around the MOSFET. Name each one's job before you open this: a 100 Ω resistor in series with the gate, a 100 kΩ from gate to ground, and a diode across the fan.
Step 6: pins and grounds
Which ESP32 pin drives the fan, and what has to be true of the grounds?
3. The design, part by part
Here's the result of those decisions. The boards (the buck module, the ESP32, the sensor) are drawn as boxes with labels, as in chapter 22, and the drawing isn't simulated: the lab has no microcontroller. Pick any part for the reasoning behind it.
The one analog part, the fan driver, can be simulated on its own, with a 3.3 V square wave standing in for GPIO25 (slowed to 1 kHz so you can watch). Hover the drain while it switches, then take out D1.
🎯 Challenge: take out D1 and find how high the drain goes when the MOSFET turns off.
Where it breaks: the simulator's 611 V
Without D1, the simulator shows the drain flying to about 611 V at each turn-off, because its MOSFET model has no breakdown voltage: it shows how hard the coil pushes, with nothing to stop it. A real AO3400A is rated for 30 V; past that its drain breaks down and absorbs the energy as heat (chapter 4 §3's avalanche), which it survives a limited number of times. Either way the number is a warning, not a prediction: the real part fails somewhere between.
4. The fan driver on a breadboard
Your layout, your choice; here's one. The drain lives in two strips joined across the gap by the green jumper: the MOSFET's adapter board is in the bottom half, the fan's wire and D1 in the top. This build's own breadboard check caught exactly that jumper missing while this chapter was being written: it's the easiest wire to forget.
5. The shopping list
| Ref | Part | Why this one |
|---|---|---|
| U1 | Buck module (adjustable or 5 V) | 12 → 5 V at a fraction of a 7805's heat. Set 5.0 V before connecting. |
| C1 | 470 µF electrolytic, 10 V+ | Bulk capacitance against Wi-Fi brown-outs. |
| U2 | ESP32 dev board | The brains (chapter 22). |
| U3 | BME280 breakout | The temperature, I²C at 0x76. |
| Q1 | AO3400A on a SOT-23 adapter | Under 48 mΩ at a 2.5 V gate; 30 V; ±12 V gate. |
| R1, R2 | 100 Ω, 100 kΩ ¼ W | Gate current limit; gate pull-down for boot. |
| D1 | 1N5819 | Flyback, fast enough for 25 kHz PWM. |
| M1 | 12 V fan, ~0.2 A (2-wire) | A 4-wire PWM fan takes PWM on its own wire instead: read its spec. |
| BAT1 | 12 V adapter, 1 A | Fan + buck input with a margin. |
6. Your checklist
Write the power-up order for this build, chapter 17 style: what do you connect and measure first, second, third, and what reading must you see before going on?
- Buck module alone on 12 V, nothing on its output: adjust to 5.0 V.
- Add C1 and the ESP32 board (no sensor, no fan): its 3V3 pin reads 3.3 V; upload the I²C scanner.
- Add the BME280: the scanner finds 0x76; the lines idle at 3.3 V.
- Add the fan driver without the fan: the gate reads 0 V while the board resets (that's R2), and 3.3 V when the program turns GPIO25 on.
- Add the fan: it runs when the program says so; the MOSFET stays cool; the drain, on a scope, stays near 12 V at turn-off (D1 working).
- Last, the thermostat program, with a test: warm the sensor with your hand and time the fan against your step 1 sentence.
7. From breadboard to board
A breadboard proves the design; a printed board makes it last. Chapter 15's KiCad steps apply as they are: draw the schematic you just designed, choose footprints (the AO3400A is SOT-23, so on a PCB it needs no adapter), place the parts (decoupling and bulk capacitors by the chips they serve, the fan's connector and the 12 V jack at the edge), and size the traces: the fan's 0.2 A needs only a thin trace by chapter 15's rule, but the 12 V input feeds everything, so give it more. Pour a ground plane, run the design rules check, order five boards, and solder your first one with chapter 15's "heat the joint, not the solder."
8. Where to go from here
That's Part II. You can read a schematic, pick parts from datasheets, lay them out, check them, and find what's wrong. The next projects are yours: the build logs on this site (a USB-C power bank, an ESP32 remote, a solar weather node) use exactly these steps, and the circuit lab has every part from Part II to try a design before you buy anything.
Previous: A microcontroller board · All chapters: Learn & build.
Last updated