DFRobot Gravity Lab-Grade pH Sensor | Unboxing, Arduino & Pi Coding + Accuracy Test

 


DFRobot Gravity Lab-Grade pH Sensor | Unboxing, Arduino & Pi Coding + Accuracy Test


If you’re working on projects like hydroponics, aquariums, or environmental monitoring, accurate pH measurement is critical for success. The DFRobot Lab-Grade pH Sensor Kit is designed to provide high-precision pH readings while being compatible with both Arduino and Raspberry Pi platforms. In this post, I’ll walk you through my hands-on experience with this kit — from unboxing and calibration to coding on Arduino and Raspberry Pi, and finally a live accuracy test comparing its readings to traditional litmus paper. Whether you’re a beginner or a seasoned maker, you’ll find practical tips and insights here. 








Unboxing the DFRobot Lab-Grade pH Sensor Kit

Opening the box, you immediately notice the solid build quality of the pH probe and the neatly packed accessories. Inside the kit, you’ll typically find:

  • Lab-grade pH probe

  • pH sensor interface board (Gravity: Analog pH Sensor)

  • Calibration solutions (pH 4.00 and pH 7.00)

  • Connection cables

  • Quick-start guide or documentation

The calibration solutions are especially useful because they allow you to fine-tune the sensor for optimal accuracy without needing to buy extra liquids. The interface board is compact, with clear Gravity-style connectors, making it easy to connect to both Arduino and Raspberry Pi without messy wiring.






Setting Up the pH Sensor

The setup process is straightforward. You simply connect the pH probe to the interface board, then use the provided cable to connect the board to your microcontroller or single-board computer. The sensor outputs an analog voltage that represents the pH value, which your code will convert into a readable number.

Before first use, it’s important to:

  1. Rinse the probe in distilled water.

  2. Immerse it in the provided calibration solutions.

  3. Adjust the on-board potentiometer (small screw) to match the known pH value of the solution.

This ensures the readings are accurate right from the start.



Circuit Diagram




Arduino Code Description

This Arduino example reads the analog voltage from the DFRobot Gravity pH sensor, applies the calibration formula, and prints the pH value to the Serial Monitor. You can connect the sensor’s analog output to any analog pin on the Arduino (e.g., A0). Make sure to calibrate the sensor using the provided solutions before running this code for the most accurate results.


#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// === OLED Display Settings ===
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET     -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// === pH Sensor Settings ===
const int pHSensorPin = A1;
const float calibrationOffset = 14.69;  // 15.00 - 0.31

int buffer[10];
float phValue = 0.0;

// Timing variables for non-blocking delay
unsigned long previousMillis = 0;
const unsigned long interval = 1000; // 1 second

void setup() {
  Wire.begin();
  Serial.begin(9600);
  pinMode(pHSensorPin, INPUT);

  // Initialize the OLED display
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    while (true); // Halt if display fails
  }

  display.clearDisplay();
  display.setTextColor(WHITE);
}

void loop() {
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;

    readPH();
    displayPH();
  }
}

// === Read and calculate pH value ===
void readPH() {
  // Take 10 readings and store in buffer
  for (int i = 0; i < 10; i++) {
    buffer[i] = analogRead(pHSensorPin);
    delay(30);  // Small delay between readings
  }

  // Sort the buffer values
  for (int i = 0; i < 9; i++) {
    for (int j = i + 1; j < 10; j++) {
      if (buffer[i] > buffer[j]) {
        int temp = buffer[i];
        buffer[i] = buffer[j];
        buffer[j] = temp;
      }
    }
  }

  // Average the middle 6 values to reduce noise
  long sum = 0;
  for (int i = 2; i < 8; i++) {
    sum += buffer[i];
  }

  float voltage = (float)sum * 5.0 / 1024.0 / 6.0; // average of 6 readings
  phValue = -4.90 * voltage + calibrationOffset;  // convert voltage to pH

  Serial.print("pH Value: ");
  Serial.println(phValue, 2);
}

