Arduino Thermostat with NTC Thermistor and Relay
Level 27 · Level 27 — Keep It Warm · 30 minutes
Two lines and one remembered answer: a heater that holds steady instead of chattering at the edge of comfortable.

Preview the project free; a course seat is required to run and submit. No hardware kit needed.
Your project challenge
Switch a heater that holds steady between 18 and 22 °C instead of chattering. Wire it up: - Temperature sensor: VCC to 5V, GND to GND, OUT to A0 - Relay: VCC to 5V, GND to GND, IN to D7 Heater ON below 18 °C. OFF above 22 °C. Between them, change nothing. Switch within a second.
Components you’ll use
- Arduino Uno
- NTC Thermistor Module
- Relay Module
What you’ll build
A thermostat: a sensor reads the room, and a relay switches the heater.
How it works
readCelsius()turns the reading into degrees.- The sensor reads backwards: a colder room gives a higher number, and not in a straight line. That is why the helper exists.
- The relay is active low, as in Level 24. Heater ON means IN LOW.
- The reading wobbles by up to half a degree either way.
The key idea
One line makes the heater chatter. Park the room on it, and the wobble flips it on, off, on.
Use two lines: ON below 18, OFF above 22.
Between 18 and 22, change nothing.
At 20 °C the answer depends on where the room came from. Only a variable that outlives one pass of loop() remembers that. That gap is called hysteresis.
⚠ Watch out
- Turn the middle case into a plain
else, and the heater switches off as soon as the room passes 18. - Declare
heatingas a plain variable insideloop(), and it forgets on every pass. - Switch within a second of the room crossing a line.
The interactive editor includes the wiring guide, code editor and simulation controls.