Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27, 2, 16);
- int sensorPin = A0; //A0 FOR ARDUINO SENSOR TURBIDITY
- int pH = A1; //PH Sensor
- int buf [10];
- float ph (float voltage) {
- return 7 + ((2.5 - voltage) / 0.18) ;
- }
- void setup()
- {
- // put your setup code here, to run once:
- pinMode (pH, INPUT);
- Serial.begin (115200);
- // initialize LCD
- lcd.begin();
- // turn on LCD backlight
- lcd.backlight();
- }
- void loop() {
- // put your main code here, to run repeatedly:
- lcd. setCursor (13,1) ;
- lcd.print (" ") ;
- lcd. setCursor (13, 2) ;
- lcd.print (" ") ;
- for (int i=0; i<10;i++)
- {
- buf[i]=analogRead(pH) ;
- delay (10) ;
- }
- float avgValue=0;
- for (int i=0;i<10;i++)
- avgValue+=buf [i];
- float pHVol=(float)avgValue*5.0/1024/10;
- float phValue = -5.70 * pHVol + 21.34;
- int sensorValue = analogRead(sensorPin);
- Serial.println(sensorValue);
- if (sensorValue >=550) {
- lcd.setCursor(0, 0);
- lcd.print("Status: Jernih");
- Serial.print(" its CLEAR ");
- }
- if ((sensorValue > 450) && (sensorValue < 550)) {
- lcd.setCursor(0, 0);
- lcd.print("Status: Keruh");
- Serial.print(" its CLOUDY ");
- }
- if (sensorValue <= 450) {
- lcd.setCursor(0, 0);
- lcd.print("Status: Kotor");
- Serial.print(" its DIRTY ");
- }
- lcd. setCursor (0,1) ;
- lcd. print ("pH : ");
- lcd. print (ph (pHVol) , 2) ;
- delay(100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement