Arduino Starter Kit · thermostat project

Auto Desk Fan

A small fan that switches itself on when your desk gets warmer than the temperature you pick, and spins faster the hotter it gets. A screen shows the room temperature, your target, and how hard the fan is working.

13 partsall from the Starter Kit
11 Uno pins5V, GND, A0, A1, 2–5, 9, 11, 12
~60 minwiring + upload + test
No solderingunless your LCD has no header pins

Building with an Elegoo kit instead? It works with two part swaps. See the Elegoo changes.

How it works

Sense, decide, switch

The Uno is the brain. Two things feed it information, and it controls two things. Everything else on the breadboard is there to protect the parts or keep power steady.

IN TMP36 sensor "how warm is it?" Target knob "how warm is too warm?" Arduino Uno compares the two, picks a fan speed, 4 times a second A0 · voltage A1 · voltage OUT 16×2 LCD screen Now 76.5°F / Set 73.0°F 62% MOSFET electronic switch DC motor the fan pins 2–5, 11, 12 pin 9 · PWM
1 · Read the room

The Uno reads the sensor 16 times and averages them to smooth out noise. The TMP36 gives 0.5 V at 0 °C plus 0.01 V per degree, so a 75 °F room reads about 0.74 V.

2 · Read the knob

Fully left is 64 °F, fully right is 90 °F, snapped to half-degree steps (in °C) so the number doesn't jitter.

3 · Decide

The fan turns on a little above your target and off a little below it. That gap stops it from clicking on and off when the room sits right at the target.

4 · Drive the fan

Pin 9 switches the MOSFET on and off about 490 times a second. More "on" time means a faster fan. From a stop it gets a 0.2 s full-power kick so the motor actually starts.

≤ 0.9 °F belowOff
near targetStays as it was
+0.9 °F aboveTurns on at 46%
+7.2 °F or moreFull speed, 100%
Speed climbs in a straight line between those points, for example 69% at 3.6 °F over. Once on, it slows to 39% at the target and shuts off 0.9 °F below it.
Meet the parts

What each piece does and how to hold it

Legs are drawn in the direction they'll point into the breadboard. The coloured dot under each leg matches the wire colours on the build diagram further down.

TMP 36 +Vs→5VA0GND flat facetoward you

TMP36 temperature sensor

Small black part, 3 legs, "TMP" printed on the flat face
What it does
Turns temperature into a voltage the Uno can measure. Warmer air, higher voltage.
How to hold it
Flat face toward you. Left leg to 5V, middle to A0, right to GND. Other small 3-legged kit parts look almost the same, so check the print.

Feels hot? It's in backwards. Unplug USB right away and turn it around.

5VwiperGND turn ↻

Potentiometer ×2

10kΩ knob · one for the target, one for LCD contrast
What it does
A knob like a volume dial. The middle leg's voltage slides from 0 V to 5 V as you turn it.
Target knob
Outer legs to 5V and GND, middle to A1. Picks 64–90 °F. If turning right lowers the target, swap the two outer legs.
Contrast knob
Outer legs to 5V and GND, middle to LCD pin 3. Adjusts how dark the letters look.
Now 76.5°F Set 73.0°F 62% 116 7–10 empty

16×2 LCD screen

Green board, 16 pins along one edge
What it does
Shows two rows of 16 letters. The Uno sends each letter in two halves over 4 data wires (D4–D7), with RS and E telling the screen when to listen.
Pins used
1 VSS→GND · 2 VDD→5V · 3 V0→contrast · 4 RS→12 · 5 RW→GND · 6 E→11 · 11–14 D4–D7→5,4,3,2 · 15 A→220Ω→5V · 16 K→GND
IRF520 GDS metal tabprinttoward you

IRF520 MOSFET

Black body with a metal tab on top
What it does
An electronic switch. A Uno pin can only supply a trickle of current, enough for an LED but not a motor. The MOSFET lets that trickle open and close the much bigger flow through the motor, like a finger flicking a light switch.
How to hold it
Printed side toward you. Left leg Gate (from pin 9), middle Drain (to the motor), right Source (to GND).
220Ω · red red brown 10kΩ · brown black orange

Resistors: 2 × 220Ω, 1 × 10kΩ

Read the colour bands from the end away from the gold band
220Ω on the LCD backlight
Limits current so the backlight doesn't burn out.
220Ω on pin 9
Softens the current spike each time pin 9 switches the MOSFET.
10kΩ from gate to GND
Holds the MOSFET off while the Uno is starting up, so the fan doesn't twitch at power-on.
Direction
Resistors work either way round.
plain end→ motor/drain row stripe end→ 5V rail current can only go → this way

1N4007 diode

Small black cylinder with a grey stripe at one end
What it does
A one-way valve for electricity. When the motor switches off, its coil kicks back a voltage spike. The diode gives that spike a loop back through the motor so it never hits the MOSFET or the Uno.
How to place it
Across the motor's two wires, stripe on the 5V side.

Stripe must face 5V. Backwards, it shorts 5V straight to GND every time the fan turns on.

wire 1 → 5Vwire 2 → drain shaft(blade here)

DC motor

