I'm using LCD 1602A 16x2 and I tried installing several sketches but it still shows that error code.
And if anyone sees any mistake in the code please tell
I got this from the internet and did several changes but there are still many errors
this is the code i'm using
#include <Streaming.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <LiquidCrystal.h>
// Pin connected to the sensor data pin
#define DHTPIN 7
// Display pins
LiquidCrystal LCD (12, 11, 5, 4, 3, 2);
// Use the line according to the sensor model
// #define DHTTYPE DHT11 // Sensor DHT11
#define DHTTYPE DHT22 //DHT Sensor 22 (AM2302)
// #define DHTTYPE DHT21 // DHT Sensor 21 (AM2301)
// Definitions sensor: pin, type
DHT DHT (DHTPIN, DHTTYPE);
// Array symbol degree
byte level [8] = {B00001100,
B00010010,
B00010010,
B00001100,
B00000000,
B00000000,
B00000000,
B00000000,
};
void setup ()
{
// Initialize the display
lcd.begin (16, 2);
lcd.clear ();
// Create the custom character with the symbol of the degree
lcd.createChar (0, degree);
// Information on the initial display
lcd.setCursor (0, 0);
lcd.print ("Temp. : ");
lcd.setCursor (13.0);
// Shows the symbol of the degree
lcd.write (byte (0));
lcd.print ("C");
lcd.setCursor (0.1);
lcd.print ("Humid. : ");
lcd.setCursor (14.1);
lcd.print ("%");
Serial.begin (9600);
Serial.println ("Waiting for data ...");
// Starts DHT sensor
dht.begin ();
}
void loop ()
{
// Wait 2 seconds between the measurements
delay (2000);
// Moisture reading
h = dht.readHumidity float ();
// Reading of temperature (Celsius)
t = dht.readTemperature float ();
// Check if the sensor is responding
if (isnan (h) || isnan (t))
{
Serial.println ("Failed to read DHT sensor data !!!");
return;
}
// Display the temperature in the serial monitor and display
Serial.print ("Temperature: ");
Serial.print (t);
lcd.setCursor (8.0);
lcd.print (t);
Serial.print (" C * ");
// Show the moisture in the serial monitor and display
Serial.print ("humidity: ");
Serial.print (h);
Serial.println (" %");
lcd.setCursor (8.1);
lcd.print (h);
}
and below is the error code
C:\Users\Lenovo\Documents\Arduino\Probes_Arduino_LCD_1206A_DHT22\Probes_Arduino_LCD_1206A_DHT22.ino: In function 'void setup()':
Probes_Arduino_LCD_1206A_DHT22:38: error: 'lcd' was not declared in this scope
 lcd.begin (16, 2);
 ^
Probes_Arduino_LCD_1206A_DHT22:41: error: 'degree' was not declared in this scope
 lcd.createChar (0, degree);
          ^
Probes_Arduino_LCD_1206A_DHT22:57: error: 'dht' was not declared in this scope
 dht.begin ();
 ^
C:\Users\Lenovo\Documents\Arduino\Probes_Arduino_LCD_1206A_DHT22\Probes_Arduino_LCD_1206A_DHT22.ino: In function 'void loop()':
Probes_Arduino_LCD_1206A_DHT22:66: error: 'h' was not declared in this scope
 h = dht.readHumidity float ();
 ^
Probes_Arduino_LCD_1206A_DHT22:66: error: 'dht' was not declared in this scope
 h = dht.readHumidity float ();
   ^
Probes_Arduino_LCD_1206A_DHT22:68: error: 't' was not declared in this scope
 t = dht.readTemperature float ();
 ^
Probes_Arduino_LCD_1206A_DHT22:80: error: 'lcd' was not declared in this scope
 lcd.setCursor (8.0);
 ^
