Terrarium
A terrarium is a tightly closed, clear glass or plastic container filled with small plants. It also has come to mean an open, transparent container for growing and displaying plants. Terrariums are most useful for small plants that do not adapt well to normal home atmospheres. When properly planted and located, they provide a novel way to grow many plants with minimal care.
My plan was to build a sensor based system that could monitor temperature, humidity, and luminosity of my terrarium, from a simple web page. This would allow me to monitor the terrarium’s health so I always knew that it was in the best condition.
My terrarium

- Type
- Enclosure: Open, 30cm diameter spherical glass bowl
- Climate: Tropical
- Substrate
- Draining layer: Lava rock
- Filter layer: Charcoal
- Soil layer: Red and black lava rock, sand, pumice mix
- Decorations: River rocks
- Plants
- Hedera helix
- Hedera helix “Brokamp”
- Peperomia caperata “Rosso”
- Euonymus fortunei “Emerald Gaety”
- Euonymus fortunei “Emerald’n Gold”
- Pilea depressa “Baby Tears”
- Climate
- Temperature: > 25 °C
- Humidity: > 50 %RH
- Light: 14 hours daily
Live data
Data is updated randomly throughout the day.
Humidity0 %rH
Luminosity0 lux
Fanoff
AUX2off
AUX3off
Photos
![]() | ![]() | ![]() |
How to build a terrarium
Enclosure
Any glass bowl would do, as long as it can rest on your table. You can build a closed terrarium but it’s a bit more complex to get right the first time. An aquarium (without the water, obviously) would be a good option too.
Substrate
You will need at least a 3-layer substrate for a healthy environment inside your terrarium.
- River pebbles at the bottom of the bowl to make up for a drainage and leaving a place for water to collect. Depending on the plants inside, they will “smell” the water there and push their roots into this layer. If you want to be 100% on the safe side, you can place a small plastic tube into this layer so you can remove the water later (this way there won’t be any nasty odors if your charcoal layer fails). There should always be water standing in your drainage layer (if you remove it for esthetic reasons once per month, make sure you water your terrarium abundantly so the drainage layer is re-filled). For a 30cm terrarium (height), the drainage layer should be about 5-6cm.
- Charcoal layer to act as a water (and odor) filter next. This layer doesn’t have to be too high, 3-4cm of charcoal is more than enough.
- Next is the actual soil. I advise against using organic soil and instead go for a mix of pumice, sand and lava rock (ground to the coarseness level you want). I went for a mix of pumice, red and black lava rock for a nicer look. This layer is where your plant’s roots will form so make sure you have enough (7-8cm in a small slope from the back of the terrarium, for esthetic reasons).
You can add a small top layer of sand if you want to give the impression of a sandy beach or if you go for the jungle look skip the sand (or mix the sand in the soil layer).
Some big rocks won’t hurt, make sure you boil them so you don’t get any nasties (read flies and worms) in your terrarium.
Plants
There are three types of terrariums that you should consider building:
- Carnivorous plants bog: high humidity, only use distilled water, never fertilize and never use organic soil. You will also need a light that’s more powerful than normal. The plants you want in your terrarium in this case are Dionea Muscipula (Venus flytrap), Drosera variants (Aliciae), temperate Pinguicula (Tina).
- Desert: ultra low humidity, never fertilize, high temperature, soil layer should be mostly sand with some pumice. If you can replicate the “high temperature at day” - “low temperature at night” cycle you’re gold. The plants you can use are succulents and cacti. Make sure you add some bones (not human) for that “Oshit!!!” effect on your visitors.
- Temperate/tropical: high humidity, strong light, normal but inorganic soil layer, proper airflow. Any plants that is small enough to fit in your terrarium is good but you might want plants with smaller leaves, plants that crawl on the forest floor (vines and the likes). Peperomia sp. does wonders, Asplenium sandersonii, Argostemma sp. Thailand, Begonia sp., Fittonia sp, etc.
You have to decide on one of the types and you can’t mix the plants unless you really know what you are doing.
Insects
A bio-active terrarium is one that uses micro-fauna (i.e. tiny animals) and micro-flora (i.e. microbial organisms) to regulate the environment. Just as nature has its ways to recycle decaying plants and organic matter, a bio-active setup hopes to achieve the same, albeit on a much smaller scale.
If you want, you can add isopods and springtails to your terrarium, they will eat the mold and maintain the overall health of your terrarium. I chose not to.
Isopods are the great recyclers of a bio-active setup, any decaying organic material (commonly known as “detritus”) is fair game for these hardcore munching machines. They’ll make sure that any departed plant matter or mosses are taken care of before any rot sets in.
The burrowing nature of isopods also helps to aerate any substrate that they end up tunneling through. So as you might imagine, having a healthy colony of isopods in a terrarium can really keep that soil soft and tilled.
Lights
While you can’t replicate the Sun inside your terrarium for obvious reasons, that shouldn’t stop you from providing the best lighting conditions to your plants. Depending on where your terrarium is standing, you can either opt for growing lights, normal lights or red-blue LED lights. If your terrarium is on your desk, some normal Ikea lights would do good (maybe even an Ikea lamp over the desk). The light should be provided to your plants on a fixed day/night cycle else they will complain (and die): 8 hours of light per day should be minimal, I’d say go for 14 hours but not more.
Maintenance
- Always water with distilled water to avoid calciferous deposits on the inside of the terrarium glass.
- If you need to fertilize (look at the plants if they are healthy) use Osmocote pellets. Don’t over-fertilize.
- You will need to find a balance between light, humidity, temperature and airflow. Too little light and the plants will grow leggy or look sick. Too little humidity and the plants will die. Too much humidity and you will get mold.
- Keep a fan running to maintain a proper airflow in the terrarium, else the mold will destroy it.
- If you get fungus gnats inside, it means your terrarium humidity is too high: use yellow sticky cards to catch and kill them but you will need to keep a card inside for about a month.
- If you want to maintain your inorganic soil (actually not yours, your terrarium’s), remove any fallen leaves from the top of the soil.
Electronics
Time to make your terrarium stand out from others, to make it “smart”. To do this, we need to know what we want to measure and why. I am no expert in terrarium, so this is a first for me, but I understand sensors and micro-controllers very well, so applying my knowledge in one will hopefully bridge the gap to the other.
- Arduino Mega 2560 - micro-controller
- Breadboard & wires
- Adafruit SHTC3 - temperature & humidity sensor
- SparkFun TSL2561 - luminosity sensor
This is the Arduino sketch that’s loaded onto my Arduino Mega micro-controller. It’s as basic as it can get, but if you plan to use it, some tweaks might be required:
- Change
MAX_HUMIDITY
to a value when you want the fan to start. The fan is connected to the pin 3 of the micro-controller (I’m using a 3.3V fan so I don’t need a relay and separate power), the water-mister is connected to the pin 4 and pin 5 is reserved for a future device. - The data is written as JSON to the serial port of the micro-controller, every 10 seconds. If you want to change that interval, modify the
timeout
value.
#include <SparkFunTSL2561.h>
#include <Adafruit_SHTC3.h>
#include <Wire.h>
#include <ArduinoJson.h>
#define FAN_PIN 3
#define AUX2_PIN 4
#define AUX3_PIN 5
#define MAX_HUMIDITY 65
SFE_TSL2561 sensor1;
Adafruit_SHTC3 sensor2 = Adafruit_SHTC3();
boolean gain;
boolean fan;
boolean rain;
unsigned int ms;
unsigned long next_update;
unsigned char time = 2;
unsigned long timeout = 10000UL;
StaticJsonDocument<200> json_document;
void setup () {
Serial.begin(115200);
next_update = millis() + timeout;
fan = false;
rain = false;
analogReference(EXTERNAL);
pinMode(FAN_PIN, OUTPUT);
pinMode(AUX2_PIN, OUTPUT);
pinMode(AUX3_PIN, OUTPUT);
sensor1.begin();
sensor2.begin();
gain = 0;
sensor1.setTiming(gain, time, ms);
sensor1.setPowerUp();
}
void loop () {
if (millis() >= next_update) {
delay(ms);
unsigned int data0, data1;
if (sensor1.getData(data0, data1)) {
double lux;
boolean good;
good = sensor1.getLux(gain, ms, data0, data1, lux);
json_document["light"] = lux;
} else {
byte error = sensor1.getError();
printError(error);
return "";
}
sensors_event_t humidity, temp;
if (sensor2.getEvent(&humidity, &temp)) {
json_document["temperature"] = temp.temperature;
json_document["humidity"] = humidity.relative_humidity;
if (humidity.relative_humidity > MAX_HUMIDITY) {
fan = true;
digitalWrite(FAN_PIN, HIGH);
rain = false;
digitalWrite(AUX2_PIN, LOW);
} else {
fan = false;
digitalWrite(FAN_PIN, LOW);
rain = true;
digitalWrite(AUX2_PIN, HIGH);
}
}
json_document["fan"] = fan;
json_document["aux2"] = rain;
json_document["aux3"] = false;
serializeJson(json_document, Serial);
Serial.println();
next_update = millis() + timeout;
}
}
void printError (byte error) {
Serial.print("I2C error: ");
Serial.print(error, DEC);
Serial.print(", ");
switch (error) {
case 0:
Serial.println("success");
break;
case 1:
Serial.println("data too long for transmit buffer");
break;
case 2:
Serial.println("received NACK on address (disconnected?)");
break;
case 3:
Serial.println("received NACK on data");
break;
case 4:
Serial.println("other error");
break;
default:
Serial.println("unknown error");
}
}
Depending on the operating system installed on the machine that’s retrieving data from the Arduino Mega micro-controller, you can get the JSON like this:
$ head -1 /dev/ttyACM0 > ~/terrarium.json
author
created September 1, 2022
updated July 5, 2023
words 1634
tags #projects, #terrarium, #arduino, #sensors