#include "Wire.h" // Library for I2C communication
#include "LiquidCrystal_I2C.h" // Library for LCD
// Wiring: SDA pin is connected to A4 and SCL pin to A5.
// Connect to LCD via I2C, default address 0x27 (A0-A2 not jumpered)
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); // Change to (0x27,20,4) for 20x4 LCD.
void setup() {
// Initiate the LCD:
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Moisture Sensor %");
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(A6, INPUT);
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
float value0 = analogRead(A0);
float Moisture0 = (0.00005*(value0*value0))-(0.0033*value0)+0.2162;
lcd.print("s1)");
lcd.print(Moisture0*2.81);
lcd.print(" ");
lcd.setCursor(10, 1);
float value3 = analogRead(A3);
float Moisture3 = (0.00005*(value3*value3))-(0.0033*value3)+0.2162;
lcd.print("s4)");
lcd.print(Moisture3*2.81);
lcd.print(" ");
lcd.setCursor(0, 2);
float value1 = analogRead(A1);
float Moisture1 = (0.00005*(value1*value1))-(0.0033*value1)+0.2162;
lcd.print("s2)");
lcd.print(Moisture1*2.81);
lcd.print(" ");
lcd.setCursor(10, 2);
float value4 = analogRead(A6);
float Moisture4 = (0.00005*(value4*value4))-(0.0033*value4)+0.2162;
lcd.print("s5)");
lcd.print(Moisture4*2.81);
lcd.print(" ");
lcd.setCursor(0, 3);
float value2 = analogRead(A2);
float Moisture2 = (0.00005*(value2*value2))-(0.0033*value2)+0.2162;
lcd.print("s3)");
lcd.print(Moisture2*2.81);
lcd.print(" ");
/*
// Print 'Hello World!' on the first line of the LCD:
lcd.setCursor(2, 0); // Set the cursor on the third column and first row.
lcd.print("Hello World!"); // Print the string "Hello World!"
lcd.setCursor(2, 1); //Set the cursor on the third column and the second row (counting starts at 0!).
lcd.print("LCD tutorial"); */
}
/*
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(20,4);
lcd.setCursor(0, 0);
lcd.print("Moisture Sensor %");
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(A4, INPUT);
}
void loop()
{
int contPos;
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
float value0 = analogRead(A0);
float Moisture0 = (0.00005*(value0*value0))-(0.0033*value0)+0.2162;
lcd.print("s1)");
lcd.print(Moisture0*2.81);
lcd.print(" ");
lcd.setCursor(10, 1);
float value3 = analogRead(A3);
float Moisture3 = (0.00005*(value3*value3))-(0.0033*value3)+0.2162;
lcd.print("s4)");
lcd.print(Moisture3*2.81);
lcd.print(" ");
lcd.setCursor(0, 2);
float value1 = analogRead(A1);
float Moisture1 = (0.00005*(value1*value1))-(0.0033*value1)+0.2162;
lcd.print("s2)");
lcd.print(Moisture1*2.81);
lcd.print(" ");
lcd.setCursor(10, 2);
float value4 = analogRead(A4);
float Moisture4 = (0.00005*(value4*value4))-(0.0033*value4)+0.2162;
lcd.print("s5)");
lcd.print(Moisture4*2.81);
lcd.print(" ");
lcd.setCursor(0, 3);
float value2 = analogRead(A2);
float Moisture2 = (0.00005*(value2*value2))-(0.0033*value2)+0.2162;
lcd.print("s3)");
lcd.print(Moisture2*2.81);
lcd.print(" ");
}
*/