Project · Beginner · ESP32
Filament Dry Box Monitor with ESP32
Humidity logging, alerts, and desiccant change reminders.
In this guide
- Goal & materials
- Steps / firmware
- Troubleshooting
- AI assist notes
- Related gear & books
Filament absorbs moisture from the air, and wet filament prints with stringing, bubbles, rough surfaces, and weak layers. A sealed dry box with desiccant helps, but only if the desiccant is still working. An ESP32 with a humidity sensor tells you what is happening inside the box, logs it, and reminds you when the desiccant needs recharging.
Parts
- An ESP32 development board.
- A digital temperature and humidity sensor. Good choices are the Sensirion SHT3x or SHT4x families or a Bosch BME280. Note that the similar-looking BMP280 does not measure humidity.
- A sealed container with a gasketed lid.
- Indicating silica gel or another desiccant.
- Four-wire cable and a way to seal the cable entry, such as a small cable gland or sealant.
DHT22 sensors work but are slower and generally less accurate than the I2C sensors above. Check the datasheet for the accuracy of the exact sensor you buy.
Layout: keep the electronics out of the box
Put only the sensor inside the dry box. The ESP32 warms up when Wi-Fi is active, and heat near the sensor lowers the relative humidity reading, making the box look drier than it is. Mount the ESP32 outside and run the I2C cable through a sealed entry. Keep the cable reasonably short; I2C is designed for short distances.
Wiring
- Sensor VCC to 3.3 V, GND to GND.
- SDA to GPIO 21 and SCL to GPIO 22 on most classic ESP32 DevKits (other boards and chips use different defaults).
- Most breakout boards include pull-up resistors. If yours does not, add them on SDA and SCL to 3.3 V.
Firmware
This example uses the Adafruit SHT31 library and prints readings every minute. Adjust for your sensor's library.
#include <Wire.h>
#include <Adafruit_SHT31.h>
Adafruit_SHT31 sht31;
const float ALERT_RH = 30.0; // set for your filament
const float CLEAR_RH = 25.0; // hysteresis so alerts do not flap
bool alerting = false;
void setup() {
Serial.begin(115200);
Wire.begin(21, 22);
if (!sht31.begin(0x44)) {
Serial.println("SHT31 not found, check wiring and address");
while (true) delay(1000);
}
}
void loop() {
float t = sht31.readTemperature();
float rh = sht31.readHumidity();
if (!isnan(t) && !isnan(rh)) {
Serial.printf("temp_c=%.1f rh=%.1f\n", t, rh);
if (!alerting && rh >= ALERT_RH) { alerting = true; Serial.println("ALERT: humidity high"); }
if (alerting && rh <= CLEAR_RH) { alerting = false; Serial.println("Humidity back to normal"); }
}
delay(60000);
}
From here, publish the readings to MQTT for Home Assistant, push a notification when an alert starts, or write a CSV line to an SD card.
Choosing thresholds
There is no single correct number. Moisture-sensitive materials such as nylon, TPU, and PVA generally need much drier storage than PLA. Use the filament manufacturer's storage or drying recommendations where available, and treat your alert threshold as a setting you tune. What matters most is the trend: a box that held steady and is now climbing needs attention.
Desiccant reminders that mean something
Calendar reminders ignore how often you open the box. Base the reminder on the readings instead:
- Baseline: after recharging desiccant and closing the box, note the stable humidity it reaches.
- Drift: when the stable reading rises a set amount above that baseline, the desiccant is saturating.
- Recovery time: after you open and close the lid, fresh desiccant pulls humidity back down quickly. If recovery gets slow, it is time to recharge.
Recharge silica gel following the manufacturer's temperature and time instructions. Indicating beads change color as they saturate, which is a useful cross-check on the sensor.
Checking sensor accuracy
A simple, well-established check is the saturated salt test. A sealed container with a damp slurry of table salt (sodium chloride) settles near 75% relative humidity at room temperature. Put the sensor in with it for several hours and compare. If your reading is off by a few percent, apply an offset in software.
Power options
- USB power is simplest and lets you keep Wi-Fi connected.
- Battery works well with deep sleep: wake every few minutes, read, send, and sleep again. Readings change slowly, so short intervals are not needed.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Sensor not found | Wrong address, swapped SDA/SCL, no pull-ups | Run an I2C scanner; check wiring |
| Humidity reads low and temperature high | Sensor near the ESP32 or another heat source | Move the sensor away from electronics |
| Humidity never drops | Leaky lid or cable entry, saturated desiccant | Check the gasket and seal; recharge desiccant |
| Humidity stuck at 0 or 100 | Wrong sensor type selected in code, or failed sensor | Confirm the library matches the part |
Summary
Keep the sensor in the box and the ESP32 outside it, seal the cable entry, set an alert threshold with hysteresis for your materials, and base desiccant reminders on the humidity trend rather than the calendar. A quick salt test confirms your sensor is telling the truth.
Related
- Projects hub
- Newsletter
- Books for deeper reading