pH sensor returning values not corresponding to pH

So I am working with an Atlas Gravity pH Sensor and in the calibration code the sensor returned plausible pH values, whereas with the code I'm writing I get values that don't make sense. is there some command that helps return the actual ph level?

No. You must compute a value based on the voltage read from the sensor. I see a stated value of 2.7 to 0.2 volts. What numbers are you getting from the analog read?

Which Arduino board do you have ?

The Atlas Scientific Gravity™ Analog pH Sensor / Meter: https://atlas-scientific.com/embedded-solutions/gravity-analog-ph-sensor-meter/.
They say: pH = (-5.6548 * voltage) + 15.509

Put it in a glass of water to start with.
When using it with a aquarium, the differences in grounding can disturb the sensor.

They provide code with calibration and storing settings to EEPROM. That code is hard to chew :grimacing: I can not tell if that is good code or not.

2 Likes

Thank you, the values i get are 427-428

Is the water pH 3.7 ?
Calculation: https://www.google.com/search?q=(-5.6548*(427%2F1024*5))%2B15.509

2 Likes

using an elegoo uno r3

yes! thats what it reads on the callibration code thank you so much

Hi, @noveltytimes
Welcome to the forum.

Can you please post your code?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

int pHA = A0;
int led = 2;


void setup(){
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  pinMode(pHA, INPUT);
}

void loop(){
  int pH = analogRead(pHA);
  Serial.println(pH);
  if (pH < 7){
    digitalWrite(led, HIGH);
  }
  delay(1500);
}

^this is my code, the callibration code is a little longer;

uint8_t user_bytes_received = 0;                
const uint8_t bufferlen = 32;                   
char user_data[bufferlen];                     

void parse_cmd(char* string) {                   
  strupr(string);                                
  if (strcmp(string, "CAL,7") == 0) {       
    pH.cal_mid();                                
    Serial.println("MID CALIBRATED");
  }
  else if (strcmp(string, "CAL,4") == 0) {            
    pH.cal_low();                                
    Serial.println("LOW CALIBRATED");
  }
  else if (strcmp(string, "CAL,10") == 0) {      
    pH.cal_high();                               
    Serial.println("HIGH CALIBRATED");
  }
  else if (strcmp(string, "CAL,CLEAR") == 0) { 
    pH.cal_clear();                              
    Serial.println("CALIBRATION CLEARED");
  }
}

void setup() {
  Serial.begin(9600);                            
  delay(200);
  Serial.println(F("Use commands \"CAL,7\", \"CAL,4\", and \"CAL,10\" to calibrate the circuit to those respective values"));
  Serial.println(F("Use command \"CAL,CLEAR\" to clear the calibration"));
  if (pH.begin()) {                                     
    Serial.println("Loaded EEPROM");
  }
}

void loop() {
  if (Serial.available() > 0) {                                                      
    user_bytes_received = Serial.readBytesUntil(13, user_data, sizeof(user_data));   
  }

  if (user_bytes_received) {                                                      
    parse_cmd(user_data);                                                          
    user_bytes_received = 0;                                                        
    memset(user_data, 0, sizeof(user_data));                                         
  }
  
  Serial.println(pH.read_ph());                                                      
  delay(1000);
}

Really sorry about the formatting, apparently i still dont have attachment privileges

Please post ALL the code. The errors are in the part you did not post.

// to use the Atlas gravity circuits with 
// the gravity isolator board's pulse output 
// uncomment line 8: #define USE_PULSE_OUT
// you can use any pins instead of just the analog ones
// but it must be recalibrated
// note that the isolator's analog output also provides isolation

// #define USE_PULSE_OUT

#ifdef USE_PULSE_OUT
  #include "ph_iso_grav.h"       
  Gravity_pH_Isolated pH = Gravity_pH_Isolated(A0);         
#else
  #include "ph_grav.h"             
  Gravity_pH pH = Gravity_pH(A0);   
#endif

@jremington this is the rest of the code i omitted from the calibration code, it wasnt used when i ran either sets of code, theres nothing else left

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.