error: 'lcd' does not name a type

I am having an issue where the lcd.begin(); will not work because of the error I keep getting :frowning: any help would be appreciated!

Here is the code.

EDIT: I realized I needed to put the lcd.begin(); in the setup.

#include <LiquidCrystal.h>

  const int waterPin = 0;
  int waterLevel;
  const int led = 7;
  const int buzzerPin = 4;

  lcd.begin(16,1);
  LiquidCrystal lcd (0, 1, 8, 9, 10, 11);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(waterPin, OUTPUT);
  pinMode(led, OUTPUT);
  digitalWrite(led,LOW);
  
}

void loop() {
  // put your main code here, to run repeatedly:
  waterLevel = analogRead(waterPin);
  Serial.println(waterLevel);
  lcd.print(waterLevel);
  delay(100);
  
  if(waterLevel >= 100){
    Serial.println(waterLevel);
    lcd.print(waterLevel);
    
    buzz();
    digitalWrite(led, HIGH);
    delay(100);
    digitalWrite(led,LOW);
    delay(100);
  }
  else {
    Serial.println(waterLevel);
    lcd.print(waterLevel);
    delay(100);
    noTone(buzzerPin);
  }
}
void buzz(){
  tone(buzzerPin, 2000);
  delay(50);
  noTone(buzzerPin);
  delay(50);
}

I realized I needed to put the lcd.begin(); in the setup.

You certainly can't put it anywhere before the lcd object is declared

Hi epicgamer.

Move your lcd.begin statement into the setup area and it should work.