Arduino-Based Room Temperature Monitor
Content:
Learn how to measure room temperature using the original LM35 temperature sensor and display it on an LCD with Arduino. Perfect for beginners who want to understand temperature sensing and real-time display.
Arduino-Based Room Temperature Monitor
Ever wonder exactly how warm your room gets in summer, or whether your basement stays cold enough for your server rack? A $5 sensor, an Arduino, and an afternoon is all it takes to build a fully functional room temperature and humidity monitor with a real-time LCD display — no cloud subscription required.
In this guide we'll wire up a DHT11 sensor (or the more accurate DHT22) to an Arduino Uno, write clean sketch code to read and display data on a 16×2 LCD, and optionally add a threshold LED alert. By the end you'll have a standalone device that powers up and runs forever without a computer attached.
Why Build This?
Commercial thermostats and weather stations cost $30–$150 and are locked down black boxes. Building your own means you understand every component, can customize the display, log data to an SD card, trigger alerts, or pipe readings over serial to a Raspberry Pi for graphing. This project is a perfect foundation.
Components You'll Need
| Component | Qty | Approx. Cost | Notes |
|---|---|---|---|
| Arduino Uno R3 | 1 | $12–$25 | Any ATmega328P board works |
| DHT11 or DHT22 Sensor | 1 | $1–$4 | DHT22 for ±0.5°C accuracy |
| 16×2 LCD (HD44780) | 1 | $3–$8 | I2C module saves pins |
| I2C LCD Adapter | 1 | $1–$3 | PCF8574 backpack |
| 10kΩ Resistor | 1 | <$0.10 | Pull-up for DHT data pin |
| LED + 220Ω Resistor | 1 each | <$0.50 | Optional alert indicator |
| Breadboard + jumpers | 1 set | $3–$6 | Half-size board is plenty |
| USB-A to USB-B cable | 1 | — | Came with your Arduino |
Circuit Wiring
We're using an I2C LCD to keep pin usage minimal — it only needs 4 wires total (power, ground, SDA, SCL). The DHT sensor adds one more data pin. Here's the full wiring map:
0x27 or 0x3F. A scanner sketch is included at the bottom of this post.
Installing Libraries
Search for DHT sensor library by Adafruit. Install it and accept the dependency on Adafruit Unified Sensor when prompted.
Search for LiquidCrystal I2C by Frank de Brabander and install it. This abstracts all the LCD timing for you.
Under Tools → Board select Arduino Uno. Under Tools → Port select the COM port (Windows) or /dev/cu.usbmodem… (Mac/Linux) where your board appears.
The Sketch
Below is the complete annotated sketch. Paste it into a new IDE window, adjust the ALERT_TEMP threshold to your liking, and upload.
// ─────────────────────────────────────────────
// Room Temperature Monitor
// Hardware: Arduino Uno + DHT22 + I2C 16x2 LCD
// ─────────────────────────────────────────────
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// ── Pin & sensor configuration ──────────────
#define DHT_PIN 2
#define DHT_TYPE DHT22 // Change to DHT11 if needed
#define LED_PIN 13
#define ALERT_TEMP 28.0 // °C — LED fires above this
// ── LCD: address, columns, rows ─────────────
LiquidCrystal_I2C lcd(0x27, 16, 2);
DHT dht(DHT_PIN, DHT_TYPE);
void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Temp Monitor v1");
lcd.setCursor(0, 1);
lcd.print(" Initializing…");
dht.begin();
delay(2000); // DHT needs time to stabilise
}
void loop() {
float humidity = dht.readHumidity();
float tempC = dht.readTemperature();
float tempF = dht.readTemperature(true);
float heatIndex = dht.computeHeatIndex(tempC, humidity, false);
// Validate readings
if (isnan(humidity) || isnan(tempC)) {
lcd.clear();
lcd.print("Sensor error!");
Serial.println("DHT read failed.");
delay(2000);
return;
}
// ── LCD Row 0: Temperature ───────────────
lcd.setCursor(0, 0);
lcd.print("T:");
lcd.print(tempC, 1);
lcd.print("\xDF""C HI:");
lcd.print(heatIndex, 1);
// ── LCD Row 1: Humidity ──────────────────
lcd.setCursor(0, 1);
lcd.print("H:");
lcd.print(humidity, 1);
lcd.print("% F:");
lcd.print(tempF, 1);
// ── Threshold alert ──────────────────────
digitalWrite(LED_PIN, tempC > ALERT_TEMP ? HIGH : LOW);
// ── Serial log (for plotting or data logging)
Serial.print("Temp: "); Serial.print(tempC);
Serial.print("°C Humidity: "); Serial.print(humidity);
Serial.print("% HeatIndex: "); Serial.println(heatIndex);
delay(2000); // DHT min sample rate is ~1s
}
How It Works
Reading the Sensor
The DHT22 uses a single-wire protocol. The library handles all the timing-critical bit-banging. Calls to readTemperature() and readHumidity() return floating-point values. Always call isnan() to guard against occasional bad reads — this sensor can glitch on first boot or if your power supply is noisy.
Heat Index
The computeHeatIndex() function calculates the "feels like" temperature using the Rothfusz regression formula, which combines temperature and relative humidity. This is particularly useful in humid climates where 28°C at 80% RH feels significantly hotter than 28°C at 40% RH.
The LCD Display
The I2C LCD adapter reduces your wiring from 6–10 pins to just 4 (VCC, GND, SDA, SCL). Behind the scenes it uses a PCF8574 I/O expander chip to drive the HD44780 LCD controller in 4-bit mode. The LiquidCrystal_I2C library handles all of this transparently.
Alert LED
A simple digitalWrite keyed to a threshold comparison. In a production build you might swap this LED for a buzzer, a relay driving a fan, or an SMS via a SIM800L module.
Calibration Tips
The DHT11 is accurate to ±2°C; the DHT22 to ±0.5°C. If you need tighter accuracy, compare your reading to a calibrated reference thermometer and add a constant offset in the sketch:
tempC = dht.readTemperature() + 0.8; // your calibration offset
Also keep the sensor away from direct sunlight, heat vents, and computer exhaust — ambient airflow gives the most representative room reading.
Going Further
This build is a solid foundation. Here are natural next steps depending on your interests:
Data Logging — Add an SD card module and log timestamped readings to a CSV. Pair with an RTC module (DS3231) for accurate timestamps even across power cycles.
Wi-Fi Upload — Swap the Uno for an ESP8266 or ESP32 (both speak Arduino IDE) and push readings to ThingSpeak, InfluxDB, or a Home Assistant MQTT broker for historical graphing.
Multiple Rooms — Run several DHT sensors on different data pins, cycle through them in loop(), and display per-room stats — or build a small sensor network with cheap 433 MHz radio modules (nRF24L01).
OLED Upgrade — Replace the 16×2 LCD with a 128×64 SSD1306 OLED for a slicker graphical display including a scrolling temperature history graph.
0x27 in the main code if needed.
#include <Wire.h>
void setup() {
Wire.begin(); Serial.begin(9600);
Serial.println("Scanning I2C bus…");
for(byte addr=1; addr<127; addr++) {
Wire.beginTransmission(addr);
if(Wire.endTransmission()==0) {
Serial.print("Device at 0x"); Serial.println(addr, HEX);
}
}
}
void loop(){}
Wrapping Up
You now have a self-contained room temperature monitor that boots instantly, draws under 100mA, and can run indefinitely from a 5V USB phone charger or a 9V wall adapter. The total BOM cost is under $15, and the skills you practiced — I2C communication, sensor polling, defensive coding with isnan() — transfer directly to dozens of other sensor projects.
Build it, hack it, make it your own. If you log your calibration offsets or adapt the sketch for a different sensor, drop a note in the comments. Happy making. ✦
Comments
Post a Comment