Home
Smiling planter
A plant pot that tells you how it feels: a happy face when the soil is moist, a thirsty face when it is dry.
- Medium
- about 50 min
- ESP32-S3
- 6 parts
- 10 wires
- 60 lines of code
ESP32 packs are built on real parts: the simulator runs Arduino Uno circuits only.
Idea
The sensor gives a raw number, not a percentage. You calibrate it yourself with a glass of water, which is what every real measuring instrument needs.
Before you start
Keep the board and the top of the sensor dry. Only the part of the sensor below the line goes into the soil.
What you learn
Reading an analog sensor, calibrating it, and mapping a reading onto 0 to 100.
How it works
input
Soil sensor
decides
ESP32-S3
output
TFT 1.54 in
Powered with 5 V through the board's USB-C port.
A reference design. The sketch is compiled with the real ESP32 toolchain, and its pins are checked against the wiring table automatically. It has not yet been built and tested on real parts by us, so wire it on the bench and run the checks before you build it into a case. Real modules vary: follow the labels printed on yours, not their position in the picture.
Parts
0 of 6 ready
No prices here: they change by shop and by week. Buy each part by its name and the note beside it.
You also need
A computer with Arduino IDE 2 installed (free)
3D wiring
One jumper per step, with the USB cable unplugged. Several wires may share 3V3, 5V or GND: the expansion board or breadboard gives each its own pin.
Step 0 of 10
Lay out the parts
Seat the board on its expansion board or breadboard and lay the modules out round it. Nothing is connected yet.
All connections
smiling-planter.ino
// Smiling planter
// A happy face when the soil is wet enough, a thirsty face when it is dry.
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
const int PIN_SOIL_AOUT = 1;
const int PIN_TFT_SCL = 12;
const int PIN_TFT_SDA = 11;
const int PIN_TFT_RES = 14;
const int PIN_TFT_DC = 13;
const int PIN_TFT_CS = 10;
// Calibrate these two: read the sensor in air, then in a glass of water.
const int READING_DRY = 2900;
const int READING_WET = 1300;
const int THIRSTY_BELOW_PERCENT = 35;
Adafruit_ST7789 tft(PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RES);
int shownPercent = -1;
void drawFace(int percent) {
bool thirsty = percent < THIRSTY_BELOW_PERCENT;
uint16_t skin = thirsty ? 0xD5A0 : 0x5E0A; // dry yellow, leaf green
tft.fillScreen(ST77XX_BLACK);
tft.fillCircle(120, 105, 85, skin);
tft.fillCircle(88, 85, 12, ST77XX_BLACK);
tft.fillCircle(152, 85, 12, ST77XX_BLACK);
if (thirsty) {
// a sad mouth: a dark disc with its lower part covered
tft.fillCircle(120, 160, 30, ST77XX_BLACK);
tft.fillRect(85, 150, 70, 45, skin);
} else {
tft.fillCircle(120, 120, 34, ST77XX_BLACK);
tft.fillRect(85, 84, 70, 38, skin);
}
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(3);
tft.setCursor(80, 205);
tft.printf("%3d%%", percent);
}
void setup() {
analogReadResolution(12);
SPI.begin(PIN_TFT_SCL, -1, PIN_TFT_SDA, PIN_TFT_CS);
tft.init(240, 240);
tft.setRotation(2);
}
void loop() {
long total = 0;
for (int i = 0; i < 16; i++) total += analogRead(PIN_SOIL_AOUT);
int reading = total / 16;
int percent = constrain(map(reading, READING_DRY, READING_WET, 0, 100), 0, 100);
if (abs(percent - shownPercent) >= 2) {
shownPercent = percent;
drawFace(percent);
}
delay(2000);
}
Libraries
- Adafruit GFX Library: install it from Sketch > Include Library > Manage Libraries.
- Adafruit ST7735 and ST7789 Library: install it from Sketch > Include Library > Manage Libraries.
Uploading
First time with an ESP32: in Arduino IDE open Boards Manager, search “esp32” and install “esp32 by Espressif Systems”.
- Open the sketch in Arduino IDE.
- Plug the board in with the USB-C cable.
- Tools > Board > ESP32S3 Dev Module, then Tools > Port and choose the board's port.
- Press Upload (the arrow). Wait for “Done uploading”.