LCD doesn't change what it displays

I have a program for a soil moisture sensor to find a plant's moisture level and when I put it into the plant, the LCD still shows the screen as if it had 0 water, even when I water the plant as the monitor is in the plant. Here is my code:

// C++ code
//
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd_1(0x27, 16, 2); // Set the LCD address and dimensions (16x2)

int moisture = 0;
void setup()
{
  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  Serial.begin(9600);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  lcd_1.init(); // Initialize the LCD
}

void loop()
{
  // Apply power to the soil moisture sensor
  digitalWrite(A0, HIGH);
  delay(10); // Wait for 10 millisecond(s)
  moisture = digitalRead(A1);
  // Turn off the sensor to reduce metal corrosion
  // over time
  digitalWrite(A0, LOW);
  Serial.println(moisture);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  digitalWrite(12, LOW);
  if (moisture < 200) {
    digitalWrite(12, HIGH);
  } else {
    if (moisture < 400) {
      digitalWrite(11, HIGH);
    } else {
      if (moisture < 600) {
        digitalWrite(10, HIGH);
      } else {
        if (moisture < 800) {
          digitalWrite(9, HIGH);
        } else {
          digitalWrite(8, HIGH);
        }
      }
    }
  }
  delay(100); // Wait for 100 millisecond(s)
  if (moisture <= 720 && (moisture >= 170 && moisture > 170)) {
    lcd_1.print("I am happy!");
    delay(3000); // Wait for 3000 millisecond(s)
    lcd_1.clear();
    lcd_1.print("Thank you!");
    delay(3000); // Wait for 3000 millisecond(s)
    lcd_1.clear();
  } else {
    if (moisture >= 720) {
      lcd_1.print("I am sad. ");
      delay(3000); // Wait for 3000 millisecond(s)
      lcd_1.clear();
      lcd_1.print("Too much water!");
      delay(3000); // Wait for 3000 millisecond(s)
      lcd_1.clear();
    } else {
      if (moisture <= 170) {
        lcd_1.print("I am sad. ");
        delay(3000); // Wait for 3000 millisecond(s)
        lcd_1.clear();
        lcd_1.print("I need water!");
        delay(3000); // Wait for 3000 millisecond(s)
        lcd_1.clear();
      } else {
      }
    }
  }
}

Thanks

moisture = digitalRead(A1);
try
moisture = analogRead(A1);

That will only give you a 0 (LOW) or a 1 (HIGH); maybe you meant to use analogread()? You also have set that pin as output which brings the question which moisture sensor you're using.

Note:
No experience with moisture sensors.

Post an annotated schematic showing exactly how you have wired this. From the above I do not have a clue and how things are connected is very important for the code. Hint: I do not do frizzies.

Screenshot 2024-01-22 130506

in my irl version i have a dif moisture sensor where it says A0 and D0 instead of a signal

The "diagram" is fuzzy and not readable. You have lines going to nothing, same for resistor. Your results are correct per your diagram. Post an annotated schematic, the same as is useless in solving your problem. I could take a guess at which arduino but I do not want to burn that time and spend time also guessing on what display.

You were asked for a schematic, not a Fritzing type wiring diagram.
They're utterly useless.
One of the key reasons you indicate yourself already: the parts you show in the image are NOT the parts you actually use, so it's not a correct representation of what you're doing.
Without a true representation of the parts you have, wired the way you have, connected as you have it, you're wasting our time.
And your own, of course. But that part I care less about.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.