I am very new to using Arduino, and I was building an IOT Weather Station that could tell the temperature, humidity and if it is raining. I have already uploaded the necessary libraries, plus I have downloaded the driver to make my esp8266 compatible with the Arduino IDE, and I am getting this error message;
Firebase_DHT_Rain:22:1: error: 'DHT' does not name a type
^
C:\Users\scooter\Downloads\Firebase_DHT_Rain\Firebase_DHT_Rain.ino: In function 'void setup()':
Firebase_DHT_Rain:33:5: error: expected unqualified-id before '.' token
pinMode(4,INPUT); // Data Pin of Rain Sensor , for NodeMCU D2 GPIO no. is 4
^
C:\Users\scooter\Downloads\Firebase_DHT_Rain\Firebase_DHT_Rain.ino: In function 'void loop()':
Firebase_DHT_Rain:42:15: error: expected primary-expression before '.' token
float t = dht.readTemperature(); // Reading temperature as Celsius (the default)
^
Firebase_DHT_Rain:43:15: error: expected primary-expression before '.' token
int r = digitalRead(4); // Reading the Rain Sensor Data
^
exit status 1
'DHT' does not name a type
Firebase_DHT_Rain:21:1: error: 'DHT' does not name a type
DHT dht(DHTPIN, DHTTYPE);
^
C:\Users\scooter\Downloads\Firebase_DHT_Rain\Firebase_DHT_Rain.ino: In function 'void setup()':
Firebase_DHT_Rain:32:5: error: expected unqualified-id before '.' token
dht.begin();
^
C:\Users\scooter\Downloads\Firebase_DHT_Rain\Firebase_DHT_Rain.ino: In function 'void loop()':
Firebase_DHT_Rain:41:15: error: expected primary-expression before '.' token
float h = dht.readHumidity();
^
Firebase_DHT_Rain:42:15: error: expected primary-expression before '.' token
float t = dht.readTemperature(); // Reading temperature as Celsius (the default)
^
exit status 1
'DHT' does not name a type
And here is the code
#include <Firebase.h>
#include <FirebaseArduino.h>
#include <FirebaseCloudMessaging.h>
#include <FirebaseError.h>
#include <FirebaseHttpClient.h>
#include <FirebaseObject.h>
#include <FirebaseArduino.h>
#include <dht.h>
#include "DHT.h"
#include <ESP8266WiFi.h>
#define FIREBASE_HOST "%%%%%%%%%" // Enter the Firebase Database URL Without Https and backslash
#define WIFI_SSID "Enter your WiFI SSID" // Change the name of your WIFI
#define WIFI_PASSWORD "WIFI PASSWORD" // Change the password of your WIFI
#define DHTPIN 14 // Data Pin of DHT 11 , for NodeMCU D5 GPIO no. is 14
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
Serial.begin(9600);
WiFi.begin (WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
dht.begin();
pinMode(4,INPUT); // Data Pin of Rain Sensor , for NodeMCU D2 GPIO no. is 4
Serial.println ("");
Serial.println ("WiFi Connected!");
Firebase.begin(FIREBASE_HOST);
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // Reading temperature as Celsius (the default)
int r = digitalRead(4); // Reading the Rain Sensor Data
Firebase.setFloat ("Temperature",t);
Serial.println(t);
Firebase.setFloat ("Humidity",h);
Serial.println(h);
if (r == 1)
{
Firebase.setString("Rain", "Yeah");
Serial.println("its raining");
}
else
{
Firebase.setString("Rain", "Nah");
Serial.println("no rains today");
}
delay(200);
}
I have just spent the last few weeks trying to figure out the problem, but I can't get it to work. If anyone is able to help me fix the code and get away that error message it would be very very much appreciated.
When I comment out the #include <dht.h> I get this error message;
Firebase_DHT_Rain:9:17: fatal error: DHT.h: No such file or directory
#include "DHT.h"
^
compilation terminated.
exit status 1
DHT.h: No such file or directory
There is a big confusion in your sketch between a library named DHT and a library named dht, both of which you #include
Using the DHT library you create an object named dht which I am not surprised causes a problem. If you really do only want to use the dht library then comment out #include "DHT.h", change DHT dht(DHTPIN, DHTTYPE); to dht dhtObject(DHTPIN, DHTTYPE); and rename all of the calls to dht functions to call dhtObject throughout the sketch
@UKHeliBob Thank you so much for your help so far. Just one question, will it work the same with the new code, and could you please send me the new code with everything new that you told be to fill in be filled by @UKHeliBob in because I am very busy lately and may not be able to do it, and I need the code very soon?
ALL of the calls to dht functions need to be changed to dhtObject if you follow my suggestion
The reason that I have suggested creating an object named dhtObject is to avoid having an object with the same name as the library, ie dht, which may cause problems
The error is happening because DHT11 is defined in the DHT library and that is no longer included but looking at the dht library it seems that the function calls are different too
I should have asked before, but is there any reason why you want to use the dht library and not the DHT library ?
Thank you so much for the code!!!! IT WORKS!!!!! If it wasn't for you, I would be stuck here for years going nowhere. I just want to thank you very much for the code. I just have one more question. That is, when I compile my code it says "Hard Resetting RT Pin..." after a successful compile. Then it just stays like that forever and doesn't actually compile onto the board. I have included a photo of what I mean. Thanks for your help.
Both of there cannot be true. If it works then it must be uploading to the board. After uploading to the board it is reset, hence the message. Here is what I see when I upload the code
esptool.py v2.8
Serial port COM8
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 80:7d:3a:47:65:b6
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 360928 bytes to 263571...
Wrote 360928 bytes (263571 compressed) at 0x00000000 in 5.9 seconds (effective 486.6 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...