Small silver can with two wires
What it does
Spins when current flows through it. More average current, faster spin.
Which wire where
Either wire to 5V, the other to the MOSFET's drain row. If air blows the wrong way, swap them.
− − + long→ 5V − short→ GND

100µF capacitor

Blue can, stripe with "−" marks one side
What it does
A tiny reservoir of charge. The motor gulps current when it starts; the capacitor covers the dip so the screen doesn't flicker and the Uno doesn't reset.
How to place it
Straight across the rails, close to the motor: long leg on 5V, short (striped) leg on GND.

Polarity matters. Backwards, this kind of capacitor can swell or pop.

Wire it

Step by step, with the circuit building up

Click a step (or just scroll through them) and the diagram shows only what's in place so far, with the new parts glowing. Switch between the Breadboard view (where every leg and wire physically goes) and the Wiring map (what connects to what). Hover or tap any wire on the breadboard to see its two ends.

Reading the breadboard

Holes are named by row letter and column number, like c4. Each column of five holes is joined inside the board: a4 to e4 are one connection, and f4 to j4 are another. The gap down the middle separates them.

The two long rails along the far edge run the whole length of the board. Blue line = − rail (GND), red line = + rail (5V). This layout fits a 30-column half-size board. On a bigger board, use the same hole names counting from the left end.

Whole circuit

Hover or tap a wire or part to see exactly where it goes.

  1. Uno + USB cablebreadboard + jumpersTMP362 × 10kΩ pot16×2 LCDIRF5201N4007DC motor100µF cap2 × 220Ω1 × 10kΩ
    • Everything is in the Arduino Starter Kit.
    • Keep USB unplugged while you wire. Only plug in when a step says so.

    Wire unplugged. Most mistakes are harmless if nothing is powered while you fix them.

    • Jumper from the Uno's 5V pin to the breadboard's red + rail.
    • Jumper from a Uno GND pin to the blue − rail.
    • If your breadboard has rails on both long edges, bridge + to + and − to − so both sides are live.
    • Flat face toward you, "TMP" print readable.
    • Left leg → 5V rail, middle leg → A0, right leg → GND rail.

    If it ever feels hot, it's in backwards. Unplug USB and turn it around.

    • One outer leg → 5V rail, the other outer leg → GND rail.
    • Middle leg → A1. This knob picks the target, about 64 °F to 90 °F.
    • Push the LCD's 16 pins into row a, columns 1–16. The screen hangs off the near edge of the board, so slide something the same height under it (a book, the kit box lid) to keep it level. If it has no header pins, they need soldering on first.
    • Power: pin 1 (VSS) → GND, pin 2 (VDD) → 5V, pin 5 (RW) → GND.
    • Contrast: second knob's outer legs → 5V and GND, middle leg → LCD pin 3 (V0).
    • Data: RS (pin 4) → 12, E (pin 6) → 11, D4 → 5, D5 → 4, D6 → 3, D7 → 2. Leave pins 7–10 empty.
    • Backlight: pin 15 (A) → 220Ω resistor → 5V. Pin 16 (K) → GND.
    • Copy the sketch from the code section into a new Arduino IDE sketch and save it as desk_fan.
    • Plug in USB. Pick Tools › Board › Arduino Uno and the right Port, then press Upload.
    • The LCD says "Desk fan ready", then shows Now and Set lines. Blank or solid blocks? Turn the contrast knob slowly.
    • Open Tools › Serial Monitor at 9600 baud: a line like temp=24.6,set=23.0,fan=0 appears each second (those are °C).

    Check: the LCD shows the room temperature, and turning the target knob changes the Set line.

    • Unplug USB first. Printed side toward you: legs are Gate, Drain, Source, left to right.
    • Pin ~9 → 220Ω resistor → a free row (the gate row). Put the MOSFET's gate leg in that row.
    • 10kΩ resistor from the gate row to GND.
    • Source (right leg) → GND. Drain (middle leg) sits in its own row: the motor row.
    • Motor wire 1 → 5V rail. Motor wire 2 → the motor row.
    • Diode across the motor: plain end in the motor row, striped end on the 5V rail.
    • 100µF capacitor across the rails near the motor: long leg on 5V, short striped leg on GND.
    • Optional: a 9V battery can power the motor instead of USB. Give it its own row (red to that row, black to GND) and move motor wire 1 and the diode's stripe to that row.

    Diode stripe must face 5V. Backwards, it shorts 5V to GND whenever the fan switches on.

    • Cut a small propeller from card (kit Project 9 has a pinwheel template) and press it onto the motor shaft.
    • Tape the motor down so it can't walk off the table.
    • Plug in USB. Turn the target below room temperature: the fan gives a short full-speed kick, then settles.
    • Pinch the TMP36 between your fingers: the temperature climbs and the fan speeds up.
    • Turn the target above room temperature: the fan stops.

    Check: the fan starts, speeds up as it warms, and stops when the target is above the room.

    • Plug the Uno into a USB phone charger or power bank. The sketch is stored on the board and runs by itself.
The code

desk_fan.ino

The exact sketch used in the build. LiquidCrystal comes with the Arduino IDE, so there's nothing extra to install.

