OC
OceanRemote
Low-code IoT platform
← Back to Course

pH Sensors and Measurement Methods

pH Sensors and Measurement Methods

🔌 pH Sensors and Measurement Methods - Soil Acidity Monitoring

🔌 What You'll Learn:

  • 🧪 Compare 4 pH measurement methods (strips, pen, sensor, lab)
  • 🔌 Wire analog pH sensor to ESP32 for continuous monitoring
  • 📊 Convert voltage readings to actual pH values (0-14 scale)
  • ⚙️ Calibrate sensor using pH 4 and pH 7 buffer solutions

📊 pH Measurement Methods Comparison

Method Price Accuracy Pros Cons
🧪 pH Test Strips$5-10±0.5Cheap, no batteriesLow accuracy, one-time use
📱 Digital pH Pen$10-20±0.1Portable, instant readingNeeds calibration monthly
🖥️ Soil pH Sensor$15-30±0.2Continuous monitoringNeeds ESP32, calibration
🔬 Lab Analysis$10-15/sample±0.05Most accurateSlow, per-sample cost

🔌 Soil pH Sensor Wiring

pH Sensor (Analog)          ESP32
═══════════════════          ═══════
VCC (3.3V/5V)      ─────►   3.3V
GND                ─────►   GND
PO (pH Output)     ─────►   GPIO34 (ADC)
    

📖 Complete pH Sensor Code

#define PH_PIN 34

// Calibration values (measure in pH 7 and pH 4 solutions)
float ph7_voltage = 2.50;   // Voltage reading in pH 7 buffer
float ph4_voltage = 3.00;   // Voltage reading in pH 4 buffer

float readPH() {
    int raw = analogRead(PH_PIN);
    float volt = raw * (3.3 / 4095.0);
    
    // Linear calibration: slope = (7-4)/(volt7 - volt4)
    float slope = 3.0 / (ph7_voltage - ph4_voltage);
    return 7.0 - (volt - ph7_voltage) * slope;
}

void setup() {
    Serial.begin(115200);
    pinMode(PH_PIN, INPUT);
}

void loop() {
    float ph = readPH();
    
    Serial.printf("🌡️ Soil pH: %.1f\n", ph);
    
    if (ph < 5.5)      Serial.println("   ❌ ACIDIC → Add 2-3kg lime/100m²");
    else if (ph < 6.5) Serial.println("   ✅ OPTIMAL for most crops");
    else if (ph < 7.5) Serial.println("   ✅ GOOD (slightly alkaline)");
    else               Serial.println("   ❌ ALKALINE → Add sulfur/compost");
    
    delay(60000);
}
    
💡 Calibration Steps (Critical!):
  1. Buy pH 4.0 and pH 7.0 buffer solutions ($10)
  2. Rinse probe with distilled water
  3. Dip in pH 7.0 → read voltage → record as ph7_voltage
  4. Dip in pH 4.0 → read voltage → record as ph4_voltage
  5. Update code with your values
⚠️ pH Sensor Care:
  • ❌ Never let probe dry out → Store in storage solution or pH 4 buffer
  • ❌ Don't touch glass bulb (oils from skin affect readings)
  • ✅ Calibrate monthly (or before each use for accuracy)
  • ✅ Replace probe every 1-2 years (signal slows down)
🎯 Quick Reference:
  • 🧪 pH < 5.5: Add lime (2-3kg/100m²)
  • ✅ pH 6.0-7.0: Perfect for vegetables
  • 🧪 pH > 7.5: Add sulfur or organic matter
  • ⚙️ Calibrate monthly for accuracy
💡 Key Takeaways:
  • Apply these concepts directly to your farm or project.
  • Take notes on important details for the quiz.
  • Use the button below to track your progress.