pH Sensor and ADS1115 output I2C

Hey folks,
Im trying to migrate a pH sensor (PH-4502C) from an UNO to a Wemos Mini using an ADS1115 and

level shifter.

I cant seem to integrate the output of the ADS1115 (adc0) into the existing Generic pH code

(see below). The output from the ADS1115 (adc0) seems to be working correctly with as expected

results using just a ADS1115 test sketch (see below).

I have done an extensive search, Google, Multiple Forums, etc. cant seem to figure it out on my own as

of now.

Fairly certain A0 would be commented out but not sure how to handle the analogRead(analogInPin);

SCL = (D1) SDA = (D2), Would it be DigitalRead (D2)? I wouldn’t think so as ADC0 is already provided.

Knowing everyone is busy nowadays, any help would be greatly appreciated.

Mike

ADS1115 code

#include <Wire.h>
#include <Adafruit_ADS1015.h>

Adafruit_ADS1115 ads(0x48);
float Voltage = 0.0;

void setup(void) 
{
  Serial.begin(9600);  
  ads.begin();
}

void loop(void) 
{
  int16_t adc0;  // we read from the ADC, we have a sixteen bit integer as a result

  adc0 = ads.readADC_SingleEnded(0);
  Voltage = (adc0 * 0.1875)/1000;
  
  Serial.print("AIN0: "); 
  Serial.print(adc0);
  Serial.print("\tVoltage: ");
  Serial.println(Voltage, 7);  
  Serial.println();
  
  delay(1000);
}

pH code (PH-4502C)

//const int analogInPin = A0; 

unsigned long int avgValue; 
int buf[10],temp;
void setup() {
 Serial.begin(9600);
}
 
void loop() {
 for(int i=0;i<10;i++) 
 { 
  buf[i]=analogRead(analogInPin);
  delay(10);
 }
 for(int i=0;i<9;i++)
 {
  for(int j=i+1;j<10;j++)
  {
   if(buf[i]>buf[j])
   {
    temp=buf[i];
    buf[i]=buf[j];
    buf[j]=temp;
   }
  }
 }
 avgValue=0;
 for(int i=2;i<8;i++)
 avgValue+=buf[i];
 float pHVol=(float)avgValue*5.0/1024/6;
 float phValue = -5.70 * pHVol + 21.34;
 Serial.print("sensor = ");
 Serial.println(phValue);
 
 delay(20);
}

Why using level shifters?

What output does the ADS1115 actually give you?

Hey, I used the Level shifter to handle the 5v pH sensor on the 3.3 volt Wemos.

measuring approx. a pH of 7 using just the ADS1115 test code. It changes when I change test liquid.

19:20:44.740 -> AIN0: 14367 Voltage: 2.6938126 19:20:44.787 -> 19:20:45.757 -> AIN0: 14367 Voltage: 2.6938126 19:20:45.804 -> 19:20:46.776 -> AIN0: 14368 Voltage: 2.6940000

Mike

M_Angelopulos: Hey, I used the Level shifter to handle the 5v pH sensor on the 3.3 volt Wemos.

That board gives an output of about 2.5V at pH=7, and a normal pH probe has -59 mV/pH point change. So as long as the pH remains above -6 (yes, it can go negative) you're fine.

The only possible level shifting would be by voltage divider, and then you're risking your measurement to be thrown off by the voltage divider that's built into the WeMOS (the ADC of which has a range of 0-1V).

Make sure you know and understand both the signal you're trying to measure and what you're measuring your signal with!

wvmarle, Thanks for the reply. I'm not using the Analog pin, I wouldn't think the internal ADC would be an issue.

Mike

I figured it out,

Thanks,

#include <Wire.h>
#include <Adafruit_ADS1015.h>

Adafruit_ADS1115 ads(0x48);

#define Sensorpin D2                              //ADS1115 output from A0,  SCL=D1 SDA=D2 
unsigned long int avgValue;                       //Store the average value of the sensor feedback
int buf[10], temp;
float phVoltage = 0.0;

void loop()

{
  int16_t adc0;                                    //read from the ADC, sixteen bit integer as a result
  adc0 = ads.readADC_SingleEnded(0);
  phVoltage = (adc0 * 0.1875) / 1000;

  for (int i = 0; i < 10; i++)                    //Get 10 sample value from the sensor for smooth the value
  {
    buf[i] = analogRead(Sensorpin);
    delay(10);
  }
  for (int i = 0; i < 9; i++)                     //sort the analog from small to large
  {
    for (int j = i + 1; j < 10; j++)
    {
      if (buf[i] > buf[j])
      {
        temp = buf[i];
        buf[i] = buf[j];
        buf[j] = temp;
      }
    }
  }
  avgValue = 0;
  for (int i = 2; i < 8; i++)                     //take the average value of 6 center sample
    avgValue += buf[i];
  float phValue = -5.70 * phVoltage + 21.34;      //  Slope calculation?
  Serial.print("sensor = ");
  Serial.println(phValue);

  delay(1000);
}

void setup() {
  Serial.begin(9600);
  ads.begin();
}

Thanks,