Using library LCD_I2C_lib-master in folder: C:\Users\Lenovo\Documents\Arduino\libraries\LCD_I2C_lib-master (legacy)
Using library Adafruit_Unified_Sensor at version 1.0.2 in folder: C:\Users\Lenovo\Documents\Arduino\libraries\Adafruit_Unified_Sensor
Using library DHT_sensor_library-1.3.0 at version 1.3.0 in folder: C:\Users\Lenovo\Documents\Arduino\libraries\DHT_sensor_library-1.3.0
Using library LiquidCrystal at version 1.0.7 in folder: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire
exit status 1
'lcd' was not declared in this scope
Thank you for answering.
Below is the code I've updated. But now it is stated as
Using library LCD_I2C_lib-master in folder: C:\Users\Lenovo\Documents\Arduino\libraries\LCD_I2C_lib-master (legacy)
Using library Adafruit_Unified_Sensor at version 1.0.2 in folder: C:\Users\Lenovo\Documents\Arduino\libraries\Adafruit_Unified_Sensor
Using library DHT_sensor_library-1.3.0 at version 1.3.0 in folder: C:\Users\Lenovo\Documents\Arduino\libraries\DHT_sensor_library-1.3.0
Using library LiquidCrystal at version 1.0.7 in folder: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire
exit status 1
'degree' was not declared in this scope
#include <Streaming.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <LiquidCrystal.h>
// Pin connected to the sensor data pin
#define DHTPIN 7
// Display pins
LiquidCrystal LCD (12, 11, 5, 4, 3, 2);
// Use the line according to the sensor model
// #define DHTTYPE DHT11 // Sensor DHT11
#define DHTTYPE DHT22 //DHT Sensor 22 (AM2302)
// #define DHTTYPE DHT21 // DHT Sensor 21 (AM2301)
// Definitions sensor: pin, type
DHT DHT (DHTPIN, DHTTYPE);
// Array symbol degree
byte level [8] = {B00001100,
B00010010,
B00010010,
B00001100,
B00000000,
B00000000,
B00000000,
B00000000,
};
void setup ()
{
// Initialize the display
LCD.begin (16, 2);
LCD.clear ();
// Create the custom character with the symbol of the degree
LCD.createChar (0, degree);
// Information on the initial display
LCD.setCursor (0, 0);
LCD.print ("Temp. : ");
LCD.setCursor (13.0);
// Shows the symbol of the degree
LCD.write (byte (0));
LCD.print ("C");
LCD.setCursor (0.1);
LCD.print ("Humid. : ");
LCD.setCursor (14.1);
LCD.print ("%");
Serial.begin (9600);
Serial.println ("Waiting for data ...");
// Starts DHT sensor
dht.begin ();
}
void loop ()
{
// Wait 2 seconds between the measurements
delay (2000);
// Moisture reading
h = dht.readHumidity float ();
// Reading of temperature (Celsius)
t = dht.readTemperature float ();
// Check if the sensor is responding
if (isnan (h) || isnan (t))
{
Serial.println ("Failed to read DHT sensor data !!!");
return;
}
// Display the temperature in the serial monitor and display
Serial.print ("Temperature: ");
Serial.print (t);
LCD.setCursor (8.0);
LCD.print (t);
Serial.print (" C * ");
// Show the moisture in the serial monitor and display
Serial.print ("humidity: ");
Serial.print (h);
Serial.println (" %");
LCD.setCursor (8.1);
LCD.print (h);
}
exit status 1
no matching function for call to 'LiquidCrystal::setCursor(double)'
Below is the code which I have changed as stated in the comments:
#include <Streaming.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <LiquidCrystal.h>
// Pin connected to the sensor data pin
#define DHTPIN 7
// Display pins
LiquidCrystal LCD (12, 11, 5, 4, 3, 2);
// Use the line according to the sensor model
// #define DHTTYPE DHT11 // Sensor DHT11
#define DHTTYPE DHT22 //DHT Sensor 22 (AM2302)
// #define DHTTYPE DHT21 // DHT Sensor 21 (AM2301)
// Definitions sensor: pin, type
DHT DHT (DHTPIN, DHTTYPE);
// Array symbol level
byte level [8] = {B00001100,
B00010010,
B00010010,
B00001100,
B00000000,
B00000000,
B00000000,
B00000000,
};
void setup ()
{
// Initialize the display
LCD.begin (16, 2);
LCD.clear ();
// Create the custom character with the symbol of the level
LCD.createChar (0, level);
// Information on the initial display
LCD.setCursor (0, 0);
LCD.print ("Temp. : ");
LCD.setCursor (13.0);
// Shows the symbol of the level
LCD.write (byte (0));
LCD.print ("C");
LCD.setCursor (0.1);
LCD.print ("Humid. : ");
LCD.setCursor (14.1);
LCD.print ("%");
Serial.begin (9600);
Serial.println ("Waiting for data ...");
// Starts DHT sensor
dht.begin ();
}
void loop ()
{
// Wait 2 seconds between the measurements
delay (2000);
// Moisture reading
h = dht.readHumidity float ();
// Reading of temperature (Celsius)
t = dht.readTemperature float ();
// Check if the sensor is responding
if (isnan (h) || isnan (t))
{
Serial.println ("Failed to read DHT sensor data !!!");
return;
}
// Display the temperature in the serial monitor and display
Serial.print ("Temperature: ");
Serial.print (t);
LCD.setCursor (8.0);
LCD.print (t);
Serial.print (" C * ");
// Show the moisture in the serial monitor and display
Serial.print ("humidity: ");
Serial.print (h);
Serial.println (" %");
LCD.setCursor (8.1);
LCD.print (h);
}
I took this code from the internet because I'm still kind of new to arduino and the first time using this kind of code.
I'm trying to get a code with the LCD screen connected with the DHT22 but when i searched the internet what i found was mostly about the LCD screen or DHT22 only not for activating both.
Below is the attachment of the schematic reference i used for my project.
boice77:
I took this code from the internet because I'm still kind of new to arduino and the first time using this kind of code.
I'm trying to get a code with the LCD screen connected with the DHT22 but when i searched the internet what i found was mostly about the LCD screen or DHT22 only not for activating both.
Below is the attachment of the schematic reference i used for my project.
This is a normal occuring thing. You take some code from the internet and expect it to do your bidding after some alteration and modification. Usually not the case.
If this is your first script to me it seems complex without having done other simpler things before.
Like you I'm also new to arduino so I can't help you much yet but I think you should at least read and understand some of the examples in the IDE that will help you along way forward.
That should be pretty obvious. Fire up the IDE. Open your sketch, and start typing.
I tried to look at the example code but still confused with it.
I find that hard to comprehend. lcd.print() is dirt simple to use. You just need something to print. That could be a temperature value, a humidity value, or a literal string. None of them are difficult to come by.