#include
LiquidCrystal lcd(3, 2, 7, 6, 5, 4);
#define SensorPin 0 //pH meter Analog output to Arduino Analog Input 0
#define Offset 0.00 //deviation compensate
unsigned long int avgValue; //Store the average value of the sensor feedback
int S1;
int S2;
int S3;
int S4;
int S5;
int S6;
void setup()
{
pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);
pinMode(13, INPUT);
Serial.begin(9600);
Serial.prinOUTPUTtln("Ready"); //Test the serial monitor
}
void loop()
{
int buf[10]; //buffer for read analog
for (int i = 0; i < 10; i++) //Get 10 sample value from the sensor for smooth the value
{
buf = analogRead(SensorPin);
delay(10);
}
for (int i = 0; i < 9; i++) //sort the analog from small to large
{
for (int j = i + 1; j < 10; j++)
{
if (buf > buf[j])
{
int temp = buf;
buf = buf[j];
buf[j] = temp;
}
}
}
avgValue = 0;
for (int i = 2; i < 8; i++) //take the average value of 6 center sample
avgValue += buf;
float phValue = (float)avgValue * 5.0 / 1024 / 6; //convert the analog into millivolt
phValue = 3.5 * phValue + Offset; //convert the millivolt into pH value
Serial.print(" pH:");
Serial.print(phValue, 2);
Serial.println(" ");
digitalWrite(13, HIGH);
delay(800);
digitalWrite(13, LOW);
lcd.setCursor(0, 1);
lcd.print("PH:");
lcd.print(phValue, 2);
if(digitalRead(9) == LOW)
{
lcd.setCursor(10, 1);
lcd.print("text");
}
else
{
lcd.setCursor(10, 1);
lcd.print("meian");
}
}