Build Project

Agriculture

Build an Educational Soil pH Monitor

Build an educational ESP32 soil pH monitor with a conditioning board, GPIO34 ADC1 input, pH 4/pH 7 calibration, and no fertilizer advice.

AdvancedAges 13+75-90 minUnder 45 USDParent Safe
Project Mission

Build an Educational Soil pH Monitor

The Story

Soil pH sounds like one number, but the measurement depends on calibration, probe care, temperature, slurry preparation, and patience. This Golden project teaches the engineering workflow without pretending to be a lab instrument or agricultural decision system.

Explain Like I'm 12

A pH probe makes a tiny chemical voltage that needs a special interface board before the ESP32 can read it. You first teach the code what pH 7 and pH 4 look like, then it estimates a soil-water slurry reading from the ADC number.

Learning Support

  • Recommended ageAges 13+
  • Adult supervisionRecommended for handling calibration liquids and caring for the probe.
  • Classroom useRun as a calibration and measurement-limits lab; do not make crop-treatment decisions from the result.
  • Parent promptAsk why calibration has to happen before the ESP32 prints a pH estimate.
  • Screen-free activityMake a table for pH 7 buffer ADC, pH 4 buffer ADC, slurry ADC, and estimated pH.
  • Next challengeStore calibration values in nonvolatile memory after validating the manual constants.
  • Skills practiced
    • ADC1 analog reading
    • Two-point calibration
    • Sensor interface limits
    • Measurement uncertainty
  • Learning outcomes
    • Use a pH conditioning board output on ADC1 GPIO34.
    • Require pH 7 and pH 4 calibration before readings.
    • Prepare a soil-water slurry instead of pushing a probe into dry soil.
    • Explain drift, stabilization, storage, and cleaning limits.
  • Mini experiments
    • Record stable pH 7 ADC values.
    • Record stable pH 4 ADC values.
    • Compare two soil slurries after the readings settle.

Safety Standards

  • Unplug USB before changing jumper wires. Recheck 3.3 V, 5 V, and GND before reconnecting power.
  • Do not power motors, pumps, LED strips, or servos from the ESP32 3.3 V pin. Use a suitable external supply and common ground.
  • Breadboards are for low-current prototypes. Move high-current or unattended builds to proper terminals, enclosure, strain relief, and fusing.

What You Will Build

An educational soil pH estimator that reads a conditioned pH interface output on GPIO34 after mandatory two-point calibration.

Components List

  • ESP32 DevKit boardUses ADC1 GPIO34 for the conditioned analog signal.
  • pH probe with conditioning/interface boardDo not connect a bare pH probe directly to the ESP32 ADC.
  • pH 7 and pH 4 calibration buffersRequired for two-point calibration before soil readings.
  • Distilled water and clean cupUsed for rinsing and making a soil-water slurry.
  • Soil sampleMeasured as a settled slurry for educational estimates.

Bill of Materials

PartQtyEstimated CostNotes
ESP32 DevKit board1VariesUses ADC1 GPIO34 for the conditioned analog signal.
pH probe with conditioning/interface board1VariesDo not connect a bare pH probe directly to the ESP32 ADC.
pH 7 and pH 4 calibration buffers1VariesRequired for two-point calibration before soil readings.
Distilled water and clean cup1VariesUsed for rinsing and making a soil-water slurry.
Soil sample1VariesMeasured as a settled slurry for educational estimates.

Wiring

The pH probe connects to its interface board. Only the conditioned AOUT signal goes to ESP32 ADC1 GPIO34, and the interface output must stay within 0-3.3 V.

Wiring Diagram ESP32 DevKit GPIO34 connected to the analog output of a pH conditioning board, with 3.3 V-compatible output and common ground.
  1. 1

    Unplug USB before wiring the pH interface board.

  2. 2

    Connect the pH probe to the conditioning/interface board, not directly to the ESP32.

  3. 3

    Connect interface GND to ESP32 GND.

  4. 4

    Power the interface only as its datasheet allows, and confirm AOUT cannot exceed 3.3 V at the ESP32 pin.

  5. 5

    Connect interface AOUT to GPIO34.

  6. 6

    Calibrate with pH 7 and pH 4 buffers before measuring a soil-water slurry.

GPIO Mapping

SignalESP32 PinDirectionNotes
pH interface AOUTGPIO34ADC1 inputConditioned analog output only; must be 0-3.3 V.

Circuit Explanation

The glass pH probe is high impedance and must feed a conditioning board. The ESP32 reads only the board's conditioned voltage on ADC1 GPIO34.

Engineering Explanation

