Hi, I'm new to this and I really need help.
For my project, I'm doing a monitoring system in a hydroponics setup. I will be using three sensors which are temperature, dissolved oxygen, and pH sensors. The problem that I have been going through is the pH value has a high fluctuation and the value of the pH isn't correct when it is submerged into a 10-liter container filled with water. However, when it is submerged into a pH 7 and pH 4 (buffer solution) it's correct.
The weird thing is that the readings stabilize to within +/-0.2 when I put the probe in a beaker fill with the buffer solution. When the probe is in the container (10 liters of water) itself, the readings aren't in the range of the tap water pH.
I'm using Arduino IDE software to code for the pH sensor. The values will be displayed in Grafana. I'm using a pH sensor from Inesa Scientific Instrument (E-201-C). It has a potentiometer. I don't know if its the code problem
The code that I'm using is
#include <Servo.h>
Servo acid_solution;
Servo alkaline_solution;
#define acid_pump 9
#define alkaline_pump 10
float calibration_value = 11.15;
int phval = 0;
unsigned long int avgval;
int buffer_arr[50], temp;
float value1,
value2,
value3,
value4,
value5,
main_value;
float ph_value;
void setup()
{
Serial.begin(9600);
pinMode(A0, INPUT);
acid_solution.attach(acid_pump);
alkaline_solution.attach(alkaline_pump);
}
void loop() {
Serial.println(ph_value);
getting_value();
value1 = ph_value;
delay(300);
getting_value();
value2 = ph_value;
delay(300);
getting_value();
value3 = ph_value;
delay(300);
getting_value();
value4 = ph_value;
delay(300);
getting_value();
value5 = ph_value;
main_value = (value1 + value2 + value3 + value4 + value5) / 5;
if (main_value > 6.5)
{
acid_solution.write(0); //Clockwise maximum speed rotation
}
else
{
acid_solution.write(90);
}
if (main_value < 5.5)
{
alkaline_solution.write(0);
}
else
{
alkaline_solution.write(90);
}
}
void getting_value()
{
for (int i = 0; i < 50; i++)
{
buffer_arr[i] = analogRead(A0);
delay(30);
}
for (int i = 0; i < 49; i++)
{
for (int j = i + 1; j < 50; j++)
{
if (buffer_arr[i] > buffer_arr[j])
{
temp = buffer_arr[i];
buffer_arr[i] = buffer_arr[j];
buffer_arr[j] = temp;
}
}
}
avgval = 0;
for (int i = 5; i < 45; i++)
avgval += buffer_arr[i];
float volt = (float)avgval * 5.0 / 1024 / 40;
ph_value = -5.70 * volt + calibration_value;
}