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.