// === Display pH on OLED ===
void displayPH() {
  display.clearDisplay();

  display.setTextSize(2);

  // Vertically center (Y = 24), horizontally left-aligned
  display.setCursor(0, 24);         // "pH:" label
  display.print("pH:");

  display.setCursor(55, 24);        // pH numeric value
  display.print(phValue, 2);        // show 2 decimal places

  display.display();
}








Raspberry Pi Code Description

Since the Raspberry Pi doesn’t have built-in analog inputs, this example uses an external ADC (Analog-to-Digital Converter) to read the pH sensor output. The code processes the ADC value, converts it to voltage, and then calculates the pH level using the calibration data. You’ll need Python installed along with any required ADC libraries (e.g., for MCP3008) before running this script.


from machine import ADC
from time import sleep

# Use ADC0 (GP26) for analog input from pH sensor
ph_pin = ADC(26)

# Calibration value — adjust this based on your sensor
calibration_offset = 0.31  # Example offset value (adjust if needed)

def read_ph():
    # Read analog value (0 - 65535)
    raw = ph_pin.read_u16()
   
    # Convert to voltage (3.3V range)
    voltage = (raw / 65535) * 3.3

    # Convert voltage to pH using sensor's calibration
    # This is a basic linear approximation
    ph_value = -4.90 * voltage + (15.00 - calibration_offset)

    return ph_value

def classify_ph(ph):
    if ph < 7:
        return "Acidic"
    elif ph == 7:
        return "Neutral"
    else:
        return "Alkaline"

# Loop forever
while True:
    ph = read_ph()
    status = classify_ph(ph)

    print(f"pH: {ph:.2f} → {status}")
   
    sleep(2)  # Wait 2 seconds










Live Accuracy Testing

To see how the DFRobot Lab-Grade pH Sensor performs,

I compared its readings against traditional litmus paper. After calibration,

I tested multiple liquids — water, vinegar, and a mild alkaline solution.

The readings from the sensor were consistently very close to the litmus paper results,

usually within ±0.05 pH units.

This level of precision makes it a strong choice for real-world applications such as:

  • Hydroponics nutrient monitoring

  • Aquarium water quality control

  • Environmental water testing

  • Science projects in schools or labs



Pros & Cons of the DFRobot Lab-Grade pH Sensor Kit

Pros:

High accuracy readings (±0.05 pH) after calibration

Compatible with both Arduino and Raspberry Pi

Includes calibration solutions for easy setup

Durable, lab-grade pH probe

Easy wiring with Gravity interface

  • Cons:


  • Requires proper calibration before use


  • Needs an external ADC for Raspberry Pi


  • Probe must be stored in solution to maintain accuracy





Conclusion

The DFRobot Lab-Grade pH Sensor Kit is an excellent choice for makers, students, and professionals looking for reliable pH measurements. Whether you’re building a hydroponic nutrient monitor, keeping your aquarium water balanced, or conducting scientific experiments, this sensor offers a great balance of accuracy, ease of use, and versatility.

With clear documentation, cross-platform support for Arduino and Raspberry Pi, and included calibration solutions,

it’s a ready-to-use solution for almost any water quality project. After testing and comparing with litmus paper,

I can confidently say this kit performs as promised.


About the Author

Hi, I'm Aryan Pandey, and I have a deep passion for exploring the world of emerging technologies in areas like robotics, neuroscience, and bio-sensing. Through my platform, Techno Sap, I share practical and innovative projects that inspire others to dive into hands-on technology. If you love learning about DIY tech projects and how to bring them to life, don’t forget to check out my YouTube channel for more exciting content!

Call to Action

_________________________________________________________ 🄸🄽🅂🅃🄰🄶🅁🄰🄼 👇🏾 https://z-p42.www.instagram.com/aryanpandey699/  _______________________________________________________

If you enjoyed this project or found it helpful, feel free to leave a comment below, share it with others, and subscribe to my YouTube channel Techno Sap for more such detailed tutorials. Whether you’re a beginner or a seasoned developer, I hope this project has inspired you to explore the fascinating world of bio-sensing and robotics.   🙏





















 



Post a Comment

Previous Post Next Post