Colaboração
ARTE
BELEZA E BEM-ESTAR
ARTESANATO
CULTURA E HISTÓRIA
ENTRETENIMENTO
MEIO AMBIENTE
COMIDA E BEBIDAS
ENGENHARIA REVERSA
CIÊNCIAS
ESPORTES
TECNOLOGIA
TECNOLOGIA VESTÍVEL
ESP32 Self-Watering Pot Controller
Ed

Criado por

Ed

16. novembro 2026FI
0
0
0
0
0

ESP32 Self-Watering Pot Controller

A tank unit that sits next to one houseplant pot. An ESP32 reads a capacitive soil-moisture sensor in the pot and an ultrasonic sensor looking down into a 1.7 L printed water tank. It shows soil moisture % and tank level % on a 0.96 in OLED and runs a small 5 V submersible pump through a logic-level MOSFET when the soil is dry and the tank is not empty. Powered from USB-C 5 V.

Instruções

1

Circuit board

Carregando visualizador KiCanvas...

Visualizador profissional de design PCB

2

Schematic

Carregando visualizador KiCanvas...

Visualizador profissional de design PCB

3

Print the enclosure base

Arquivo de designSTL71.6 KBCC0 - Free
4

Print the enclosure lid

Arquivo de designSTL79.1 KBCC0 - Free
5

Print the button plunger

Arquivo de designSTL16.3 KBCC0 - Free
6

Print the water tank

Arquivo de designSTL1.4 KBCC0 - Free
7

Print the tank lid with enclosure seat

Arquivo de designSTL46.5 KBCC0 - Free
8

Print the tube stake for the pot

Arquivo de designSTL32.2 KBCC0 - Free
9

Firmware

firmware.inoarduino
// Self-watering pot controller - ESP32 DevKit (38-pin) carrier board
// Soil: capacitive v1.2 on GPIO34 (ADC1). Tank: HC-SR04 TRIG=GPIO5, ECHO=GPIO18 (via 1k/2k divider).
// OLED SSD1306 128x64 I2C @0x3C on SDA=21 SCL=22. Pump MOSFET gate GPIO25. Button GPIO27 to GND.
// Button: short press = force a watering cycle, hold 3 s = calibrate soil sensor (dry / wet).
#include <Arduino.h>
#include <Wire.h>
#include <Preferences.h>

// ---------------- pins ----------------
const int PIN_SOIL = 34;
const int PIN_TRIG = 5;
const int PIN_ECHO = 18;
const int PIN_PUMP = 25;
const int PIN_BTN  = 27;
const int PIN_SDA  = 21;
const int PIN_SCL  = 22;

// ---------------- settings (adjust for your pot / tank) ----------------
const float TANK_EMPTY_CM   = 20.0;  // sensor-to-water distance when tank is empty
const float TANK_FULL_CM    = 4.0;   // sensor-to-water distance when tank is full
const int   SOIL_DRY_PCT    = 35;    // start watering below this moisture %
const int   TANK_MIN_PCT    = 10;    // never pump below this tank level %
const uint32_t PUMP_RUN_MS  = 5000;  // one watering shot
const uint32_t SOAK_MS      = 10UL * 60UL * 1000UL; // wait for water to soak in before next automatic shot
const uint32_t MEASURE_MS   = 1000;

Preferences prefs;
int calDry = 3000;   // raw ADC in air (dry)
int calWet = 1300;   // raw ADC in water (wet)

// ---------------- minimal SSD1306 driver ----------------
const uint8_t OLED_ADDR = 0x3C;
uint8_t fb[1024];
bool oledOk = false;

static const uint8_t FONT[] PROGMEM = {
0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x5F,0x00,0x00, 0x00,0x07,0x00,0x07,0x00, 0x14,0x7F,0x14,0x7F,0x14,
0x24,0x2A,0x7F,0x2A,0x12, 0x23,0x13,0x08,0x64,0x62, 0x36,0x49,0x56,0x20,0x50, 0x00,0x08,0x07,0x03,0x00,
0x00,0x1C,0x22,0x41,0x00, 0x00,0x41,0x22,0x1C,0x00, 0x2A,0x1C,0x7F,0x1C,0x2A, 0x08,0x08,0x3E,0x08,0x08,
0x00,0x80,0x70,0x30,0x00, 0x08,0x08,0x08,0x08,0x08, 0x00,0x00,0x60,0x60,0x00, 0x20,0x10,0x08,0x04,0x02,
0x3E,0x51,0x49,0x45,0x3E, 0x00,0x42,0x7F,0x40,0x00, 0x72,0x49,0x49,0x49,0x46, 0x21,0x41,0x49,0x4D,0x33,
0x18,0x14,0x12,0x7F,0x10, 0x27,0x45,0x45,0x45,0x39, 0x3C,0x4A,0x49,0x49,0x31, 0x41,0x21,0x11,0x09,0x07,
0x36,0x49,0x49,0x49,0x36, 0x46,0x49,0x49,0x29,0x1E, 0x00,0x00,0x14,0x00,0x00, 0x00,0x40,0x34,0x00,0x00,
0x00,0x08,0x14,0x22,0x41, 0x14,0x14,0x14,0x14,0x14, 0x00,0x41,0x22,0x14,0x08, 0x02,0x01,0x59,0x09,0x06,
0x3E,0x41,0x5D,0x59,0x4E, 0x7C,0x12,0x11,0x12,0x7C, 0x7F,0x49,0x49,0x49,0x36, 0x3E,0x41,0x41,0x41,0x22,
0x7F,0x41,0x41,0x41,0x3E, 0x7F,0x49,0x49,0x49,0x41, 0x7F,0x09,0x09,0x09,0x01, 0x3E,0x41,0x41,0x51,0x73,
0x7F,0x08,0x08,0x08,0x7F, 0x00,0x41,0x7F,0x41,0x00, 0x20,0x40,0x41,0x3F,0x01, 0x7F,0x08,0x14,0x22,0x41,
0x7F,0x40,0x40,0x40,0x40, 0x7F,0x02,0x1C,0x02,0x7F, 0x7F,0x04,0x08,0x10,0x7F, 0x3E,0x41,0x41,0x41,0x3E,
0x7F,0x09,0x09,0x09,0x06, 0x3E,0x41,0x51,0x21,0x5E, 0x7F,0x09,0x19,0x29,0x46, 0x26,0x49,0x49,0x49,0x32,
0x03,0x01,0x7F,0x01,0x03, 0x3F,0x40,0x40,0x40,0x3F, 0x1F,0x20,0x40,0x20,0x1F, 0x3F,0x40,0x38,0x40,0x3F,
0x63,0x14,0x08,0x14,0x63, 0x03,0x04,0x78,0x04,0x03, 0x61,0x59,0x49,0x4D,0x43, 0x00,0x7F,0x41,0x41,0x41,
0x02,0x04,0x08,0x10,0x20, 0x00,0x41,0x41,0x41,0x7F, 0x04,0x02,0x01,0x02,0x04, 0x40,0x40,0x40,0x40,0x40,
0x00,0x03,0x07,0x08,0x00, 0x20,0x54,0x54,0x78,0x40, 0x7F,0x28,0x44,0x44,0x38, 0x38,0x44,0x44,0x44,0x28,
0x38,0x44,0x44,0x28,0x7F, 0x38,0x54,0x54,0x54,0x18, 0x00,0x08,0x7E,0x09,0x02, 0x18,0xA4,0xA4,0x9C,0x78,
0x7F,0x08,0x04,0x04,0x78, 0x00,0x44,0x7D,0x40,0x00, 0x20,0x40,0x40,0x3D,0x00, 0x7F,0x10,0x28,0x44,0x00,
0x00,0x41,0x7F,0x40,0x00, 0x7C,0x04,0x78,0x04,0x78, 0x7C,0x08,0x04,0x04,0x78, 0x38,0x44,0x44,0x44,0x38,
0xFC,0x18,0x24,0x24,0x18, 0x18,0x24,0x24,0x18,0xFC, 0x7C,0x08,0x04,0x04,0x08, 0x48,0x54,0x54,0x54,0x24,
0x04,0x04,0x3F,0x44,0x24, 0x3C,0x40,0x40,0x20,0x7C, 0x1C,0x20,0x40,0x20,0x1C, 0x3C,0x40,0x30,0x40,0x3C,
0x44,0x28,0x10,0x28,0x44, 0x4C,0x90,0x90,0x90,0x7C, 0x44,0x64,0x54,0x4C,0x44, 0x00,0x08,0x36,0x41,0x00,
0x00,0x00,0x77,0x00,0x00, 0x00,0x41,0x36,0x08,0x00, 0x02,0x01,0x02,0x04,0x02
};

void oledCmd(uint8_t c) {
  Wire.beginTransmission(OLED_ADDR); Wire.write(0x00); Wire.write(c); Wire.endTransmission();
}

bool oledInit() {
  Wire.beginTransmission(OLED_ADDR);
  if (Wire.endTransmission() != 0) return false;
  const uint8_t init[] = {0xAE,0xD5,0x80,0xA8,0x3F,0xD3,0x00,0x40,0x8D,0x14,0x20,0x00,
                          0xA1,0xC8,0xDA,0x12,0x81,0xCF,0xD9,0xF1,0xDB,0x40,0xA4,0xA6,0x2E,0xAF};
  for (uint8_t c : init) oledCmd(c);
  return true;
}

void oledShow() {
  if (!oledOk) return;
  oledCmd(0x21); oledCmd(0); oledCmd(127);
  oledCmd(0x22); oledCmd(0); oledCmd(7);
  for (int i = 0; i < 1024; i += 16) {
    Wire.beginTransmission(OLED_ADDR);
    Wire.write(0x40);
    Wire.write(&fb[i], 16);
    Wire.endTransmission();
  }
}

void clearFb() { memset(fb, 0, sizeof(fb)); }

void setPixel(int x, int y) {
  if (x < 0 || x > 127 || y < 0 || y > 63) return;
  fb[x + (y / 8) * 128] |= (1 << (y & 7));
}

void drawChar(int x, int y, char c, int s) {
  if (c < 32 || c > 126) c = '?';
  for (int col = 0; col < 5; col++) {
    uint8_t bits = pgm_read_byte(&FONT[(c - 32) * 5 + col]);
    for (int row = 0; row < 8; row++)
      if (bits & (1 << row))
        for (int dx = 0; dx < s; dx++)
          for (int dy = 0; dy < s; dy++) setPixel(x + col * s + dx, y + row * s + dy);
  }
}

void drawText(int x, int y, const char *t, int s = 1) {
  while (*t) { drawChar(x, y, *t++, s); x += 6 * s; }
}

void drawBar(int x, int y, int w, int h, int pct) {
  for (int i = 0; i < w; i++) { setPixel(x + i, y); setPixel(x + i, y + h - 1); }
  for (int j = 0; j < h; j++) { setPixel(x, y + j); setPixel(x + w - 1, y + j); }
  int fill = (w - 4) * constrain(pct, 0, 100) / 100;
  for (int i = 0; i < fill; i++)
    for (int j = 2; j < h - 2; j++) setPixel(x + 2 + i, y + j);
}

// ---------------- sensors ----------------
int readSoilRaw() {
  long sum = 0;
  for (int i = 0; i < 16; i++) { sum += analogRead(PIN_SOIL); delay(2); }
  return sum / 16;
}

int soilPercent(int raw) {
  if (calDry == calWet) return 0;
  long p = (long)(calDry - raw) * 100 / (calDry - calWet);
  return constrain((int)p, 0, 100);
}

float readDistanceCm() {
  float best[5]; int n = 0;
  for (int i = 0; i < 5; i++) {
    digitalWrite(PIN_TRIG, LOW); delayMicroseconds(4);
    digitalWrite(PIN_TRIG, HIGH); delayMicroseconds(10);
    digitalWrite(PIN_TRIG, LOW);
    unsigned long us = pulseIn(PIN_ECHO, HIGH, 30000UL);
    if (us > 0) best[n++] = us / 58.0f;
    delay(30);
  }
  if (n == 0) return -1;
  for (int i = 0; i < n; i++)            // median
    for (int j = i + 1; j < n; j++)
      if (best[j] < best[i]) { float t = best[i]; best[i] = best[j]; best[j] = t; }
  return best[n / 2];
}

int tankPercent(float cm) {
  if (cm < 0) return -1;
  float p = (TANK_EMPTY_CM - cm) * 100.0f / (TANK_EMPTY_CM - TANK_FULL_CM);
  return constrain((int)p, 0, 100);
}

// ---------------- pump ----------------
bool pumpOn = false;
uint32_t pumpStart = 0, lastWater = 0;
bool everWatered = false;

void pump(bool on) {
  pumpOn = on;
  digitalWrite(PIN_PUMP, on ? HIGH : LOW);
  if (on) pumpStart = millis();
  else { lastWater = millis(); everWatered = true; }
}

// ---------------- button ----------------
// returns 0 = nothing, 1 = short press, 2 = long press (>3 s)
int readButton() {
  static bool was = false; static uint32_t t0 = 0; static bool longDone = false;
  bool down = digitalRead(PIN_BTN) == LOW;
  int ev = 0;
  if (down && !was) { t0 = millis(); longDone = false; }
  if (down && !longDone && millis() - t0 > 3000) { ev = 2; longDone = true; }
  if (!down && was && !longDone && millis() - t0 > 40) ev = 1;
  was = down;
  return ev;
}

void waitPress() {
  while (digitalRead(PIN_BTN) == LOW) delay(10);
  delay(50);
  while (digitalRead(PIN_BTN) == HIGH) delay(10);
  delay(50);
  while (digitalRead(PIN_BTN) == LOW) delay(10);
}

void calibrate() {
  pump(false);
  clearFb(); drawText(0, 0, "CALIBRATE SOIL", 1);
  drawText(0, 16, "1) Sensor in DRY air"); drawText(0, 28, "   then press button");
  oledShow(); waitPress();
  int dry = readSoilRaw();
  clearFb(); drawText(0, 0, "CALIBRATE SOIL", 1);
  drawText(0, 16, "2) Sensor in WATER"); drawText(0, 28, "   (up to the line)"); drawText(0, 40, "   then press button");
  oledShow(); waitPress();
  int wet = readSoilRaw();
  clearFb();
  if (dry - wet > 200) {
    calDry = dry; calWet = wet;
    prefs.putInt("dry", calDry); prefs.putInt("wet", calWet);
    drawText(0, 16, "Saved."); 
  } else {
    drawText(0, 16, "Bad readings,"); drawText(0, 28, "not saved.");
  }
  char b[32]; snprintf(b, sizeof(b), "dry=%d wet=%d", dry, wet); drawText(0, 44, b);
  oledShow(); delay(2500);
}

void setup() {
  pinMode(PIN_PUMP, OUTPUT); digitalWrite(PIN_PUMP, LOW);
  pinMode(PIN_TRIG, OUTPUT); digitalWrite(PIN_TRIG, LOW);
  pinMode(PIN_ECHO, INPUT);
  pinMode(PIN_BTN, INPUT_PULLUP);
  Serial.begin(115200);
  analogReadResolution(12);
  analogSetPinAttenuation(PIN_SOIL, ADC_11db);
  prefs.begin("plantpot", false);
  calDry = prefs.getInt("dry", calDry);
  calWet = prefs.getInt("wet", calWet);
  Wire.begin(PIN_SDA, PIN_SCL, 400000);
  oledOk = oledInit();
  clearFb(); drawText(10, 24, "PlantPot", 2); oledShow();
  delay(1000);
}

void loop() {
  static uint32_t lastMeas = 0;
  static int soil = 0, tank = -1, raw = 0;
  static float dist = -1;
  static bool forceRequest = false;

  int ev = readButton();
  if (ev == 2) { calibrate(); lastMeas = 0; }
  if (ev == 1) forceRequest = true;

  // pump safety timeout
  if (pumpOn && millis() - pumpStart >= PUMP_RUN_MS) pump(false);

  if (millis() - lastMeas >= MEASURE_MS || lastMeas == 0) {
    lastMeas = millis();
    raw = readSoilRaw();
    soil = soilPercent(raw);
    dist = readDistanceCm();
    tank = tankPercent(dist);
    bool tankOk = tank >= TANK_MIN_PCT;          // unknown (-1) counts as empty
    if (pumpOn && !tankOk) pump(false);

    if (!pumpOn && tankOk) {
      bool soaked = !everWatered || millis() - lastWater >= SOAK_MS;
      if (forceRequest || (soil < SOIL_DRY_PCT && soaked)) pump(true);
    }
    forceRequest = false;

    Serial.printf("soil raw=%d %d%%  dist=%.1fcm tank=%d%%  pump=%d\n", raw, soil, dist, tank, pumpOn);

    clearFb();
    char b[24];
    drawText(0, 0, "SOIL");
    snprintf(b, sizeof(b), "%3d%%", soil); drawText(70, 0, b, 2);
    drawBar(0, 18, 128, 8, soil);
    drawText(0, 32, "TANK");
    if (tank < 0) snprintf(b, sizeof(b), " ?? "); else snprintf(b, sizeof(b), "%3d%%", tank);
    drawText(70, 32, b, 2);
    drawBar(0, 48, 128, 8, tank < 0 ? 0 : tank);
    if (pumpOn) drawText(30, 0, "PUMP");
    else if (!tankOk) drawText(30, 0, "FILL!");
    oledShow();
  }
  delay(10);
}
10

