// LCD1602 to Arduino Uno connection example
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
void setup()
{
Serial.begin(115200);
pinMode(A0, INPUT);
lcd.begin(16, 2);
lcd.print("CAMPUS IGUALADA");
}
void loop()
{
float lectura_sensor = analogRead(A0);
float voltatge_sensor;
float m;
float b;
float pH;
voltatge_sensor = (lectura_sensor / 1023)*5;
if ((voltatge_sensor < 1.2) || (voltatge_sensor > 2.8))
{
Serial.println("Voltatge sensor --> ERROR");
lcd.setCursor(0, 1);
lcd.print("ERROR----");
}
else
{
Serial.print("Voltatge sensor -->");
Serial.println(voltatge_sensor);
m = (14.0-0.0) / (2.8-1.2);
b = (0.0 - m*1.2);
pH = m*voltatge_sensor+b;
Serial.print("pH -->");
Serial.println(pH);
delay(100);
lcd.setCursor(0,1);
lcd.print("pH:");
lcd.print(pH);
}
}