Projects / Hydroponic nutrient and pH doser

Hydroponic nutrient and pH doser

Advanced5 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32

    Calibrate pH

    Use buffers 4 and 7.

  2. ESP32TDS

    Calibrate TDS

    Use a known standard solution.

  3. ESP32

    Test the pumps

    Find the ml delivered per second.

  4. ESP32

    Write the dose logic

    Dose, wait and read again.

  5. ESP32

    Add the daily limit

    Stop at 12 doses.

  6. ESP32TDS

    Add the display

    Show pH, TDS and the last dose.

  7. ESP32

    Run on a bucket

    Test with water before using nutrients.

In short

How do you build a hydroponic nutrient and pH doser?

Peristaltic pumps add nutrient or pH-down solution in small doses to keep a hydroponic tank within the TDS and pH targets. You need ESP32 DevKit V1, TDS sensor module, pH sensor kit (analog), DS18B20 waterproof probe, Resistor 4.7 kΩ, Peristaltic pump 12 V × 2, L298N Dual H-Bridge Module, 12 V 2 A DC adapter and SSD1306 OLED Display. It takes 7 steps and about 300 minutes.

Level
Advanced
Time
About 300 min
Parts
9

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
TDS sensor signalESP32 GPIO34Analog in
pH board outputESP32 GPIO35Analog in
DS18B20 dataESP32 GPIO4, with 4.7 kΩ to 3V3Water temperature
L298N IN1 and IN2ESP32 GPIO25 and GPIO26pH-down pump
L298N IN3 and IN4ESP32 GPIO27 and GPIO14Nutrient pump
PumpsL298N OUT1 and OUT3Dosing
12 V adapterL298N supplyPower (fuse 2 A)
OLED SDA and SCLESP32 GPIO21 and GPIO22Display

Code

Dosing is slow chemistry: add a little, wait for the water to circulate, then read again, because reading right after a dose makes the controller overshoot. Calibrate the pH probe with fresh pH 4 and pH 7 buffer solutions and the TDS probe with a known standard, then replace the two simple conversion lines in the sketch. The daily maximum stops a stuck probe from pumping acid into the tank all night. Keep nutrients, acid and the electronics apart, put the pump tubing in a tray, wear gloves and eye protection when handling concentrated pH-down, and keep it away from children and pets. Arduino IDE with the ESP32 boards package 2.0.x, board "ESP32 Dev Module". This is a hobby controller for leafy greens and herbs; for a commercial crop keep checking by hand.

Runs on a virtual ESP32 Dev Module 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).

// Doser: dose in small steps, then wait for the water to mix. Board: ESP32 Dev Module.
const int PH_PIN = 34, TDS_PIN = 35;
const int PUMP_PH = 25, PUMP_NUT = 27;
const float PH_MAX = 6.3, TDS_MIN = 700;       // set from your crop guide
const unsigned long MIX_WAIT = 15UL * 60UL * 1000UL;
unsigned long lastDose = 0;
int dosesToday = 0;
float readPh() { return 7.0 + (2.5 - analogRead(PH_PIN) * 3.3 / 4095.0) / 0.18; }  // replace with your calibration
float readTds() { return analogRead(TDS_PIN) * 3.3 / 4095.0 * 500.0; }              // replace with your calibration
void dose(int pin, unsigned long ms) {
  digitalWrite(pin, HIGH); delay(ms); digitalWrite(pin, LOW);
  lastDose = millis(); dosesToday++;
}
void setup() {
  pinMode(PUMP_PH, OUTPUT); pinMode(PUMP_NUT, OUTPUT);
  pinMode(26, OUTPUT); pinMode(14, OUTPUT); digitalWrite(26, LOW); digitalWrite(14, LOW);
  Serial.begin(115200);
}
void loop() {
  float ph = readPh(), tds = readTds();
  Serial.printf("pH %.2f  TDS %.0f  doses %d\n", ph, tds, dosesToday);
  if (millis() - lastDose > MIX_WAIT && dosesToday < 12) {   // daily maximum of 12 doses
    if (ph > PH_MAX) dose(PUMP_PH, 2000);
    else if (tds < TDS_MIN) dose(PUMP_NUT, 2000);
  }
  delay(300000);                                   // read every 5 minutes
}

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 ESP32 Dev Module with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

pH 11.72  TDS 826  doses 0

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
pH too highA short pH-down dose
TDS too lowA short nutrient dose
Right after a doseNo second dose for 15 minutes
Probe unpluggedDaily maximum stops dosing

If it does not work

pH reading jumps

Keep the probe wet and away from pump motors.

Pump delivers little

Prime the tube and check the tube is not kinked.

Overshoots

Shorten the dose or lengthen the wait.

Readings drift

Recalibrate and clean the probes.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the hydroponic nutrient and pH doser?

ESP32 DevKit V1, TDS sensor module, pH sensor kit (analog), DS18B20 waterproof probe, Resistor 4.7 kΩ, Peristaltic pump 12 V × 2, L298N Dual H-Bridge Module, 12 V 2 A DC adapter and SSD1306 OLED Display.

How long does the hydroponic nutrient and pH doser take to build?

About 300 minutes for a advanced maker, in 7 steps.

How do I know the hydroponic nutrient and pH doser works?

pH too high: A short pH-down dose. TDS too low: A short nutrient dose. Right after a dose: No second dose for 15 minutes.

pH reading jumps: what should I check?

Keep the probe wet and away from pump motors.

Pump delivers little: what should I check?

Prime the tube and check the tube is not kinked.

Overshoots: what should I check?

Shorten the dose or lengthen the wait.

Readings drift: what should I check?

Recalibrate and clean the probes.