WiFi temperature – humidity station (ESP32)
FreeINO

WiFi temperature – humidity station (ESP32)

Build your own temperature and humidity station with ESP32 and DHT22 and view readings on your phone over WiFi. Step-by-step guide, free source code.

Downloadable files

  • tram_do.ino
    Arduino source code · 2 KB
    Download

License CC BY 4.0 — free to use, credit “OctaX.vn”. Demo the production version requires a free account to download.

Want to customize it?

The OctaX assistant adjusts dimensions, content and branding on request — estimated ≈ 4 credits.

✦ Customize with AI

Materials

  • ESP32 DevKit
  • DHT22 sensor (AM2302)
  • 10 kΩ resistor
  • Jumper wires, breadboard
  • USB cable, 5V power supply

Steps

  1. Install the Arduino IDE, add the ESP32 board (Espressif) and Adafruit's "DHT sensor library".
  2. Wire the DHT22: pin 1 → 3V3, pin 2 (DATA) → GPIO4 with a 10 kΩ pull-up resistor to 3V3, pin 4 → GND.
  3. Open the source code and enter your WiFi name and password in TEN_WIFI, MAT_KHAU.
  4. Upload the code and open the Serial Monitor (115200) to see the IP address.
  5. Open a browser on your phone (same WiFi) at that IP address: the page refreshes every 10 seconds.

Source code

// Trạm đo nhiệt độ – độ ẩm WiFi — OctaX.vn (CC BY 4.0)
// Bo: ESP32. DHT22 DATA → GPIO4 (kéo lên 10 kΩ về 3V3). Cần thư viện "DHT sensor library" (Adafruit).
#include 
#include 
#include 

const char* TEN_WIFI = "ten-wifi";      // ← điền tên WiFi
const char* MAT_KHAU = "mat-khau-wifi"; // ← điền mật khẩu WiFi

DHT dht(4, DHT22);
WebServer may(80);
float nhietDo = NAN, doAm = NAN;
unsigned long lanDoTruoc = 0;

// Trang web gọn: tự làm mới mỗi 10 giây
void trangChu() {
  String h = ""
             "Trạm đo"
             ""
             "

Trạm đo OctaX

"; if (isnan(nhietDo)) h += "

Chưa đọc được cảm biến — kiểm tra dây DATA và điện trở kéo lên.

"; else h += "

" + String(nhietDo, 1) + " °C

" "

" + String(doAm, 0) + " %

"; may.send(200, "text/html; charset=utf-8", h); } // Trả dữ liệu dạng JSON cho ứng dụng khác đọc (vd OctaX MiniApp) void duLieu() { may.send(200, "application/json", "{\"nhietDo\":" + String(nhietDo, 1) + ",\"doAm\":" + String(doAm, 0) + "}"); } void setup() { Serial.begin(115200); dht.begin(); WiFi.begin(TEN_WIFI, MAT_KHAU); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.print("\nMở trình duyệt vào: http://"); Serial.println(WiFi.localIP()); may.on("/", trangChu); may.on("/du-lieu", duLieu); may.begin(); } void loop() { may.handleClient(); // DHT22 chỉ nên đọc tối đa 1 lần / 2 giây if (millis() - lanDoTruoc > 2500) { lanDoTruoc = millis(); float t = dht.readTemperature(), a = dht.readHumidity(); if (!isnan(t) && !isnan(a)) { nhietDo = t; doAm = a; } } }

Related templates

3-tier wall-mounted wooden bookshelf
FreeCSV

3-tier wall-mounted wooden bookshelf

Build a 3-tier 800×600 mm wall-mounted wooden bookshelf: cut list, tools, step-by-step assembly and secure mounting. Free CSV download.

🛠️ DIY