# Lcd does not name a type?

**URL:** <https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122>\
**Category:** Programming\
**Created:** [May 12, 2022, 3:10pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122 "2022-05-12T15:10:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![littlecrow](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@littlecrow](https://forum.arduino.cc/u/littlecrow)\
**Post date:** [May 12, 2022, 3:10pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/1 "2022-05-12T15:10:42Z")

</div>

I need help getting my code to work the problem says  
im trying to get an LED and the 1602 LCD w/12C to turn on when a soil moisture sensor im using the LIQUIDCRYSTAL I2C

A library for I2C LCD displays library  
works the code is

```cpp
int lcd;

 // LiquidCrystal - Version: 1.0.0
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A5; // Analog input pin that the Sensor is attached to
int sensorValue = 0; // value read from the Soil Moisture 

void loop() {
sensorValue = analogRead(analogInPin);// read the analog in value:
lcd.setCursor(0, 1);
lcd.print(sensorValue);
// wait 300 milliseconds before the next loop for the 
//analog-to-digital converter to settle after the last reading:
delay(300);

}

void setup() {

// set up the LCD's number of columns and rows:
lcd.begin(16, 2)
delay(300);
lcd.clear();
lcd.print("Soil Moisture:");// print the results to the LCD Display:

}

```

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [May 12, 2022, 3:12pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/2 "2022-05-12T15:12:40Z")

</div>

> [@littlecrow](#):
>
> I need help getting my code to

What code?

(This is not an installation issue)

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [May 12, 2022, 3:13pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/3 "2022-05-12T15:13:52Z")

</div>

Without your code, I think it's difficult to determine what is wrong.

Your topic has been moved to a more suitable location on the forum. _Installation and Troubleshooting_ is not for problems with (nor for advise on) your project 😉 See [About the Installation & Troubleshooting category](https://forum.arduino.cc/t/about-the-installation-troubleshooting-category/847458).

---

<div class="post-metadata">

**Author:** ![in0](https://avatars.discourse-cdn.com/v4/letter/i/77aa72/32.png) [@in0](https://forum.arduino.cc/u/in0)\
**Post date:** [May 12, 2022, 3:15pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/4 "2022-05-12T15:15:33Z")

</div>

Hi @littlecrow. Please provide a link to where you found this "soil moisture" sketch.

Arduino Web Editor is a little bit tricky to use sometimes due to the fact that it has all ~4800 libraries of the Arduino Library Manager pre-installed. So sometimes a different library gets used than the one your sketch was written for. You can see that it had a couple different libraries to pick from here:

> [@littlecrow](#):
>
> ```plaintext
> Multiple libraries were found for "LiquidCrystal.h"
> 
> Used: /home/builder/opt/libraries/liquidcrystal_1_0_0
> 
> Not used: /home/builder/opt/libraries/liquidcrystal_1_0_7
> 
> Using library liquidcrystal_1_0_0 at version 1.0.0 in folder: /home/builder/opt/libraries/liquidcrystal_1_0_0
> 
> ```

We can probably figure out which specific library was meant to be used by looking at the information original source of the sketch. With that information, we can figure out how to cajole the Arduino Web Editor into picking the right library.

---

<div class="post-metadata">

**Author:** ![littlecrow](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@littlecrow](https://forum.arduino.cc/u/littlecrow)\
**Post date:** [May 13, 2022, 2:06pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/5 "2022-05-13T14:06:45Z")

</div>

ok ill add the code

---

<div class="post-metadata">

**Author:** ![littlecrow](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@littlecrow](https://forum.arduino.cc/u/littlecrow)\
**Post date:** [May 13, 2022, 2:24pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/6 "2022-05-13T14:24:43Z")

</div>

Ok so i fixed it by putting: int lcd;, but now i have a different problem. it says "request for member 'setCursor' in 'lcd', which is of non-class type 'int'." this is the code:

```cpp

int lcd;

 // LiquidCrystal - Version: 1.0.0
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A5; // Analog input pin that the Sensor is attached to
int sensorValue = 0; // value read from the Soil Moisture 

void loop() {
sensorValue = analogRead(analogInPin);// read the analog in value:
lcd.setCursor(0, 1);
lcd.print(sensorValue);
// wait 300 milliseconds before the next loop for the 
//analog-to-digital converter to settle after the last reading:
delay(300);

}

void setup() {

// set up the LCD's number of columns and rows:
lcd.begin(16, 2)
delay(300);
lcd.clear();
lcd.print("Soil Moisture:");// print the results to the LCD Display:

}

```

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [May 13, 2022, 2:57pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/7 "2022-05-13T14:57:24Z")

</div>

The` int lcd;` creates a variable with the name lcd of the data type int.

> [@littlecrow](#):
>
> // initialize the library with the numbers of the interface pins  
> // These constants won't change. They're used to give names  
> // to the pins used:

What you need to do is to create an instance of the LiquidCrystal class called lcd like so:  
`LiquidCrystal lcd(rd, en, d4, d5, d6, d7);`  
but replace rd, en, d4, d5, d6, d7 with the pins that connect between the lcd and the Arduino. Look at the example code that comes with the LiquidCrystal library.

[**Read the forum guidelines**](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966#posting-code-and-common-code-problems) to see how to **properly post code** and some information on how to get the most from this forum.  
**Use the IDE autoformat tool** (ctrl-t or Tools, Auto format) before posting code in code tags.

Please go back and **fix your original post** by highlighting the code and clicking the \</\> in the menu bar.

 ![code tags new](https://europe1.discourse-cdn.com/arduino/original/4X/4/7/0/47090818c9d4d7d934b4b44ab7b96e834ea3164c.jpeg)

This will compile. Replace the pin numbers in the LCD constructor with the pins that you are using. I also moved the setup() to before loop() (not necessary, but the usual order) and added a missing semicolon.

```arduino
// LiquidCrystal - Version: 1.0.0
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
// These constants won't change. They're used to give names
// to the pins used:
LiquidCrystal lcd(12,11,4,5,6,7); // replace with your pin numbers

const int analogInPin = A5; // Analog input pin that the Sensor is attached to
int sensorValue = 0; // value read from the Soil Moisture

void setup()
{
   // set up the LCD's number of columns and rows:
   lcd.begin(16, 2); // added missing ;
   delay(300);
   lcd.clear();
   lcd.print("Soil Moisture:");// print the results to the LCD Display:
}

void loop()
{
   sensorValue = analogRead(analogInPin);// read the analog in value:
   lcd.setCursor(0, 1);
   lcd.print(sensorValue);
   // wait 300 milliseconds before the next loop for the
   //analog-to-digital converter to settle after the last reading:
   delay(300);
}

```

Posted in code tags after auto-formatting.

---

<div class="post-metadata">

**Author:** ![littlecrow](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@littlecrow](https://forum.arduino.cc/u/littlecrow)\
**Post date:** [May 16, 2022, 2:28pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/8 "2022-05-16T14:28:54Z")

</div>

where do i put the code that you told me to do? here is my curent code and what it says:

```cpp

int lcd;

 // LiquidCrystal - Version: 1.0.0
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
// These constants won't change. They're used to give names
// to the pins used:
LiquidCrystal lcd(gnd, vcc, sda, scl, a4, a5);
const int analogInPin = A5; // Analog input pin that the Sensor is attached to
int sensorValue = 0; // value read from the Soil Moisture 

void loop() {
sensorValue = analogRead(analogInPin);// read the analog in value:
lcd.setCursor(0, 1);
lcd.print(sensorValue);
// wait 300 milliseconds before the next loop for the 
//analog-to-digital converter to settle after the last reading:
delay(300);

}

void setup() {

// set up the LCD's number of columns and rows:
lcd.begin(16, 2)
delay(300);
lcd.clear();
lcd.print("Soil Moisture:");// print the results to the LCD Display:

}

```

error: conflicting declaration 'LiquidCrystal lcd'

---

<div class="post-metadata">

**Author:** ![wildbill](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wildbill/32/1126438_2.png) [@wildbill](https://forum.arduino.cc/u/wildbill)\
**Post date:** [May 16, 2022, 2:32pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/9 "2022-05-16T14:32:23Z")

</div>

Delete this:

```cpp
int lcd;

```

---

<div class="post-metadata">

**Author:** ![littlecrow](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@littlecrow](https://forum.arduino.cc/u/littlecrow)\
**Post date:** [May 16, 2022, 2:37pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/10 "2022-05-16T14:37:18Z")

</div>

ok i deleted it. now the error is: 'gnd' was not declared in this scope.

```cpp

 // LiquidCrystal - Version: 1.0.0
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
// These constants won't change. They're used to give names
// to the pins used:
LiquidCrystal lcd(gnd, vcc, sda, scl, a4, a5);
const int analogInPin = A5; // Analog input pin that the Sensor is attached to
int sensorValue = 0; // value read from the Soil Moisture 

void loop() {
sensorValue = analogRead(analogInPin);// read the analog in value:
lcd.setCursor(0, 1);
lcd.print(sensorValue);
// wait 300 milliseconds before the next loop for the 
//analog-to-digital converter to settle after the last reading:
delay(300);

}

void setup() {

// set up the LCD's number of columns and rows:
lcd.begin(16, 2)
delay(300);
lcd.clear();
lcd.print("Soil Moisture:");// print the results to the LCD Display:

}

```

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [May 16, 2022, 2:38pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/11 "2022-05-16T14:38:33Z")

</div>

> [@littlecrow](#):
>
> A library for I2C LCD displays library

Base your code on the examples of that library and nothing else.

> [@littlecrow](#):
>
> `LiquidCrystal lcd(gnd, vcc, sda, scl, a4, a5);`

That is using the normal LiquidCrystal library, not an I2C one.

---

<div class="post-metadata">

**Author:** ![littlecrow](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@littlecrow](https://forum.arduino.cc/u/littlecrow)\
**Post date:** [May 16, 2022, 2:41pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/12 "2022-05-16T14:41:58Z")

</div>

ok i did the second thing still the same error message

```cpp

// LiquidCrystal I2C - Version: Latest 
#include <LiquidCrystal_I2C.h>

// initialize the library with the numbers of the interface pins
// These constants won't change. They're used to give names
// to the pins used:
LiquidCrystal_I2C lcd(gnd, vcc, sda, scl, a4, a5);
const int analogInPin = A5; // Analog input pin that the Sensor is attached to
int sensorValue = 0; // value read from the Soil Moisture 

void loop() {
sensorValue = analogRead(analogInPin);// read the analog in value:
lcd.setCursor(0, 1);
lcd.print(sensorValue);
// wait 300 milliseconds before the next loop for the 
//analog-to-digital converter to settle after the last reading:
delay(300);

}

void setup() {

// set up the LCD's number of columns and rows:
lcd.begin(16, 2)
delay(300);
lcd.clear();
lcd.print("Soil Moisture:");// print the results to the LCD Display:

}

```

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [May 16, 2022, 2:48pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/13 "2022-05-16T14:48:27Z")

</div>

> [@littlecrow](#):
>
> `LiquidCrystal_I2C lcd(gnd, vcc, sda, scl, a4, a5);`

What do the examples of the LiquidCrystal\_I2C library that you use tell you to use?

---

<div class="post-metadata">

**Author:** ![littlecrow](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@littlecrow](https://forum.arduino.cc/u/littlecrow)\
**Post date:** [May 17, 2022, 2:54pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/15 "2022-05-17T14:54:20Z")

</div>

what are you talking about? the libary i use is from arduino and no one is doing the thing we are doing.

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [May 17, 2022, 3:01pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/16 "2022-05-17T15:01:24Z")

</div>

It's fairly unusual to have to name the GND pin.

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [May 17, 2022, 3:01pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/17 "2022-05-17T15:01:41Z")

</div>

> [@littlecrow](#):
>
> `LiquidCrystal_I2C lcd(gnd, vcc, sda, scl, a4, a5);`

That constructor is totally wrong. Do as @sterretje says and look at the example code that comes with the LiquidCrystal\_I2C library to see the syntax for the constructor.

You will need to know the LCD I2C address and the nLCD to I2C backpack pin mapping (wiring) to be able to write the constructor.

---

<div class="post-metadata">

**Author:** ![littlecrow](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@littlecrow](https://forum.arduino.cc/u/littlecrow)\
**Post date:** [May 17, 2022, 3:05pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/18 "2022-05-17T15:05:35Z")

</div>

Ok thank you but which one of the codes is it?

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [May 17, 2022, 3:10pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/19 "2022-05-17T15:10:27Z")

</div>

Any example code of the LiquidCrystal\_I2C library that you use will show how the constructor is used.

> [@littlecrow](#):
>
> Ok thank you but which one of the codes is it?

---

<div class="post-metadata">

**Author:** ![littlecrow](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@littlecrow](https://forum.arduino.cc/u/littlecrow)\
**Post date:** [May 17, 2022, 3:11pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/20 "2022-05-17T15:11:31Z")

</div>

ok thank you, but can you show me an example

---

<div class="post-metadata">

**Author:** ![gfvalvo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gfvalvo/32/1013044_2.png) [@gfvalvo](https://forum.arduino.cc/u/gfvalvo)\
**Post date:** [May 17, 2022, 3:12pm UTC](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122/21 "2022-05-17T15:12:08Z")

</div>

Just go to examples in the Arduino IDE and select that library. It's not hard. Put in some effort.

[Next page](https://forum.arduino.cc/t/lcd-does-not-name-a-type/991122.md?page=2)
