Advertisement
andretafta

Project Kreanova Banun

Jun 9th, 2024
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <LiquidCrystal_I2C.h>
  2.  
  3. LiquidCrystal_I2C lcd(0x27, 2, 16);
  4.  
  5. int sensorPin = A0; //A0 FOR ARDUINO SENSOR TURBIDITY
  6. int pH = A1; //PH Sensor
  7. int buf [10];
  8.  
  9. float ph (float voltage) {
  10.   return 7 + ((2.5 - voltage) / 0.18) ;
  11. }
  12.  
  13. void setup()
  14. {
  15.   // put your setup code here, to run once:
  16.   pinMode (pH, INPUT);
  17.  
  18.   Serial.begin (115200);
  19.   // initialize LCD
  20.   lcd.begin();
  21.   // turn on LCD backlight                      
  22.   lcd.backlight();
  23. }
  24. void loop() {
  25.    // put your main code here, to run repeatedly:
  26.   lcd. setCursor (13,1) ;
  27.   lcd.print ("      ") ;
  28.  
  29.   lcd. setCursor (13, 2) ;
  30.   lcd.print ("      ") ;
  31.  
  32.   for (int i=0; i<10;i++)
  33.   {
  34.     buf[i]=analogRead(pH) ;
  35.     delay (10) ;
  36.   }
  37.  
  38.  
  39.   float avgValue=0;
  40.   for (int i=0;i<10;i++)
  41.   avgValue+=buf [i];
  42.  
  43.  
  44.   float pHVol=(float)avgValue*5.0/1024/10;
  45.   float phValue = -5.70 * pHVol + 21.34;
  46.  
  47.   int sensorValue = analogRead(sensorPin);
  48.   Serial.println(sensorValue);
  49.  
  50.   if (sensorValue >=550) {
  51.     lcd.setCursor(0, 0);
  52.     lcd.print("Status: Jernih");
  53.     Serial.print(" its CLEAR ");
  54.   }
  55.   if ((sensorValue > 450) && (sensorValue < 550)) {
  56.     lcd.setCursor(0, 0);
  57.     lcd.print("Status: Keruh");
  58.     Serial.print(" its CLOUDY ");
  59.   }
  60.   if  (sensorValue <= 450) {
  61.     lcd.setCursor(0, 0);
  62.     lcd.print("Status: Kotor");
  63.     Serial.print(" its DIRTY ");
  64.   }
  65.  
  66.   lcd. setCursor (0,1) ;
  67.   lcd. print ("pH : ");
  68.   lcd. print (ph (pHVol) , 2) ;
  69.  
  70.   delay(100);
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement