KEMBAR78
PH Sensor | PDF | Computer Engineering | Electronic Engineering
0% found this document useful (0 votes)
68 views6 pages

PH Sensor

The document contains code for an Arduino project that measures water quality parameters like pH and PPM. It initializes an LCD display and variables. It takes pH and PPM readings, displays them on the LCD, and sends an SMS alert if PPM is above 300. Key functions include GetEC() to measure conductivity, PrintReadings() to display readings, and trackingsp() to send SMS alerts.

Uploaded by

Harshal Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views6 pages

PH Sensor

The document contains code for an Arduino project that measures water quality parameters like pH and PPM. It initializes an LCD display and variables. It takes pH and PPM readings, displays them on the LCD, and sends an SMS alert if PPM is above 300. Key functions include GetEC() to measure conductivity, PrintReadings() to display readings, and trackingsp() to send SMS alerts.

Uploaded by

Harshal Patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

#include<LiquidCrystal.

h>
#include <SoftwareSerial.h>

LiquidCrystal lcd(6, 7, 8, 9, 10, 11);

int R1= 1000;


int Ra=25; //Resistance of powering Pins
int ECPin= A1;
int ECGround=A2;
int ECPower =A3;

#define vehisw 12

boolean sms_flag=1;

float PPMconversion=0.7;

float TemperatureCoef = 0.019; //this changes depending on what chemical we are


measuring

float K=2.88;

float Temperature=10;
float EC=0;
float EC25 =0;
int ppm =0;

float raw= 0;
float Vin= 5;
float Vdrop= 0;
float Rc= 0;
float buffer=0;

const int analogInPin = A0;


int sensorValue = 0;
unsigned long int avgValue;
float b;
int buf[10],temp;

void setup()
{
Serial.begin(9600);

pinMode(vehisw, OUTPUT);

pinMode(ECPin,INPUT);
pinMode(ECPower,OUTPUT);//Setting pin for sourcing current
pinMode(ECGround,OUTPUT);//setting pin for sinking current
digitalWrite(vehisw, LOW);
digitalWrite(ECGround,LOW);//We can leave the ground connected permanantly

delay(100);// gives sensor time to settle

delay(100);

R1=(R1+Ra);// Taking into acount Powering Pin Resitance


lcd.begin(16, 2);
lcd.clear();

lcd.print("Arduino Based ..");


lcd.setCursor(0,1);
lcd.print("Water Purificatio");
delay(2000);
lcd.clear();
lcd.print(" RCPIT Shirpur..");

lcd.setCursor(0,1);
lcd.print("Please Wait.....");
delay(2000);

lcd.clear();
lcd.print("PH Value :");
lcd.setCursor(0,1);
lcd.print("PPM Valu :");

//gsm_init();

void loop()

for(int i=0;i<10;i++)
{
buf[i]=analogRead(analogInPin);
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 pHVol=(float)avgValue*5.0/1024/6;
float phValue = -5.70 * pHVol + 21.34;

lcd.setCursor(12,0);
lcd.print(phValue);
delay(4000);

GetEC();
PrintReadings();
delay(5000);

digitalWrite(vehisw, HIGH);
lcd.clear();
lcd.print("PH Value :");
lcd.setCursor(0,1);
lcd.print("PPM Valu :");
}

void GetEC()
{

digitalWrite(ECPower,HIGH);
raw= analogRead(ECPin);
raw= analogRead(ECPin);
digitalWrite(ECPower,LOW);

Vdrop= (Vin*raw)/1024.0;
Rc=(Vdrop*R1)/(Vin-Vdrop);
Rc=Rc-Ra; //acounting for Digital Pin Resitance
EC = 1000/(Rc*K);

EC25 = EC/ (1+ TemperatureCoef*(20-25.0));


ppm=(EC25)*(PPMconversion*1000);

void PrintReadings()
{

lcd.setCursor(12,1);
lcd.print(ppm);

delay(4000);

if (ppm >= 300)


{

lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Water Quality ");
lcd.setCursor(0,1);
lcd.print("is Not Good");
delay(3000);
if (sms_flag == 1)
{

trackingsp();
delay(1000);

};

void gsm_init()
{
lcd.clear();
lcd.print("Finding Module..");
boolean at_flag=1;
while(at_flag)
{
Serial.println("AT");
while(Serial.available()>0)
{
if(Serial.find("OK"))
at_flag=0;
}

delay(1000);
}

lcd.clear();
lcd.print("Module Connected..");
delay(1000);
lcd.clear();
lcd.print("Disabling ECHO");
boolean echo_flag=1;
while(echo_flag)
{
Serial.println("ATE0");
while(Serial.available()>0)
{
if(Serial.find("OK"))
echo_flag=0;
}
delay(1000);
}

lcd.clear();
lcd.print("Echo OFF");
delay(1000);
lcd.clear();
lcd.print("Finding Network..");
boolean net_flag=1;
while(net_flag)
{
Serial.println("AT+CPIN?");
while(Serial.available()>0)
{
if(Serial.find("+CPIN: READY"))
net_flag=0;
}
delay(1000);
}
lcd.clear();
lcd.print("Network Found..");
delay(1000);
lcd.clear();
}

void init_sms()
{
Serial.println("AT+CMGF=1");
delay(400);
Serial.println("AT+CMGS=\"+918007480377\""); // use your 10 digit cell no. here
delay(400);
}

void send_data(String message)


{
Serial.println(message);
delay(200);
}

void send_sms()
{
Serial.write(26);
}

void lcd_status()
{
lcd.clear();
lcd.print("Message Sent");
delay(2000);
lcd.clear();
lcd.print("System Ready");
return;
}

void trackingsp()
{
init_sms();
send_data("Filter Water Quality ");
send_data("IS not good");
send_data("Please take some action soon..\nThankyou");
send_sms();
delay(2000);
lcd_status();
sms_flag = 0;
}

You might also like