This project is based on detecting the pH level of a liquid on the scale of 0-14 using a simple arduino circuit. The power of Hydrogen (pH) is an important parameter when we need to find whether a solution is acidic or basic or when we want to form a new solution with certain pH value.
#define SensorPin 1
unsigned long int avgValue;
float b;
int buf[10],temp;
void setup()
{
pinMode(13,OUTPUT);
Serial.begin(9600);
}
void loop()
{
for(int i=0;i<10;i++)
{
buf[i]=analogRead(SensorPin);
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 phValue=(float)avgValue*5.0/1024/6;
phValue=3.5*phValue;
Serial.print(" pH:");
Serial.print(phValue,2);
Serial.println(" ");
digitalWrite(13, HIGH);
delay(800);
digitalWrite(13, LOW);
}