Trying to make an irrigation system with arduino (code problem)

#include <LiquidCrystal.h>
#include <elapsedMillis.h>
#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 16, 2); 
const byte ROWS = 4; 
const byte COLS = 4; 
char keys[ROWS][COLS] = {
 {'1','2','3','A'},
 {'4','5','6','B'},
 {'7','8','9','C'},
 {'*','0','#','D'}
};
byte rowPins[ROWS] = {11, 10, 9, 8}; 
byte colPins[COLS] = {7, 6, 5, 4}; 
const int humedadPin = A0;
int relePin = 12;
int luzPin = A1;
elapsedMillis timeElapsed;
int daysElapsed;
int hourElapsed;
int segElapsed;
int minElapsed;
boolean previousStatusOn = false;
int limiteHumedad = 500;
int limiteLuz = 100;
char key = '9';
int humedad;
int luz;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins,
ROWS, COLS );
void setup(){
 lcd.begin(16,2);
 lcd.init();
 lcd.backlight();
 Serial.begin(9600);
  pinMode(relePin, OUTPUT);
}
void loop(){
 humedad = analogRead(humedadPin);
 luz = analogRead(luzPin);
 key = keypad.getKey();
 int key_1 = key - 48;

 if (key == 'A'){
 menuHumedad();
 }
 if (key == 'B'){
 menuLuz();
 }
 if (key == 'C'){
 printMenu();
 }
 if (key == 'D' && previousStatusOn == true){
 printEncendido();
 }
 if (key == 'D' && previousStatusOn == false){
 printApagado();
 }

 printEnLoop();
  Serial.print("timeElapsed: ");
 Serial.print(timeElapsed);
 if(humedad > limiteHumedad && luz > limiteLuz &&
previousStatusOn == false)
 {
 empezarRegar();
 }
 else if((humedad < limiteHumedad || luz < limiteLuz) &&
previousStatusOn == true){
 pararRegar();
 }
}
void empezarRegar() {
 digitalWrite(relePin, HIGH);
 calcTimeElapsed();
 printTimeElapsedLastRiego();
 printEncendido();
 timeElapsed = 0;
 previousStatusOn = true;
}
void pararRegar() {
 digitalWrite(relePin, LOW);
 calcTimeElapsed();
 printTimeElapsedRegando();
 printApagado();
  previousStatusOn = false;
 timeElapsed = 0;
}
void printMenu() {
 lcd.setCursor(0, 0);
 lcd.print("Elige humedad: A");
 lcd.setCursor(0, 1);
 lcd.print("Elige luz: B ");
 lcd.print(key);
}
void menuHumedad() {
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("Elige humedad0-9");
 lcd.setCursor(0, 1);
 lcd.print("Seleccionado: ");
 key = keypad.waitForKey();
 limiteHumedad = 1000 - (80 * (key - 48));
 lcd.print(key);
 delay(1000);
 if(previousStatusOn) {
   printEncendido();
 }
 else{
 printApagado();
 }
}
void menuLuz() {
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("Elige luz:0-9");
 lcd.setCursor(0, 1);
 lcd.print("Seleccionado: ");
 key = keypad.waitForKey();
 limiteLuz = 600 - (66 * (key - 48));
 lcd.print(key);
 delay(1000);
 if(previousStatusOn) {
 printEncendido();
 }
 else{
 printApagado();
 }
}
void printEncendido(){
 lcd.setCursor(0, 0);
 lcd.print("Riego Activo ");
 lcd.setCursor(0, 1);
 lcd.print("Menu: C ");
 Serial.print("Encendido");
 Serial.println(" ");
 Serial.print("humedad: ");
 Serial.print(humedad);
 Serial.print("limiteHumedad: ");
 Serial.print(limiteHumedad);
 Serial.println(" ");
}
void printApagado(){
 lcd.setCursor(0, 0);
 lcd.print("Riego Apagado ");
 lcd.setCursor(0, 1);
 lcd.print("Menu: C ");
}o
void printEnLoop(){
 Serial.print("humedad: ");
 Serial.print(humedad);
 Serial.print(" limiteHumedad: ");
 Serial.print(limiteHumedad);
 Serial.print(" limiteLuz: ");
 Serial.print(limiteLuz);
 Serial.print(" luz: ");
 Serial.print(luz);
 Serial.println(" ");
}
void calcTimeElapsed(){
 long timeRemaining = timeElapsed;
 daysElapsed = timeRemaining/86400000;
 timeRemaining = timeRemaining - daysElapsed*86400000;
 hourElapsed = timeRemaining/3600000;
 timeRemaining = timeRemaining - hourElapsed*3600000;
 minElapsed = timeRemaining/60000;
 timeRemaining = timeRemaining - minElapsed*60000;
 segElapsed = timeRemaining/1000;
}
void printTimeElapsedRegando() {
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("Tiempo riego: ");
 lcd.setCursor(0, 1);
 lcd.print(daysElapsed);
 lcd.print("d");
 lcd.print(hourElapsed);
 lcd.print("h");
 lcd.print(minElapsed);
 lcd.print("\'");
 lcd.print(segElapsed);
 lcd.print("\"");
 delay(3000);
}
void printTimeElapsedLastRiego() {
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("Ultimo riego: ");
 lcd.setCursor(0, 1);
 lcd.print(daysElapsed);
 lcd.print("d");
 
 }
 lcd.print(hourElapsed);
 lcd.print("h");
 lcd.print(minElapsed);
 lcd.print("\'");
 lcd.print(segElapsed + 3);
 lcd.print("\"");
}

I’m working on this code for an irrigation system with a an arduino Mega everything looks good but when I try to compile it there’s an error that says “lcd” does not name a type. I know that there is already many post about this error and I have read quite a lot but I’ve yet not been able to spot the reason for the error.
I’m using an 16X2 lcd with the LiquidCrystalI2c library. I tried to change it to the normal LiquidCrystal library(using a different Lcd) with the same error.
If there is someone that can help me I will be very thankful(sorry if my english is bad It’s not my main language)