Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
- int pH = A0;
- 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) ;
- lcd.begin () ;
- lcd.backlight () ;
- lcd. setCursor (0, 0) ;
- lcd. print ("Welcome") ;
- delay (1000) ;
- lcd.clear () ;
- }
- 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;
- lcd. setCursor (0,0) ;
- lcd. print ("pH Formula : ");
- lcd. print (ph (pHVol) , 2) ;
- lcd. setCursor (0,1) ;
- lcd. print ("pH Cal : ") ;
- lcd. print (phValue) ;
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement