예술
뷰티 및 웰니스
공예
문화 및 역사
엔터테인먼트
환경
음식 및 음료
역공학
과학
스포츠
기술
웨어러블
ESP32 Self-Watering Pot Controller
Ed

작성자

Ed

16. 11월 2026FI
20
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.

안내

1

Circuit board

KiCanvas 뷰어 로딩 중...

전문 PCB 디자인 뷰어

2

Schematic

KiCanvas 뷰어 로딩 중...

전문 PCB 디자인 뷰어

3

Print the enclosure base

디자인 파일STL71.6 KBCC0 - Free
4

Print the enclosure lid

디자인 파일STL79.1 KBCC0 - Free
5

Print the button plunger

디자인 파일STL16.3 KBCC0 - Free
6

Print the water tank

디자인 파일STL1.4 KBCC0 - Free
7

Print the tank lid with enclosure seat

디자인 파일STL46.5 KBCC0 - Free
8

Print the tube stake for the pot

디자인 파일STL32.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.

이 단계의 재료:

인쇄 회로 기판인쇄 회로 기판1 pcs

필요한 도구:

멀티미터멀티미터
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.

이 단계의 재료:

칩 저항칩 저항6 pcs
세라믹 칩 커패시터세라믹 칩 커패시터1 pcs
USB-C 소켓USB-C 소켓1 pcs
땜납 선땜납 선5 g

필요한 도구:

인두인두
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.

이 단계의 재료:

다이오드다이오드1 pcs
IRLZ44N 로직 레벨 MOSFETIRLZ44N 로직 레벨 MOSFET1 pcs
전해 커패시터전해 커패시터1 pcs
나사 단자대나사 단자대1 pcs
JST-XH 기판용 핀 헤더JST-XH 기판용 핀 헤더2 pcs
핀 헤더핀 헤더3 pcs
푸시 버튼푸시 버튼1 pcs
땜납 선땜납 선10 g

필요한 도구:

인두인두
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.

이 단계의 재료:

ESP32 개발 보드ESP32 개발 보드1 pcs

필요한 도구:

직류 전원 장치직류 전원 장치
멀티미터멀티미터
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.

이 단계의 재료:

태핑 나사태핑 나사4 pcs

필요한 도구:

드라이버 세트드라이버 세트
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.

이 단계의 재료:

OLED 디스플레이OLED 디스플레이1 pcs
태핑 나사태핑 나사4 pcs
점퍼 와이어점퍼 와이어4 pcs

필요한 도구:

드라이버 세트드라이버 세트
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.

이 단계의 재료:

수중 펌프수중 펌프1 pcs
실리콘 튜브실리콘 튜브1 m
초음파 거리 센서초음파 거리 센서1 pcs
핫멜트 글루 스틱핫멜트 글루 스틱1 pcs

필요한 도구:

글루건글루건
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.

이 단계의 재료:

배선용 전선배선용 전선1 m
열수축 튜브열수축 튜브10 cm
정전용량식 토양 수분 센서정전용량식 토양 수분 센서1 pcs
JST-XH 케이블JST-XH 케이블2 pcs
땜납 선땜납 선3 g

필요한 도구:

인두인두
와이어 스트리퍼와이어 스트리퍼
드라이버 세트드라이버 세트
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.

필요한 도구:

Arduino IDE가 설치된 컴퓨터Arduino IDE가 설치된 컴퓨터
USB 데이터 케이블USB 데이터 케이블
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.

필요한 도구:

계량 저그계량 저그
종이 타월종이 타월
물물
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).

이 단계의 재료:

USB-C 전원 어댑터USB-C 전원 어댑터1 pcs
USB-C 케이블USB-C 케이블1 pcs

필요한 도구:

멀티미터멀티미터
계량 저그계량 저그
화분화분
물물

재료

26

필요 도구

12

디자인 파일

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

관련 블루프린트

이 블루프린트들은 지식을 공유합니다 — 기술, 재료 또는 원리

CC0 퍼블릭 도메인

이 블루프린트는 CC0로 공개되었습니다. 어떤 목적으로든 자유롭게 복사, 수정, 배포 및 사용할 수 있습니다.

제품 구매를 통해 메이커를 지원하세요. 판매자가 설정한 메이커 커미션 을 받거나, 이 블루프린트의 새로운 반복을 만들어 연결로 포함시킬 수 있습니다.

토론

(0)

로그인 하여 토론에 참여하세요

댓글 로딩 중...