Build it step by step
0 of 7 doneWire the I2C devices
AHT20 and OLED on A4 and A5.
Wire the probe
Red to 5V, black to GND, yellow to D2 with 4.7 kilohm to 5V.
Wire the LED
D6 through 220 ohms to GND.
Upload the sketch
The screen shows the readings.
Compare with a separate thermometer
They should agree within a degree or two.
Set the limits
From your animal's care guide.
Warm the probe by hand
The reading rises, and the LED flashes past the limit.
How do you build a terrarium warm spot watch?
A temperature probe on the warm spot and a humidity sensor at the cool end show a small terrarium's conditions on a screen and flash a warning when they leave the range you set. It only watches. A separate thermometer and the heater controls stay as they are, and it is not a life-support device. You need Arduino Nano, AHT20 temperature and humidity sensor, DS18B20 waterproof probe, Resistor 4.7 kΩ, SSD1306 OLED Display, LED 5 mm red, Resistor 220 Ω, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 80 minutes.
- Level
- Intermediate
- Time
- About 80 min
- Parts
- 9
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- SensorsBuy
- PassivesBuyResistor 4.7 kΩ × 1
- DisplaysBuy
- SemiconductorsBuyLED 5 mm red × 1
- PassivesBuyResistor 220 Ω × 1
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| AHT20 SDA and SCL | Nano A4 and A5 | I2C data and clock |
| AHT20 and OLED VCC and GND | Nano 5V and GND | Power |
| OLED SDA and SCL | Nano A4 and A5 | Shares the same I2C wires |
| DS18B20 red and black | Nano 5V and GND | Probe power |
| DS18B20 yellow data | Nano D2 and a 4.7 kilohm resistor to 5V | One-wire data with its pull-up |
| Warning LED long leg | Nano D6 through a 220 ohm resistor, short leg to GND | Flashes outside the limits |
Code
The waterproof probe lies on the warm spot to read the temperature there, and the AHT20 at the cool end reads the air temperature and humidity. The sketch shows the readings and the day's lowest and highest warm-spot temperature, and flashes the LED and shows CHECK THE TERRARIUM when any reading leaves the limits, or when the probe returns no reading at all. The limits are placeholders; set them from your animal's own care guide. This unit only watches. It does not control a heater, mister or lamp, and it is not a life-support device, so keep a separate thermometer and check the animals yourself every day. A probe error often means a loose data wire or a missing 4.7 kilohm pull-up resistor. Keep the sensors away from the heat source's direct touch and from water, and keep the electronics and wiring out of the animal's reach. Install "Adafruit AHTX0", "OneWire", "DallasTemperature", "Adafruit SSD1306" and "Adafruit GFX" from the Library Manager. Add serial log lines to a spreadsheet to see the day's pattern.
Runs on a virtual Arduino Nano 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).
// Libraries: Adafruit AHTX0, OneWire, DallasTemperature, Adafruit SSD1306 and Adafruit GFX.
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_AHTX0.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
OneWire bus(2);
DallasTemperature probe(&bus);
Adafruit_AHTX0 aht;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const uint8_t LED = 6;
// Placeholder limits: set them from your animal's care guide.
const float WARM_MIN = 24.0; // degrees C at the warm spot
const float WARM_MAX = 35.0;
const float HUM_MIN = 40.0; // percent at the cool end
const float HUM_MAX = 80.0;
float warmLow = 100, warmHigh = -100;
unsigned long lastRead = 0;
bool alarm = false;
void setup() {
pinMode(LED, OUTPUT);
Serial.begin(9600);
probe.begin();
if (!aht.begin()) Serial.println(F("AHT20 not found"));
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
}
void loop() {
unsigned long now = millis();
if (now - lastRead >= 2000) {
lastRead = now;
probe.requestTemperatures();
float warm = probe.getTempCByIndex(0);
sensors_event_t hum, temp;
aht.getEvent(&hum, &temp);
float rh = hum.relative_humidity;
bool probeOk = (warm > -100); // -127 means no reading
if (probeOk) {
if (warm < warmLow) warmLow = warm;
if (warm > warmHigh) warmHigh = warm;
}
alarm = !probeOk || warm < WARM_MIN || warm > WARM_MAX || rh < HUM_MIN || rh > HUM_MAX;
oled.clearDisplay();
oled.setTextColor(SSD1306_WHITE);
oled.setTextSize(1);
oled.setCursor(0, 0);
oled.print(F("Warm spot: "));
if (probeOk) { oled.print(warm, 1); oled.print(F(" C")); } else oled.print(F("probe error"));
oled.setCursor(0, 14);
oled.print(F("Cool end: ")); oled.print(temp.temperature, 1); oled.print(F(" C"));
oled.setCursor(0, 28);
oled.print(F("Humidity: ")); oled.print(rh, 0); oled.print(F(" %"));
oled.setCursor(0, 42);
oled.print(F("Today ")); oled.print(warmLow, 0); oled.print(F("-")); oled.print(warmHigh, 0); oled.print(F(" C"));
oled.setCursor(0, 54);
oled.print(alarm ? F("CHECK THE TERRARIUM") : F("In range"));
oled.display();
Serial.print(warm); Serial.print(','); Serial.print(temp.temperature); Serial.print(','); Serial.println(rh);
}
digitalWrite(LED, alarm ? ((now / 400) % 2) : LOW); // flash while outside the limits
}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 Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
AHT20 not found 24.50,0.00,0.00
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Probe in air | Reads room temperature |
| Warm the probe | The reading rises |
| Over the limit | LED flashes and message appears |
| Unplug the probe | Probe error and the LED flashes |
| Serial monitor | Prints warm, cool and humidity |
If it does not work
Probe error message
Check the 4.7 kilohm pull-up and the data wire on D2.
AHT20 not found
Check SDA, SCL and power.
Readings disagree
Check each against a separate thermometer.
Blank screen
Check the OLED wires and try address 0x3D.
LED never flashes
Lower WARM_MAX to test it.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the terrarium warm spot watch?
Arduino Nano, AHT20 temperature and humidity sensor, DS18B20 waterproof probe, Resistor 4.7 kΩ, SSD1306 OLED Display, LED 5 mm red, Resistor 220 Ω, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the terrarium warm spot watch take to build?
About 80 minutes for a intermediate maker, in 7 steps.
How do I know the terrarium warm spot watch works?
Probe in air: Reads room temperature. Warm the probe: The reading rises. Over the limit: LED flashes and message appears.
Probe error message: what should I check?
Check the 4.7 kilohm pull-up and the data wire on D2.
AHT20 not found: what should I check?
Check SDA, SCL and power.
Readings disagree: what should I check?
Check each against a separate thermometer.
Blank screen: what should I check?
Check the OLED wires and try address 0x3D.
