//Library for using LCD display with I2C #include //Setting up LCD LiquidCrystal_I2C lcd(0x27, 16, 2); int blueLED= 12; // blue diode pin D12 int redLED= 11; // red diode pin D11 int sInput= 0; // Sensor input pin A0 int value= 0; //method made for printing on lcd display void printSensor(){ lcd.clear(); lcd.setCursor(0,0); lcd.print("Soil Moisture:"); lcd.setCursor(0,1); } //this method prints value of sensor void printValue(int value){ lcd.clear(); lcd.setCursor(0,0); lcd.print("Sensor value:"); lcd.print(value); lcd.setCursor(0,1); //this part tells user if he needs to water plant or not if(value < 50) { lcd.print("Water your plant"); } else { lcd.print("Plant is good"); } } //this method changes lights on diodes, if everything is ok the blue diode will work, and if plant needs water the red diode will be on void diodeLights(int value){ if(value < 50){ digitalWrite(redLED,HIGH); digitalWrite(blueLED, LOW); lcd.print("NOT ENOUGH"); } else { digitalWrite(blueLED,HIGH); digitalWrite(redLED,LOW); lcd.print("ENOUGH"); } } void setup() { lcd.clear(); lcd.backlight(); lcd.init(); lcd.begin(16,2); Serial.begin(9600); pinMode(redLED,OUTPUT); pinMode(blueLED,OUTPUT); } void loop() { lcd.clear(); printSensor(); value= analogRead(sInput); value = constrain(value, 485, 1024); value = map(value, 485, 1024, 100, 0); //You can add this part if you want to check values on serial monitor //Serial.println("Sensor value"); //Serial.println(value); diodeLights(value); delay(2000); printValue(value); delay(3000); }