Ph sensor and thingspeak collidng


#include <Arduino.h>
#include "DFRobot_LCD.h"
#include <Wire.h>
#include "WiFi.h"
#include "ThingSpeak.h"

**// ThingSpeak----------------------------------------------------------------------/**
**WiFiClient client;**
**char ssid[] = "ASUS nanosun-123";**
**char pass[] = "201312279c"; **
**int status = WL_IDLE_STATUS;**
**unsigned long myChannelNumber = 1967185;**
**const char * myWriteAPIKey = "A3Y9LSEOI6ETE19T";**



// DO SENSOR-----------------------------------------------------------------/
#define DO_PIN A1
#define VREF 5000 // VREF(mv) 
#define ADC_RES 1024 //ADC Resolution/

#define SINGLE_POINT_CALIBRATION 0
#define READ_TEMP (25)

#define CAL1_V (8354) //mv  CHANGE AFTER CALIBRATION
#define CAL1_T (25)   //℃


const uint16_t DO_Table[41] = {
  14460, 14220, 13820, 13440, 13090, 12740, 12420, 12110, 11810, 11530,
  11260, 11010, 10770, 10530, 10300, 10080, 9860, 9660, 9460, 9270,
  9080, 8900, 8730, 8570, 8410, 8250, 8110, 7960, 7820, 7690,
  7560, 7430, 7300, 7180, 7070, 6950, 6840, 6730, 6630, 6530, 6410};

uint8_t Temperaturet;
uint16_t ADC_Raw;
uint16_t ADC_Voltage;
uint16_t DO;

int16_t readDO(uint32_t voltage_mv, uint8_t temperature_c)
{
  #if SINGLE_POINT_CALIBRATION == 00
    uint16_t V_saturation = (uint32_t)CAL1_V + (uint32_t)35 * temperature_c - (uint32_t)CAL1_T * 35;
    return (voltage_mv * DO_Table[temperature_c] / V_saturation);
  #else
    uint16_t V_saturation = (int16_t)((int8_t)temperature_c - CAL2_T) * ((uint16_t)CAL1_V - CAL2_V) / ((uint8_t)CAL1_T - CAL2_T) + CAL2_V;
    return (voltage_mv * DO_Table[temperature_c] / V_saturation);
  #endif
}

// pH SENSOR---------------------------------------/
DFRobot_LCD lcd(16, 2); //16 characters and 2 lines of show

#**define PH_PIN 25 **
**float voltage,phvalue,temperature = 25;**

**float acidVoltage = 2000; //buffer solution at 4.o **
**float neutralVoltage = 1390;   //buffer solution at 7.o **

**const int Sensor_MINvalue1 = 6.5; // +-0.5 from ph 4.0**
**const int Sensor_MAXvalue1 = 7.5;**



void setup()
{
  Serial.begin(115200);


    // LCD Begin //
  lcd.init();
  lcd.setCursor(4,0);
  lcd.print("Welcome");
  delay(1000);
  lcd.clear();

  lcd.setCursor(3,0);
  lcd.print("Reading ");
  lcd.setCursor(3,1);
  lcd.print("pH & DO");
  delay(1000);
  lcd.clear();

  lcd.setCursor(3,0);
  lcd.print("Please Wait");
  delay(1000);
  lcd.clear();

}



void loop()
{
**//ThingSpeak----------------------------------------------------------//**
**      delay(100);**
**      float P = phvalue;**
**      float D = (readDO(ADC_Voltage, Temperaturet)/1000);**

**      ThingSpeak.setField(1,P);**
**      ThingSpeak.setField(2,D); **
**      ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);** 

  **//pH SENSOR--------------------------------------//**
**    static unsigned long timepoint = millis();**

**    if(millis()-timepoint>1000U){**
**      timepoint = millis();// timepoint = read temperature **

**      voltage = analogRead (PH_PIN)/4095.0*3300; **

**      float slope = (7.0-4.0)/((neutralVoltage-1500)/30 - (acidVoltage-1500)/3.0);**
**      float intercept = 7.0 - slope*(neutralVoltage-1500)/3.0;**

**      phvalue = slope*(voltage-1500)/3.0 + intercept;   // y=k*x + b [formula]**

      if( phvalue < Sensor_MAXvalue1 && phvalue > Sensor_MINvalue1 ){
         Serial.print("Voltage:");
         Serial.print(voltage,1);
         Serial.print("PH:");
         Serial.println(phvalue,2);

          //LCD setting 16x2
         lcd.setCursor(0,0);
         lcd.print("PH: ");
        
         lcd.print(phvalue,2);

         lcd.setCursor(0,1);
         lcd.print("Volt: ");
         lcd.print(voltage/1000,2);} 
      else {
        lcd.init();
        lcd.setCursor(0,0);
        lcd.print("DOSING REQUIRED");
        delay(1000);
        lcd.clear(); }   
    }

    Temperaturet = (uint8_t)READ_TEMP;
    ADC_Raw = analogRead(DO_PIN);
    ADC_Voltage = uint32_t(VREF) * ADC_Raw / ADC_RES;

    Serial.print("Temperaturet:\t" + String(Temperaturet) + "\t");
    Serial.print("ADC RAW:\t" + String(ADC_Raw) + "\t");
    Serial.print("ADC Voltage:\t" + String(ADC_Voltage) + "\t");
    Serial.println("DO:\t" + String(readDO(ADC_Voltage, Temperaturet)) + "\t"); 

    //LCD setting 16x2
    lcd.setCursor(9,0);
    lcd.print((readDO(ADC_Voltage, Temperaturet))/1000);
    lcd.print("mg/L");
    delay(5000);
    lcd.clear();   
    return; 
}

I have posted a similar code before but about a different question, as of now. i have fixed my thingSpeak, Dissolved Oxygen sensor.

however, upon including the thingspeak code into t it causes my Ph sensor to misread the ph from 7ph it would read 15.16047ph I believe it's not the code that's having the issue but the formula [ calculation ] , is there a way for me to change it so that it would read back 7ph instead. the bolded code is my ph and thins

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