Hi, i like to calculate the alkalinity from ph value i get od my PH Probe.
Here is the formula i found that works in a Spredsheet.
1.7177*LOG(phValue)+4.1333
I do not know how to calculate the LOG, Can you Help?
Thanks
Hi, i like to calculate the alkalinity from ph value i get od my PH Probe.
Here is the formula i found that works in a Spredsheet.
1.7177*LOG(phValue)+4.1333
I do not know how to calculate the LOG, Can you Help?
Thanks
I do not know how to calculate the LOG, Can you Help?
log() is standard function.
try log10.
Thanks it works now with log10 in lowercase
OK for a PH of 8 it give me 5.69, i do not understand, i was experction a value more of 80??
Alkalinity in water is quite complex. You might find this slide show helpful.
This paper seems to be definitive.
Thanks , figured that my formula is wrong, i will get back as soon as solved it
Even if you are only interested in carbonate/bicarbonate/carbonic acid, there is no simple relation between pH and base concentration, because multiple bases are being titrated.
However, around pH 8, you might expect the curve of pH versus added base to look something like this:
I want to calculate the total alkalinity (For my Spa)
I have 3 probs : Temperature, ORP and PH
I found this formula 10 to the power ((PH- 4.1333)/1.7177))
i need to transform this formula to work in my Arduino Code.
Will it work or i have to buy a Prob just for that?
/*
* OPR and PH Code
* Base on code from https://www.dfrobot.com/wiki/index.php/Analog_ORP_Meter(SKU:SEN0165) and https://www.dfrobot.com/wiki/index.php/Analog_pH_Meter_Pro_SKU:SEN0169
*
* By Pierre Mccarragher
* My Thing: To connect with Arduino we will need an analog PH prod input (A0), ORP prob to A5, two power (5V) and two GND
* The code consists of taking 40 samples of the analogue input A0,A5,
* and calculating the avrage and converting this value to Usable value
* and send it to the serial port to see it in the serial monitor.
#
# Version: 1.1
# Date : 2018.08.13
#
*/
#include <math.h> // (no semicolon)
#define VOLTAGE 5.00 //system voltage
#define OFFSET -480.29 //zero drift voltage
#define LED 13 //operating instructions
double orpValue;
float phValue;
float phVol;
#define ArrayLenth 40 //times of collection
#define orpPin 5 //orp meter output,connect to Arduino controller ADC pin
#define phPin 0 //PH meter output,connect to Arduino controller ADC pin
#define phOffset 0.00 //deviation compensate
int orpArray[ArrayLenth];
int orpArrayIndex=0;
int phArray[ArrayLenth];
int phArrayIndex=0;
int temp;
unsigned long int avgValuePH;
double avergearray(int* arr, int number){
int i;
int max,min;
double avg;
long amount=0;
if(number<=0){
printf("Error number for the array to avraging!/n");
return 0;
}
if(number<5){ //less than 5, calculated directly statistics
for(i=0;i<number;i++){
amount+=arr[i];
}
avg = amount/number;
return avg;
}else{
if(arr[0]<arr[1]){
min = arr[0];max=arr[1];
}
else{
min=arr[1];max=arr[0];
}
for(i=2;i<number;i++){
if(arr[i]<min){
amount+=min; //arr<min
min=arr[i];
}else {
if(arr[i]>max){
amount+=max; //arr>max
max=arr[i];
}else{
amount+=arr[i]; //min<=arr<=max
}
}//if
}//for
avg = (double)amount/(number-2);
}//if
return avg;
}
void setup(void) {
Serial.begin(9600);
pinMode(LED,OUTPUT);
}
void loop(void) {
static unsigned long orpTimer=millis(); //analog sampling interval
static unsigned long printTime=millis();
if(millis() >= orpTimer)
{
orpTimer=millis()+20;
orpArray[orpArrayIndex++]=analogRead(orpPin); //read an analog value every 20ms
phArray[phArrayIndex++]=analogRead(phPin); //read an analog value every 20ms
if (orpArrayIndex==ArrayLenth) {
orpArrayIndex=0;
phArrayIndex=0;
}
orpValue=((30*(double)VOLTAGE*1000)-(75*avergearray(orpArray, ArrayLenth)*VOLTAGE*1000/1024))/75-OFFSET;
phVol=avergearray(phArray, ArrayLenth) * 5.0 / 1024;
phValue= 3.5 * phVol + phOffset;
//convert the analog value to orp according the circuit
}
if(millis() >= printTime) //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
{
printTime=millis()+8000;
Serial.print("ORP: ");
Serial.print(orpValue);
Serial.println("mV");
Serial.print("PH: ");
Serial.println(phValue);
Serial.print("Total Alkalinity: ");
//Serial.println( 1.7177*log10(phValue)+4.1333);
digitalWrite(LED,1-digitalRead(LED));
}
}
If you don't know what chemical compounds are in the spa water, the calculation is completely meaningless.
OK well her is the formula
Serial.println(10^(((phValue- 4.1333)/1.7177) ));
//10 to the power of (((phValue- 4.1333)/1.7177) ))
and i get this error invalid operands of types 'int' and 'double' to binary 'operator^'
Can Someone help me code properly this formula?
For the validaty of the formula, I will test it out with a few referance solution and see if the values a good or not
Thanks
Pierre
Here is my final formula
Serial.println(pow(10,(((phValue- 4.1333)/1.7177) )));
so for PH: 8.05
i get Total Alkalinity: 190.46
I have no idear if this is any good but sure was fun makeing it!!
Thanks everyone for all the help!
Pierre
Below is the final version. No i am off to get some refinance solution for testing.
/*
* OPR and PH Code
* Base on code from https://www.dfrobot.com/wiki/index.php/Analog_ORP_Meter(SKU:SEN0165) and https://www.dfrobot.com/wiki/index.php/Analog_pH_Meter_Pro_SKU:SEN0169
*
* By Pierre Mccarragher
* My Thing: To connect with Arduino we will need an analog PH prod input (A0), ORP prob to A5, two power (5V) and two GND
* The code consists of taking 40 samples of the analogue input A0,A5,
* and calculating the avrage and converting this value to Usable value
* and send it to the serial port to see it in the serial monitor.
#
# Version: 1.1
# Date : 2018.08.13
#
*/
#include <math.h> // (no semicolon)
#define VOLTAGE 5.00 //system voltage
#define OFFSET 0 //zero drift voltage ORP offset for calibration
#define LED 13 //operating instructions
double orpValue;
float phValue;
float phVol;
#define ArrayLenth 40 //times of collection
#define orpPin 5 //orp meter output,connect to Arduino controller ADC pin
#define phPin 0 //PH meter output,connect to Arduino controller ADC pin
#define phOffset 0.00 //ph offset for calibration
#define aklOffset 0.00 //alkalinity offset for calibration
int orpArray[ArrayLenth];
int orpArrayIndex=0;
int phArray[ArrayLenth];
int phArrayIndex=0;
int temp;
unsigned long int avgValuePH;
double avergearray(int* arr, int number){
int i;
int max,min;
double avg;
long amount=0;
if(number<=0){
printf("Error number for the array to avraging!/n");
return 0;
}
if(number<5){ //less than 5, calculated directly statistics
for(i=0;i<number;i++){
amount+=arr[i];
}
avg = amount/number;
return avg;
}else{
if(arr[0]<arr[1]){
min = arr[0];max=arr[1];
}
else{
min=arr[1];max=arr[0];
}
for(i=2;i<number;i++){
if(arr[i]<min){
amount+=min; //arr<min
min=arr[i];
}else {
if(arr[i]>max){
amount+=max; //arr>max
max=arr[i];
}else{
amount+=arr[i]; //min<=arr<=max
}
}//if
}//for
avg = (double)amount/(number-2);
}//if
return avg;
}
void setup(void) {
Serial.begin(9600);
pinMode(LED,OUTPUT);
}
void loop(void) {
static unsigned long orpTimer=millis(); //analog sampling interval
static unsigned long printTime=millis();
if(millis() >= orpTimer)
{
orpTimer=millis()+20;
orpArray[orpArrayIndex++]=analogRead(orpPin); //read an analog value every 20ms
phArray[phArrayIndex++]=analogRead(phPin); //read an analog value every 20ms
if (orpArrayIndex==ArrayLenth) {
orpArrayIndex=0;
phArrayIndex=0;
}
orpValue=((30*(double)VOLTAGE*1000)-(75*avergearray(orpArray, ArrayLenth)*VOLTAGE*1000/1024))/75-OFFSET;
phVol=avergearray(phArray, ArrayLenth) * 5.0 / 1024;
phValue= 3.5 * phVol + phOffset;
//convert the analog value to orp according the circuit
}
if(millis() >= printTime) //Every 800 milliseconds, print a numerical, convert the state of the LED indicator
{
printTime=millis()+8000;
Serial.print("ORP: ");
Serial.print(orpValue);
Serial.println("mV");
Serial.print("PH: ");
Serial.println(phValue);
Serial.print("Total Alkalinity: ");
Serial.println(pow(10,(((phValue- 4.1333)/1.7177) ))-aklOffset);
digitalWrite(LED,1-digitalRead(LED));
}
}
In this particular case, having fun is the only thing that matters.