desk_fan.ino · 110 lines

  
SHOW_FAHRENHEITSet to false to show °C on the screen.
MIN_PWM = 100Slowest speed that keeps your motor turning. If it hums but won't spin, raise it by 10–20 and upload again.
FULL_SPEED_C = 4.0How many °C over target reaches full speed (4 °C = 7.2 °F). Smaller makes it ramp up faster.
SET_MIN_C / SET_MAX_CThe knob's range, 18–32 °C (64–90 °F).
Other kits

Using an Elegoo kit

The Elegoo UNO R3 board is a copy of the Arduino Uno with the same pins, so the sketch and most of the wiring stay the same. Elegoo's Super Starter and Most Complete kits don't include the TMP36 or the IRF520, so two parts get swapped. Build the circuit with the steps above, then make the changes below.

This guideElegoo kitWhy it still works
TMP36 sensorThermistor + 10kΩ resistorA thermistor's resistance drops as it warms. Paired with a 10kΩ resistor it gives A0 a voltage that tracks temperature, just like the TMP36.
IRF520 MOSFETPN2222 transistor + 330Ω resistorAnother electronic switch. It handles up to 600 mA, plenty for the kit's small fan motor. It needs a little more current from pin 9, so its resistor is 330Ω instead of 220Ω.
Contrast knob1kΩ resistor (Super Starter only)The Super Starter kit has one knob, and the target needs it. A fixed resistor from LCD pin 3 to GND sets a contrast that suits most screens. The Most Complete kit has two knobs, so skip this swap.
100µF capacitorSame part, if your kit has itThe Most Complete kit has one. Without it the fan usually still runs; if the Uno resets when the motor starts, power the motor from the kit's Power Supply Module and 9V battery.
Card bladeThe kit's DC motor and fan bladeSkip step 09 and press the included blade onto the shaft.

Wiring changes (same hole names as the breadboard view)

  1. Temperature sensor. Leave out the TMP36. Put the thermistor's legs in f9 and f10 (either way round), and a 10kΩ resistor (brown black orange) from g8 to g9. The wires at j8, j9 and j10 stay as they are.
  2. Motor switch. Leave out the MOSFET. Hold the PN2222 with its flat face toward you and put its legs in f24, f25, f26: that's emitter, base, collector. Add a black wire from j24 to the − rail.
  3. Base resistor. Swap the 220Ω resistor at j21 → j25 for a 330Ω one (orange orange brown). The 10kΩ at h25 → h27 and the wire at j27 stay; they keep the fan off while the Uno starts up.
  4. Contrast (Super Starter only). Leave out the contrast knob. Put a 1kΩ resistor (brown black red) from h3 to h4. Keep the wire at j2, because it also powers the LCD. If the top row shows solid blocks, use a 2kΩ resistor instead; if the letters are too faint, wire h3 straight to h4.

Check the transistor's print. Most PN2222s read emitter, base, collector with the flat face toward you, but some makers swap the order. If the fan never turns on, compare the legs with the picture in Elegoo's tutorial.

Code change

Replace the readTempC() function in the sketch with this one. Everything else stays the same. In the Arduino IDE, still pick Tools › Board › Arduino Uno.

readTempC() · thermistor version
float readTempC() {
  long total = 0;
  for (int i = 0; i < 16; i++) total += analogRead(TEMP_PIN); // average out noise
  float raw = total / 16.0;
  float r = 10000.0 * raw / (1023.0 - raw);   // thermistor resistance in ohms
  float kelvin = 1.0 / (1.0 / 298.15 + log(r / 10000.0) / 3950.0);
  return kelvin - 273.15 + 0.0;                // Kelvin to degrees C, plus your correction
}

Thermistors vary a little from part to part, so compare the screen with a thermometer after a few minutes. If it reads high, change the 0.0 on the last line to a negative number; if it reads low, make it positive. The correction is in °C, and 1 °C is 1.8 °F, so a screen that reads 2.7 °F high needs -1.5.

Why not the DHT11? Elegoo kits also include a DHT11 temperature and humidity module. It only reports whole degrees Celsius, which is too coarse for a fan that switches half a degree either side of the target, so the thermistor is the better fit.

If something's off

Troubleshooting

LCD is blank or shows solid blocks

Turn the contrast knob slowly end to end. Still blank: check LCD pins 1, 2 and the backlight (15, 16).

Temperature reads way too low or high

The middle TMP36 leg isn't reaching A0, or the sensor is reversed. Check it's the TMP36, not a similar-looking transistor.

Fan hums but doesn't spin

Raise MIN_PWM. Also check the blade isn't rubbing.

Fan never turns on

Turn the target knob fully left. Then check pin 9 → 220Ω → gate, source to GND, and the motor between 5V and drain.

Fan never turns off

Drain and source are probably swapped, or the gate row touches 5V. Unplug and re-seat the MOSFET, printed side toward you.

Uno resets or LCD flickers when the fan starts

USB power is dipping. Make sure the 100µF capacitor is in and the right way round, or power the motor from a 9V battery.

Knob works backwards

Swap the knob's two outer legs.

Fan blows the wrong way

Swap the two motor wires.