How to use soil moisture sensor using LCD display with arduino



Materials:-



Diagram:-

Connections:-

LCD display to arduino
  • Vss = Arduino GND
  • VDD = Arduino 5V
  • V0 = Potentiometer center pin
  • RS = Digital pin  8
  • RW = Arduino GND
  • E =   Digital pin 6
  • D4 = Arduino digital pin 5
  • D5  = Arduino digital pin 4
  • D6 = Arduino digital pin 3
  • D7 = Arduino digital pin 2
  • A = Arduino  5V
  • K = Arduino GND
    Potentiometer to arduino
    •   Left pin  = Arduino GND
    •   Right pin = Arduino 5v
    • center pin = Display VO 
    Soil moisture sensor to arduino
    • Sensor VCC = Arduino 3.5V
    • Sensor GND = Arduino GND
    • Sensor AO = Arduino A0
    Downloads:-

    LCD display library(LiquidCrystal.h) = http://bit.ly/2VeF5xt


    Code :-

    #include <LiquidCrystal.h>
    LiquidCrystal lcd(8, 6, 5, 4, 3,2);

    int sensorPin = A0;
    int sensorValue = 0;
    int percentValue = 0;

    void setup() {
      Serial.begin(9600);
      lcd.begin(16, 2);
    }

    void loop() {

      sensorValue = analogRead(sensorPin);
      Serial.print("\n\nAnalog Value: ");
      Serial.print(sensorValue);
      
      percentValue = map(sensorValue, 1023, 200, 0, 100);
      Serial.print("\nPercentValue: ");
      Serial.print(percentValue);
      Serial.print("%");
      lcd.setCursor(0, 0);
      lcd.print("Soil Moisture");
      
      lcd.setCursor(0, 1);  
      lcd.print("Percent: ");
      lcd.print(percentValue);
      lcd.print("%");
      delay(1000);
      lcd.clear();
    }