Projects / Terrarium mist reminder

Terrarium mist reminder

Intermediate2.2 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32SHT3128.8°C

    Wire the sensor and display

    Both to 3V3, GND, GPIO21 and GPIO22.

  2. ESP32

    Wire the buzzer

    Plus to GPIO25, minus to GND.

  3. ESP32

    Wire the mute button

    GPIO26 to GND.

  4. ESP32SHT3128.9°CSSD1306

    Install the libraries

    Adafruit SHT31, SSD1306 and GFX.

  5. ESP32SHT3128.9°C

    Upload the sketch

    The display shows humidity and temperature.

  6. ESP32SHT3128.9°C

    Breathe near the sensor

    The humidity rises.

  7. ESP32SHT3128.9°C

    Test a limit

    Set DRY_BELOW above the room value and wait for the beep.

In short

How do you build a terrarium mist reminder?

An ESP32 with an SHT31 sensor watches the humidity in a terrarium, shows it on an OLED and beeps a reminder to mist the plants when the air gets too dry or to open the lid when it has been too wet for too long. You need ESP32 DevKit V1, SHT31 temperature and humidity sensor, SSD1306 OLED Display, Passive buzzer, Tactile push button 6 mm and Breadboard 830 Tie Points. It takes 7 steps and about 130 minutes.

Level
Intermediate
Time
About 130 min
Parts
6

Parts list

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

Wiring

FromToWhy
SHT31 VCCESP32 3V3Power at 3.3 V
SHT31 GNDESP32 GNDCommon ground
SHT31 SDA and SCLESP32 GPIO21 and GPIO22I2C, address 0x44
OLED VCCESP32 3V3Power at 3.3 V
OLED GNDESP32 GNDCommon ground
OLED SDA and SCLESP32 GPIO21 and GPIO22Shared I2C bus, address 0x3C
Passive buzzer +ESP32 GPIO25Tone output
Passive buzzer -ESP32 GNDReturn
Mute buttonESP32 GPIO26 and GNDSilences the reminder for an hour

Code

Many terrarium plants, such as ferns and mosses, like humid air, but not air that is wet all the time, which lets mould grow. The SHT31 is an accurate temperature and humidity sensor on the I2C bus. The program reads it every two seconds and shows the humidity and temperature, with a message. When the humidity falls below 60 percent it beeps twice to remind you to mist the plants, repeating every ten minutes until you do. If the humidity stays above 95 percent for four hours it beeps three times to remind you to open the lid for a while. A button silences the reminders for an hour. The limits are only starting points, since different plants want different humidity, so change the numbers to suit yours. Keep the sensor inside the terrarium on a short lead out through a gap, and keep the ESP32, the display and the wiring outside, away from water and mist. The sensor can be damaged by direct spray or by condensation on its opening. A glass lid can be heavy, so open it with care.

Runs on a virtual ESP32 Dev Module 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 <Wire.h>
#include <Adafruit_SHT31.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SHT31 sht;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);

const int BUZZER = 25, MUTE = 26;
const float DRY_BELOW = 60.0;                      // percent: time to mist
const float WET_ABOVE = 95.0;                      // percent: air is saturated
const unsigned long WET_LIMIT_MS = 4UL * 3600UL * 1000UL;   // wet for four hours: open the lid
const unsigned long REMIND_EVERY_MS = 10UL * 60UL * 1000UL;
const unsigned long MUTE_MS = 60UL * 60UL * 1000UL;

unsigned long wetSince = 0;
unsigned long lastRemind = 0;
unsigned long mutedUntil = 0;
bool wasWet = false;

void beep(int times) {
  for (int i = 0; i < times; i++) {
#if ESP_ARDUINO_VERSION_MAJOR >= 3
    ledcAttach(BUZZER, 2000, 8);
    ledcWriteTone(BUZZER, 2000);
    delay(150);
    ledcWriteTone(BUZZER, 0);
#else
    ledcSetup(0, 2000, 8);
    ledcAttachPin(BUZZER, 0);
    ledcWriteTone(0, 2000);
    delay(150);
    ledcWriteTone(0, 0);
#endif
    delay(150);
  }
}

void setup() {
  pinMode(MUTE, INPUT_PULLUP);
  Wire.begin(21, 22);
  if (!sht.begin(0x44)) { while (true) {} }
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { while (true) {} }
}

void loop() {
  float t = sht.readTemperature();
  float h = sht.readHumidity();
  unsigned long now = millis();

  if (digitalRead(MUTE) == LOW) {
    mutedUntil = now + MUTE_MS;
    delay(300);
  }

  const char* msg = "Humidity good";
  bool dry = h < DRY_BELOW;
  bool wet = h > WET_ABOVE;

  if (wet) {
    if (!wasWet) wetSince = now;
    wasWet = true;
  } else {
    wasWet = false;
  }
  bool tooWet = wet && (now - wetSince > WET_LIMIT_MS);

  if (dry) msg = "Too dry: mist me";
  if (tooWet) msg = "Too wet: open lid";

  if ((dry || tooWet) && now > mutedUntil && now - lastRemind > REMIND_EVERY_MS) {
    lastRemind = now;
    beep(dry ? 2 : 3);
  }

  oled.clearDisplay();
  oled.setTextColor(SSD1306_WHITE);
  oled.setTextSize(2);
  oled.setCursor(0, 0);
  oled.print(h, 0); oled.print(" %RH");
  oled.setCursor(0, 22);
  oled.print(t, 1); oled.print(" C");
  oled.setTextSize(1);
  oled.setCursor(0, 48);
  oled.print(msg);
  if (now < mutedUntil) { oled.setCursor(0, 56); oled.print("Muted"); }
  oled.display();
  delay(2000);
}

Test checklist

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

CheckExpected
StartHumidity, temperature and a message
Breathe on the sensorHumidity rises quickly
Set DRY_BELOW above room humidityTwo beeps and Too dry
Press the buttonShows Muted and the beeps stop
Restore the limitsHumidity good

If it does not work

Stops at sensor begin

Check the address 0x44 or 0x45 and the I2C wires.

Humidity reads 100

Condensation on the sensor, dry it and move it up.

No beep

Check the buzzer is passive and on GPIO25.

Display blank

Check the OLED address 0x3C.

Beeps too often

Use the mute button or lengthen the reminder time.

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

Ask Lark AI

Common questions

What parts do I need for the terrarium mist reminder?

ESP32 DevKit V1, SHT31 temperature and humidity sensor, SSD1306 OLED Display, Passive buzzer, Tactile push button 6 mm and Breadboard 830 Tie Points.

How long does the terrarium mist reminder take to build?

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

How do I know the terrarium mist reminder works?

Start: Humidity, temperature and a message. Breathe on the sensor: Humidity rises quickly. Set DRY_BELOW above room humidity: Two beeps and Too dry.

Stops at sensor begin: what should I check?

Check the address 0x44 or 0x45 and the I2C wires.

Humidity reads 100: what should I check?

Condensation on the sensor, dry it and move it up.

No beep: what should I check?

Check the buzzer is passive and on GPIO25.

Display blank: what should I check?

Check the OLED address 0x3C.