Why my LiquidCrystal isn't working? - Plant water pump and soil moisture sensor

Hi, can someone please help, my code say

exit status 1

Compilation error: 'LiquidCrystal_I2C' does not name a type; did you mean 'LiquidCrystal_h'?

I have changed the name but its still keeping error?


#define BLYNK_TEMPLATE_ID "TMPL5LILNsdQ1"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"

//Include the library files
#include <LiquidCrystal.h> // Include the LiquidCrystal I2C library for LCD display
#define BLYNK_PRINT Serial // Define BLYNK_PRINT to enable serial prints for debugging
#include <ESP8266WiFi.h> // Include the ESP8266WiFi library for WiFi connectivity
#include <BlynkSimpleEsp8266.h> // Include the Blynk library for ESP8266

//Initialize the LCD display
LiquidCrystal_I2C lcd(0x27,  16, 2); // Create an LCD object with I2C address 0x27, 16 columns, and 2 rows
char auth[] = "lD_z6zC80ebJ3jSnnPoKUmJEcVDNdiRL"; // Enter your Auth token for Blynk
char ssid[] = "GiGi"; // Enter your WIFI name
char pass[] = "gigibabi"; // Enter your WIFI password

BlynkTimer timer; // Create a BlynkTimer object
bool Relay = 0; // Initialize a boolean variable to keep track of the relay state

//Define component pins
#define sensor A0 // Define the analog pin for the soil moisture sensor
#define waterPump D3 // Define the digital pin for the water pump

void setup() {
  Serial.begin(9600); // Start the serial communication at 9600 baud rate
  pinMode(waterPump, OUTPUT); // Set the water pump pin as output
  digitalWrite(waterPump, HIGH); // Turn off the water pump initially
  lcd.init(); // Initialize the LCD
  lcd.backlight(); // Turn on the LCD backlight

  Blynk.begin(auth, ssid, pass, "blynk.cloud", 80); // Connect to Blynk server using auth token, WiFi credentials, and server address

  lcd.setCursor(1, 0); // Set the cursor to column 1, row 0
  lcd.print("System Loading"); // Print "System Loading" on the LCD
  for (int a = 0; a <= 15; a++) { // Loop to show loading progress
    lcd.setCursor(a, 1); // Set the cursor to the current column, row 1
    lcd.print("."); // Print a dot to show progress
    delay(500); // Wait for 500 milliseconds
  }
  lcd.clear(); // Clear the LCD*/

  //Call the function
  timer.setInterval(100L, soilMoistureSensor); // Set a timer to call soilMoistureSensor function every 100 milliseconds
}

//Get the button value
BLYNK_WRITE(V1) {
  Relay = param.asInt(); // Get the value from the Blynk button widget

  if (Relay == 1) { // If the button is pressed
    digitalWrite(waterPump, LOW); // Turn on the water pump
    lcd.setCursor(0, 1); // Set the cursor to column 0, row 1
    lcd.print("Motor is ON "); // Print "Motor is ON" on the LCD
  } else { // If the button is not pressed
    digitalWrite(waterPump, HIGH); // Turn off the water pump
    lcd.setCursor(0, 1); // Set the cursor to column 0, row 1
    lcd.print("Motor is OFF"); // Print "Motor is OFF" on the LCD
  }
}

//Get the soil moisture values
void soilMoistureSensor() {
  int value = analogRead(sensor); // Read the analog value from the soil moisture sensor
  value = map(value, 0, 1024, 0, 100); // Map the sensor value from 0-1024 to 0-100
  value = (value - 100) * -1; // Invert the value to get the correct percentage

  Blynk.virtualWrite(V0, value); // Send the moisture value to the Blynk app
  lcd.setCursor(0, 0); // Set the cursor to column 0, row 0
  lcd.print("Moisture :"); // Print "Moisture :" on the LCD
  lcd.print(value); // Print the moisture value on the LCD
  lcd.print(" "); // Print a space for clearing any remaining characters
}

void loop() {
  Blynk.run(); // Run the Blynk library
  timer.run(); // Run the Blynk timer
}

Welcome to the forum

You are #including a library named LiquidCrystal but are trying to create an object of a library named LiquidCrystal_I2C

Is your LCD connected to the Arduino using the I2C interface ? If so, then use the LiquidCrystal_I2C library, assuming that you have installed it. Looking at the library examples should give you some ideas

1 Like

amazing, thank you so much! Its work!!!!!!!!!!!!!!!!! :star_struck:

That's good

I assume that you do have an I2C LCD

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