Projects / ESP32-C3 greenhouse climate page

ESP32-C3 greenhouse climate page

An ESP32-C3 SuperMini reads an SHT31 sensor in a small greenhouse or propagator and serves temperature, humidity and the highest and lowest values on a local page.

Intermediate2.3 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32

    Wire the sensor

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

  2. ESP32SHT3129.1°C

    Install the library

    Adafruit SHT31 from the Library Manager.

  3. ESP32SHT3129.1°C

    Edit the sketch

    Put your own Wi-Fi name and password in the placeholders.

  4. ESP32

    Upload it

    The Serial Monitor prints an address like http://192.168.1.45.

  5. ESP32

    Open the address

    On a phone on the same network.

  6. ESP32SHT3129.1°C

    Breathe on the sensor

    Humidity jumps.

  7. ESP32

    Place it in the greenhouse

    Under the vented cover, out of the sun.

In short

How do you build an ESP32-C3 greenhouse climate page?

An ESP32-C3 SuperMini reads an SHT31 sensor in a small greenhouse or propagator and serves temperature, humidity and the highest and lowest values on a local page. You need ESP32-C3 SuperMini, SHT31 temperature and humidity sensor and Breadboard 830 Tie Points. It takes 7 steps and about 140 minutes.

Level
Intermediate
Time
About 140 min
Parts
3

Parts list

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

Wiring

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

Code

Seedlings and cuttings do best in a steady temperature and a humidity that is high but not dripping. The SHT31 is an accurate digital sensor for both, and it talks over I2C at address 0x44. The ESP32-C3 reads it each time the page is opened, keeps the highest and lowest values it has seen, and sends a page with a refresh tag so it updates itself every thirty seconds. The extremes tell you more than the live value, for example how cold the greenhouse got overnight. The sensor has a small heater inside to drive off condensation, and the program leaves it switched off. A long time at near 100 percent humidity can make any humidity sensor read high, so keep the module under a small vented cover, out of direct spray and out of sunlight. The page is only for your home network. Keep the electronics dry and the USB lead protected.

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_SHT31.h>

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

Adafruit_SHT31 sht31;
WebServer server(80);

float tMin = 1000, tMax = -1000, hMin = 1000, hMax = -1000;

void handleRoot() {
  float t = sht31.readTemperature();
  float h = sht31.readHumidity();
  if (!isnan(t)) { tMin = min(tMin, t); tMax = max(tMax, t); }
  if (!isnan(h)) { hMin = min(hMin, h); hMax = max(hMax, h); }
  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='30'><title>Greenhouse</title></head>";
  page += "<body style='font-family:sans-serif;text-align:center;margin-top:2em'>";
  page += "<h1>Greenhouse</h1>";
  page += "<p style='font-size:3em'>" + String(t, 1) + " &deg;C</p>";
  page += "<p style='font-size:3em'>" + String(h, 0) + " % humidity</p>";
  page += "<p>Temperature " + String(tMin, 1) + " to " + String(tMax, 1) + " &deg;C since start</p>";
  page += "<p>Humidity " + String(hMin, 0) + " to " + String(hMax, 0) + " % since start</p>";
  page += "<p><a href='/reset'>Reset the highs and lows</a></p></body></html>";
  server.send(200, "text/html", page);
}

void handleReset() {
  tMin = 1000; tMax = -1000; hMin = 1000; hMax = -1000;
  server.sendHeader("Location", "/");
  server.send(303);
}

void setup() {
  Serial.begin(115200);
  Wire.begin(8, 9);
  if (!sht31.begin(0x44)) {                        // use 0x45 if the address pin is high
    Serial.println("SHT31 not found, check the wiring");
    while (true) { delay(1000); }
  }
  sht31.heater(false);                             // keep the built-in heater off
  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.on("/reset", handleReset);
  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.

SHT31 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 thirty secondsThe page refreshes by itself
Breathe on the sensorHumidity rises, then falls back
Warm the sensor in your handA new high appears
Tap ResetThe highs and lows start again

If it does not work

SHT31 not found

Check SDA on GPIO8, SCL on GPIO9 and the address 0x44 or 0x45.

Dots never stop

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

Humidity stuck near 100 percent

Let the sensor dry out in a warm room, and shield it from spray.

Temperature reads high in the sun

Shade the sensor.

Page does not open

Use the exact address from the Serial Monitor and the same Wi-Fi.

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 greenhouse climate page?

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

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

About 140 minutes for a intermediate maker, in 7 steps.

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

Open the page: Temperature and humidity appear. Wait thirty seconds: The page refreshes by itself. Breathe on the sensor: Humidity rises, then falls back.

SHT31 not found: what should I check?

Check SDA on GPIO8, SCL on GPIO9 and the address 0x44 or 0x45.

Dots never stop: what should I check?

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

Humidity stuck near 100 percent: what should I check?

Let the sensor dry out in a warm room, and shield it from spray.

Temperature reads high in the sun: what should I check?

Shade the sensor.