Check board and parts

Check the bare PCB for shorts between +5V and GND with a multimeter. Measure the ESP32 dev board row spacing: the sockets are 25.4 mm apart.

Materiais para este passo:

Placa de circuito impressoPlaca de circuito impresso1 pcs

Ferramentas necessárias:

MultímetroMultímetro
11

Solder SMD parts

Solder R1 and R2 (5.1k, CC pull-downs), R3 (100R gate), R4 (100k gate pull-down), R5 (1k), R6 (2k) and C2 (100 nF), all 0805. Then solder the USB-C receptacle J3.

Materiais para este passo:

Resistor de chipResistor de chip6 pcs
Ceramic Capacitor1 pcs
USB-C Receptacle1 pcs
Fio de soldaFio de solda5 g

Ferramentas necessárias:

Ferro de soldarFerro de soldar
12

Solder through-hole parts

Solder D1 (1N5819, band to +5V), Q1 (IRLZ44N), C1 (470 uF 10 V, mind polarity), J4 pump terminal, J5 and J6 JST-XH headers, J7 OLED header, SW1 and the two 1x19 female sockets.

Materiais para este passo:

DíodoDíodo1 pcs
MOSFET de nível lógico IRLZ44NMOSFET de nível lógico IRLZ44N1 pcs
Condensador eletrolíticoCondensador eletrolítico1 pcs
Bloco de terminais de parafusoBloco de terminais de parafuso1 pcs
JST-XH Board Header2 pcs
Barra de pinosBarra de pinos3 pcs
Botão de pressãoBotão de pressão1 pcs
Fio de soldaFio de solda10 g

Ferramentas necessárias:

Ferro de soldarFerro de soldar
13

Check rails and fit ESP32

Power the board through USB-C from a bench supply set to 5 V, 0.3 A limit, without the ESP32. Check 5 V on the DevKit 5V socket pin and on J4 pin 1. Then plug in the ESP32 dev board with the antenna toward the SOIL edge.

Materiais para este passo:

Placa de desenvolvimento ESP32Placa de desenvolvimento ESP321 pcs

Ferramentas necessárias:

Fonte de alimentação de corrente contínuaFonte de alimentação de corrente contínua
MultímetroMultímetro
14

Fit board into enclosure base

Set the controller board on the base standoffs with USB-C and the pump terminal at their openings. Fix with four M3 x 6 self-tapping screws.

Materiais para este passo:

Parafuso autoatarraxanteParafuso autoatarraxante4 pcs

Ferramentas necessárias:

Conjunto de chaves de fendasConjunto de chaves de fendas
15

Mount OLED in enclosure lid

Screw the OLED to the four lid posts with four M2 x 5 self-tapping screws (check the 23 x 23.5 mm hole pattern). Connect it to J7 with a 4-wire female jumper: GND, VCC, SCL, SDA. Put the plunger in the button hole.

Materiais para este passo:

SSD1306 OLED Display Module1 pcs
Parafuso autoatarraxanteParafuso autoatarraxante4 pcs
Fios de ligaçãoFios de ligação4 pcs

Ferramentas necessárias:

Conjunto de chaves de fendasConjunto de chaves de fendas
16

Mount pump and tank sensor

Set the pump on the tank floor. Pass its leads through the 6 mm lid hole and the tube through the 9.5 mm hole. Press the HC-SR04 transducers into the two 17 mm lid holes, facing down, and fix the sensor with hot glue.