Two-point calibration sets the line between pH 7 and pH 4 buffer ADC values. Readings drift with probe condition, temperature, contamination, slurry preparation, and stabilization time, so the output is an estimated educational value.

Libraries

  • Arduino ESP32 coreNo external library is required for the basic ADC sketch.

Code

Copy into Arduino IDE. Install any libraries noted in the component guides first.

esp32-soil-ph-monitor.ino
// ESP32 educational soil pH monitor
// Uses a pH interface board on ADC1 GPIO34. Calibrate before reading soil slurry samples.
const int PH_PIN = 34;

const bool CALIBRATION_RECORDED = false; // Set true only after recording your own pH 7 and pH 4 ADC values.
const float PH7_ADC = 2048.0;            // Replace with stabilized ADC average in pH 7 buffer.
const float PH4_ADC = 1530.0;            // Replace with stabilized ADC average in pH 4 buffer.

float averageAdc() {
  long sum = 0;
  for (int i = 0; i < 30; i++) {
    sum += analogRead(PH_PIN);
    delay(20);
  }
  return sum / 30.0;
}

float estimatedPh(float raw) {
  float slope = (7.0 - 4.0) / (PH7_ADC - PH4_ADC);
  return 7.0 + slope * (raw - PH7_ADC);
}

void setup() {
  Serial.begin(115200);
  analogReadResolution(12);
  analogSetPinAttenuation(PH_PIN, ADC_11db);
  Serial.println("Educational soil pH monitor - calibrated estimates only.");
}

void loop() {
  if (!CALIBRATION_RECORDED) {
    Serial.println("Calibration required: record stable pH 7 and pH 4 buffer ADC values, update constants, then set CALIBRATION_RECORDED true.");
    delay(2000);
    return;
  }

  float raw = averageAdc();
  float voltage = raw * 3.3 / 4095.0;
  float ph = estimatedPh(raw);

  Serial.printf("Estimated calibrated pH: %.2f | ADC: %.0f | Interface voltage: %.2f V\n", ph, raw, voltage);
  delay(5000);
}

Code Explanation

The sketch refuses to calculate pH until the user records real pH 7 and pH 4 ADC averages, updates the constants, and sets CALIBRATION_RECORDED true.

Expected Output

Before calibration, Serial Monitor repeatedly prints the calibration-required message. After valid constants are entered, it prints Estimated calibrated pH, ADC average, and interface voltage for the slurry sample.

Troubleshooting

  • Code only prints calibration required Record stabilized pH 7 and pH 4 ADC values, update constants, and set CALIBRATION_RECORDED true.
  • Readings drift Rinse the probe, wait for stabilization, check probe storage, and repeat calibration if needed.
  • ADC values are stuck or saturated Confirm AOUT is wired to GPIO34, grounds are common, and the interface output stays within 0-3.3 V.

Common Mistakes

  • Connecting a bare pH probe directly to GPIO34.
  • Skipping pH 7 and pH 4 calibration.
  • Letting the interface output exceed 3.3 V at the ESP32 ADC pin.
  • Treating the estimate as lab-grade or agricultural advice.

Testing Checklist

  • Verify interface output range.
  • Record pH 7 buffer ADC.
  • Record pH 4 buffer ADC.
  • Measure only a soil-water slurry after stabilization.

Engineering Tips

  • Use ADC1, not ADC2, when Wi-Fi may be added later.
  • Let readings stabilize.
  • Store and clean the probe according to its datasheet.

Upgrade Ideas

  • Add an OLED that shows the calibration-required state.
  • Store calibration constants in NVS.
  • Add a temperature sensor and document compensation limits.

Real-World Applications

  • Soil science classroom lab
  • Calibration workflow lesson
  • Sensor uncertainty demonstration

FAQs

Can I connect the pH probe directly to the ESP32?

No. Use a proper high-impedance pH interface board.

Can this tell me what fertilizer to add?

No. It is an educational estimate, not lab-grade advice or crop-treatment guidance.

Review, Testing, and References

Author: Abdul Mubeen and the ESP32 Engine editorial team. Last updated: 2026-07-10. Reviewed: wiring logic, Arduino code structure, beginner safety, and learning sequence.

Educational level: Advanced. Estimated completion time: 75-90 min. This project is for learning and prototyping; production or unattended hardware needs additional engineering review.

Project Complete!

You built an educational soil pH estimator with mandatory calibration, ADC1 GPIO34, interface-board voltage limits, and honest measurement boundaries. The project teaches calibration before conclusions.

  • ADC1 analog measurement
  • Two-point calibration
  • Voltage-limit verification
  • Probe care and drift troubleshooting