Hi! My project is about DHT22 and LCD Screen 1602A.
Where did I do wrong in the code?
Below is the code I’m using
/* LCD DHT-22 Temp & Humidity Sensor
www.ardumotive.com // Project Corner
Vasilakis Michalis - date: 18/2/2015
Many thanks to Rob Tillaart for DHT library! */
//Libraries
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <LiquidCrystal.h>
// initialize the lcd library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//DHT pin to arduino pin 6
#define dhtPin
#define dht22
#define DHTTYPE dht22
DHT dht (dhtPin , DHTTYPE)
float temp = dht.readTemperature();
const int dhtPin = 6;
//Variables
int chk;
float hum;
float temp;
void setup()
{
lcd.begin(16,2);
}
void loop()
{
// READ DATA
chk = dht.read22(dhtPin);
hum = dht.humidity;
temp= dht.temperature;
// DISPLAY DATA
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(temp,1);
lcd.print(char(223)); // Print degree symbol
lcd.print("C");
lcd.setCursor(0,1); // Change lcd line...
lcd.print("Humidity: ");
lcd.print(hum,0);
lcd.print("%");
delay(2000); //Refresh every 2 sec.
}
and error message below:
Arduino: 1.8.7 (Windows Store 1.8.15.0) (Windows 10), Board: "Arduino/Genuino Uno"
dht22lcd:18:17: error: expected primary-expression before ',' token
DHT dht (dhtPin , DHTTYPE)
^
dht22lcd:18:26: error: expected primary-expression before ')' token
DHT dht (dhtPin , DHTTYPE)
^
dht22lcd:19:1: error: expected ',' or ';' before 'float'
float temp = dht.readTemperature();
^
dht22lcd:20:18: error: expected unqualified-id before '=' token
const int dhtPin = 6;
^
C:\Users\Lenovo\Downloads\dht22lcd\dht22lcd.ino: In function 'void loop()':
dht22lcd:34:15: error: 'class DHT' has no member named 'read22'
chk = dht.read22(dhtPin);
^
dht22lcd:35:15: error: 'class DHT' has no member named 'humidity'
hum = dht.humidity;
^
dht22lcd:36:15: error: 'class DHT' has no member named 'temperature'
temp= dht.temperature;
^
exit status 1
expected primary-expression before ',' token
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
What about: expected primary-expression before ‘)’ token and also other errors?
What should I do to the code?
Error Code:
Arduino: 1.8.7 (Windows Store 1.8.15.0) (Windows 10), Board: "Arduino/Genuino Uno"
dht22lcd:18:26: error: expected primary-expression before ')' token
DHT dht (dhtPin , DHTTYPE);
^
dht22lcd:15:16: error: expected unqualified-id before numeric constant
#define dhtPin 6
^
C:\Users\Lenovo\Downloads\dht22lcd\dht22lcd.ino:19:11: note: in expansion of macro 'dhtPin'
const int dhtPin = 6;
^
C:\Users\Lenovo\Downloads\dht22lcd\dht22lcd.ino: In function 'void loop()':
dht22lcd:35:15: error: 'class DHT' has no member named 'read22'
chk = dht.read22(dhtPin);
^
dht22lcd:36:15: error: 'class DHT' has no member named 'humidity'
hum = dht.humidity;
^
dht22lcd:37:15: error: 'class DHT' has no member named 'temperature'
temp= dht.temperature;
^
exit status 1
expected primary-expression before ')' token
Renewed code:
/* LCD DHT-22 Temp & Humidity Sensor
www.ardumotive.com // Project Corner
Vasilakis Michalis - date: 18/2/2015
Many thanks to Rob Tillaart for DHT library! */
//Libraries
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <LiquidCrystal.h>
// initialize the lcd library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//DHT pin to arduino pin 6
#define dhtPin 6
#define dht22
#define DHTTYPE dht22
DHT dht (dhtPin , DHTTYPE);
const int dhtPin = 6;
//Variables
int chk;
float hum;
float temp = dht.readTemperature();
void setup()
{
lcd.begin(16,2);
}
void loop()
{
// READ DATA
chk = dht.read22(dhtPin);
hum = dht.humidity;
temp= dht.temperature;
// DISPLAY DATA
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(temp,1);
lcd.print(char(223)); // Print degree symbol
lcd.print("C");
lcd.setCursor(0,1); // Change lcd line...
lcd.print("Humidity: ");
lcd.print(hum,0);
lcd.print("%");
delay(2000); //Refresh every 2 sec.
}
I tried to use the Rob Tillaart but it keeps telling me: Specified folder/zip file does not contain a valid library.
Where are you trying to download a zip version of this library from?
The library is small, and you can also manually copy the .h , .cpp and examples files from github into a text editor. Save them as .cpp , .h files and .ino files into folder you create in your user libraries.
I have downloaded it from github.com and it appears at "Arduino-master" in my download file as a zip file
But when I tried to Add .zip library it said that Specified folder/zip file does not contain a valid library.
cattledog:
The library is small, and you can also manually copy the .h , .cpp and examples files from github into a text editor. Save them as .cpp , .h files and .ino files into folder you create in your user libraries.
I have downloaded it from github.com and it appears at "Arduino-master" in my download file as a zip file
But when I tried to Add .zip library it said that Specified folder/zip file does not contain a valid library.
Here's a process I followed. In downloads, double click and navigate through the "Arduino-master" untill you get to a level called "libraries." You will find "DHTlib" there. Make a copy and paste it on the destop.
Then, when you use the Add.ZIPLibrary use "look in" to select the desktop, and then click on DHTlib. It will show in the file name bar and will added when you click "open".