Serial.begin(115200);
what does the the difference make?
If your Arduino uses full speed native USB protocol for the serial connection, the Baud rate setting doesn't matter. If the Arduino has a UART serial connection (Uno, Nano, etc.), the smaller value won't work at all.
@noiasca @touch1337 @guix @LarryD @jremington @alto777 @camsysca @ToddL1962 @johnwasser @Idahowalker
after checking the program I have found out that the code works if I remove things that are related to thingspeak below is the code without thingspeak is there a reason y its affected by thingspeak?
#include <Arduino.h>
#include "DFRobot_LCD.h"
#include <Wire.h>
#include "WiFi.h"
#include "ThingSpeak.h"
// DO SENSOR-----------------------------------------------------------------/
#define DO_PIN A1
#define VREF 5000 // VREF(mv)
#define ADC_RES 1024 //ADC Resolution/
#define TWO_POINT_CALIBRATION 1
#define READ_TEMP (25)
#define CAL1_V (1600) //mv CHANGE AFTER CALIBRATION
#define CAL1_T (25) //℃
#define CAL2_V (1300) //mv CHANGE AFTER CALIBRATION
#define CAL2_T (15) //℃
const uint16_t DO_Table[11] = {
8570, 8410, 8250, 8110, 7960, 7820, 7690, 7560, 7430, 7300, 7180};
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 TWO_POINT_CALIBRATION == 0
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()
{
//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");
}
how did u calculate the ph for yourself?
You can just plug the values into the formulae. The only unknown number is the analogRead value of the pin.
This is how I followed your code and calculated it. This is not suggested changes to make to the code.
float acidVoltage = (1990);
float neutralVoltage = (1389);
//voltage = analogRead (PH_PIN)/4095.0*3300;
//simplify this into:
voltage = 0.806 * analogRead (PH_PIN)
//float slope = (7.0-4.0)/((neutralVoltage-1500)/30 - (acidVoltage-1500)/3.0);
//put neutralVoltage and acidVoltage values into slope calculation
//float slope = (7.0-4.0)/((1389-1500)/30 - (1990-1500)/3.0);
//no unknown values in here, just calculate the result
float slope = -0.018;
//float intercept = 7.0 - slope*(neutralVoltage-1500)/3.0;
//put the known slope and neutralVoltage values in here
//float intercept = 7.0 - -0.018*(1389-1500)/3.0;
//calculate the result
float intercept = 6.334;
//phvalue = slope*(voltage-1500)/3.0 + intercept;
//put known slope and intercept values in here
phvalue = -0.018*(voltage-1500)/3 + 6.334
how did u simplify the analogRead (PH_PIN)/4095.0*3300 into 0.806?
3300 / 4095.0 = 0.806
currently my ph sensor is reading ph of 15.16047 while its suppose to read ph 7 is there a reason y?
What is the analogRead value you get from the pin and what is the expected value?
https://drive.google.com/file/d/1L9cpXp_jUFESq66PKuWuizLmbLk7oaB4/view?usp=sharing
this is the analog value i got, im not sure what the expected value is suppose to be
this is the analog value i got, im not sure what the expected value is suppose to be
Also you can display the base 10 values, the binary isn't really good to read the variable changing.
Did you write your code in stages?
If so you should have code that JUST reads and displays pH.
If not, then please do so and show us that you get valid readings.
Then write your code that looks and acts on those readings.
FOR THE MOMENT forget about ThingSpeak, WiFi, and LCD, use the serial monitor.
Lets establish that you have correctly functioning pH device and readings.
Thanks.. Tom..
![]()
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.