Hi, ive been trying to build something, but I keep on getting the ''lcd' was not declared in this scope' error message.
#include <LiquidCrystal.h>
#define MQ3pin 8
int sensorValue; //variable to store sensor value
void setup() {
lcd.begin(16,2); // start the lcd
lcd.backlight(); // LCD back light on
lcd.println("MQ3 warming up!");
delay(20000); // allow the MQ3 to warm up
}
void loop() {
lcd.setCursor(0,0)
sensorValue = digitalRead(MQ3pin); // read digital output pin
lcd.print("Digital Output: ");
lcd.print(sensorValue);
// Determine the status
if (sensorValue) {
lcd.println(" | Alcohol: -");
} else {
lcd.println(" | Alcohol: Detected!");
}
delay(2000); // wait 2s for next reading
lcd.clear()
}
Welcome to the forum
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
See also FAQ - Arduino Forum for general rules on forum behaviour and etiquette.
Hello,
Welcome to the Arduino Forum.
This guide explains how to get the best out of this forum. Please read and follow the instructions below.
Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…
You have not declared an instance of the LiquidCrystal library names lcd. Compare your code with the library examples
The error message is correct, lcd is not declared.
Have you looked at the LCD examples to see how to declare lcd?
By typing the words "arduino lcd" into an internet search engine you can find, Arduino - LCD | Arduino Tutorial (arduinogetstarted.com) , one example of many that shows how to use the lcd.
If you want you can wait for me to correct the error or you can do your own research.
And when you post code, use code tags, please.
system
Closed
August 23, 2022, 10:24am
5
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.