Projects / ESP32-C3 room climate web page

ESP32-C3 room climate web page

Beginner2 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32

    Wire the sensor

    VCC to 3V3, GND to GND, SDA to GPIO8, SCL to GPIO9.

  2. ESP32

    Install the library

    Adafruit AHTX0 from the Library Manager.

  3. ESP32AHT2025.0°C

    Edit the sketch

    Put your own Wi-Fi name and password in the two placeholder lines.

  4. ESP32

    Upload the sketch

    Open the Serial Monitor at 115200.

  5. ESP32

    Note the address

    The Serial Monitor prints a line like http://192.168.1.45.

  6. ESP32

    Open the address

    On a phone or computer on the same network.

  7. ESP32AHT2025.0°C

    Warm the sensor in your hand

    The temperature rises on the next refresh.

In short

How do you build an ESP32-C3 room climate web page?

A tiny ESP32-C3 SuperMini reads an AHT20 sensor and serves temperature and humidity as a web page on your home Wi-Fi. You need ESP32-C3 SuperMini, AHT20 temperature and humidity sensor and Breadboard 830 Tie Points. It takes 7 steps and about 120 minutes.

Level
Beginner
Time
About 120 min
Parts
3

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
AHT20 VCCESP32-C3 SuperMini 3V3Power at 3.3 V
AHT20 GNDESP32-C3 SuperMini GNDCommon ground
AHT20 SDAESP32-C3 SuperMini GPIO8I2C data
AHT20 SCLESP32-C3 SuperMini GPIO9I2C clock

Code

This build joins your home Wi-Fi and runs a very small web server, so any phone or computer on the same network can read the room's temperature and humidity in a browser. The AHT20 is a combined temperature and humidity sensor that talks over I2C, the two-wire bus, at address 0x38. The SuperMini board has no default I2C pins that you can rely on, so the program names them: GPIO8 for data and GPIO9 for clock. When a browser asks for the page, the program reads the sensor, builds a few lines of HTML and sends it back, and a refresh tag makes the browser ask again every ten seconds. The page is only reachable from inside your home network, so do not forward a port on your router to it. The wifi name and password in the sketch are placeholders; type your own, and remember not to share a sketch with your real password in it.

Runs on a virtual ESP32-C3 in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <WiFi.h>
#include <WebServer.h>
#include <Wire.h>
#include <Adafruit_AHTX0.h>

const char* WIFI_NAME = "YOUR_WIFI_NAME";          // placeholders: use your own network
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";

Adafruit_AHTX0 aht;
WebServer server(80);

void handleRoot() {
  sensors_event_t humidity, temp;
  aht.getEvent(&humidity, &temp);
  String page = "<!DOCTYPE html><html><head><meta charset='utf-8'>";
  page += "<meta name='viewport' content='width=device-width, initial-scale=1'>";
  page += "<meta http-equiv='refresh' content='10'><title>Room climate</title></head>";
  page += "<body style='font-family:sans-serif;text-align:center;margin-top:3em'>";
  page += "<h1>Room climate</h1>";
  page += "<p style='font-size:3em'>" + String(temp.temperature, 1) + " &deg;C</p>";
  page += "<p style='font-size:3em'>" + String(humidity.relative_humidity, 0) + " % humidity</p>";
  page += "<p>Updates every 10 seconds</p></body></html>";
  server.send(200, "text/html", page);
}

void setup() {
  Serial.begin(115200);
  Wire.begin(8, 9);                                // SDA on GPIO8, SCL on GPIO9
  if (!aht.begin()) {
    Serial.println("AHT20 not found, check the wiring");
    while (true) { delay(1000); }
  }
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print('.');
  }
  Serial.println();
  Serial.print("Open http://");
  Serial.println(WiFi.localIP());
  server.on("/", handleRoot);
  server.begin();
}

void loop() {
  server.handleClient();
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32-C3 DevKitM-1 with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

AHT20 not found, check the wiring

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Open the pageTemperature and humidity appear
Wait ten secondsThe page reloads by itself
Breathe gently on the sensorHumidity jumps up, then falls
Hold it in your handTemperature rises a little
Unplug and plug in againThe page works again with the same address

If it does not work

Serial Monitor shows nothing

Set USB CDC On Boot to Enabled in the Tools menu.

Sensor not found

Check SDA and SCL are on GPIO8 and GPIO9 and the module has 3.3 V.

Dots never stop

Check the Wi-Fi name and password, and that the network is 2.4 GHz.

Connects only near the router

Some SuperMini boards have a weak antenna; try WiFi.setTxPower(WIFI_POWER_8_5dBm) after WiFi.begin.

Page does not open

Make sure the phone is on the same Wi-Fi and use the exact address from the Serial Monitor.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the ESP32-C3 room climate web page?

ESP32-C3 SuperMini, AHT20 temperature and humidity sensor and Breadboard 830 Tie Points.

How long does the ESP32-C3 room climate web page take to build?

About 120 minutes for a beginner maker, in 7 steps.

How do I know the ESP32-C3 room climate web page works?

Open the page: Temperature and humidity appear. Wait ten seconds: The page reloads by itself. Breathe gently on the sensor: Humidity jumps up, then falls.

Serial Monitor shows nothing: what should I check?

Set USB CDC On Boot to Enabled in the Tools menu.

Sensor not found: what should I check?

Check SDA and SCL are on GPIO8 and GPIO9 and the module has 3.3 V.

Dots never stop: what should I check?

Check the Wi-Fi name and password, and that the network is 2.4 GHz.

Connects only near the router: what should I check?

Some SuperMini boards have a weak antenna; try WiFi.setTxPower(WIFI_POWER_8_5dBm) after WiFi.begin.