Materiais para este passo:

Bomba de água submersívelBomba de água submersível1 pcs
Tubo de siliconeTubo de silicone1 m
Ultrasonic Distance Sensor1 pcs
Hot-Melt Glue Stick1 pcs

Ferramentas necessárias:

Pistola de cola quentePistola de cola quente
17

Wire pump and sensors

Extend the pump leads with hookup wire if needed, solder and cover with heat shrink. Pump + to J4 pin 1, pump - to J4 pin 2. Solder a 4-pin JST-XH cable to the HC-SR04 (VCC, TRIG, ECHO, GND) and a 3-pin cable to the soil sensor (GND, VCC, AOUT). Plug into J6 and J5.

Materiais para este passo:

Fio de ligaçãoFio de ligação1 m
Manga termorretráctilManga termorretráctil10 cm
Capacitive Soil Moisture Sensor1 pcs
JST-XH Cable2 pcs
Fio de soldaFio de solda3 g

Ferramentas necessárias:

Ferro de soldarFerro de soldar
Descarnador de fiosDescarnador de fios
Conjunto de chaves de fendasConjunto de chaves de fendas
18

Flash firmware

With USB-C power unplugged, connect the DevKit micro-USB through the base slot to a computer. Set TANK_EMPTY_CM and TANK_FULL_CM for this tank, then upload firmware.ino for board esp32:esp32:esp32 with the Arduino IDE. Snap the enclosure lid on.

Ferramentas necessárias:

Computador com o IDE ArduinoComputador com o IDE Arduino
USB Data Cable
19

Leak-test the tank

Fill the printed tank with water and leave it on paper towel for 24 h. If it seeps, reprint with more walls or seal the inside before use.

Ferramentas necessárias:

Jarro medidorJarro medidor
Papel de cozinhaPapel de cozinha
ÁguaÁgua
20

Set up, calibrate and test

Seat the lid on the tank and the enclosure in the lid frame. Push the soil sensor into the pot up to its line and clip the tube end into the stake. Power from the USB-C adapter. Hold the button 3 s for dry/wet calibration. Press briefly to water and check flow, readings and pump current (under 0.8 A).

Materiais para este passo:

USB-C Power Adapter1 pcs
USB-C Cable1 pcs

Ferramentas necessárias:

MultímetroMultímetro
Jarro medidorJarro medidor
Vaso de floresVaso de flores
ÁguaÁgua
21

How this product was generated

AI Generated with Prompt to Product

Materiais

26

Ferramentas necessárias

12

Ficheiros de design

6
  • cus_ai_ed_electronics_01-pcb-prodjob_01M7JE41V7S9SQK1HV75AC433D-pcb-1-3cacf52a.stlSTLCC0
    71.6 KB
  • cus_ai_ed_electronics_01-pcb-prodjob_01M7JE41V7S9SQK1HV75AC433D-pcb-2-4c75c494.stlSTLCC0
    79.1 KB
  • cus_ai_ed_electronics_01-pcb-prodjob_01M7JE41V7S9SQK1HV75AC433D-pcb-3-47b31554.stlSTLCC0
    16.3 KB
  • cus_ai_ed_electronics_01-product-prodjob_01M7JE41V7S9SQK1HV75AC433D-1-8095aebb.stlSTLCC0
    1.4 KB
  • cus_ai_ed_electronics_01-product-prodjob_01M7JE41V7S9SQK1HV75AC433D-2-e010c2f2.stlSTLCC0
    46.5 KB
  • cus_ai_ed_electronics_01-product-prodjob_01M7JE41V7S9SQK1HV75AC433D-3-c5688cb5.stlSTLCC0
    32.2 KB

Blueprints relacionados

Estes blueprints compartilham conhecimento — técnicas, materiais ou princípios

CC0 Domínio Público

Este blueprint é liberado sob CC0. Você é livre para copiar, modificar, distribuir e usar este trabalho para qualquer finalidade, sem pedir permissão.

Apoie o Maker comprando produtos através do Blueprint, onde ele ganha uma Comissão Maker definida pelos vendedores, ou crie uma nova versão deste Blueprint e inclua-o como conexão no seu próprio Blueprint para compartilhar receita.

Discussão

(0)

Entrar para participar da discussão

Carregando comentários...