Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"DHT Sensor Read Failed" in the Arduino IDE Serial Monitor. #3

Open
Nuba123 opened this issue Apr 9, 2019 · 0 comments
Open

"DHT Sensor Read Failed" in the Arduino IDE Serial Monitor. #3

Nuba123 opened this issue Apr 9, 2019 · 0 comments

Comments

@Nuba123
Copy link

Nuba123 commented Apr 9, 2019

I connected the DHT11 data pin (2) to ESP8266's D2 (GPIO 4) and define in sketch #define DHTPIN 4 for sending the temperature and humidity data to Firebase.
Following is the script.
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include <DHT.h>
//#include <ESP8266HTTPClient.h>
//#include <SoftwareSerial.h>
#include <Adafruit_Sensor.h>
#define FIREBASE_HOST "yourproject.firebaseio.com"
#define FIREBASE_AUTH "000000000000000000000"
#define WIFI_SSID "MMMM"
#define WIFI_PASSWORD "XXXXXXXXXi"
#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
delay(1000);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("Connected to ");
Serial.println(WIFI_SSID);
Serial.print("IP Address is : ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
dht.begin();
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}

Serial.print("Humidity: ");
Serial.print(h);
String fireHumid = String(h) + String("%");
Serial.print("% Temperature: ");
Serial.print(t); Serial.println("°C ");
String fireTemp = String(t) + String("°C");
delay(4000);
Firebase.pushString("xxxx.firebaseio.com/DHT11/Humidity", fireHumid);
Firebase.pushString("xxxx.firebaseio.com/DHT11/Temperature", fireTemp);
}

And I also tried in another way. I installed the DHT11-master library. If I work with this library then I have to change some code logic which I write down above. if I run this code including dht11 library then its showing the error in the below line.
float h= dht.readHumidity();
float t = dht.readTemperature();

'class dht11' has no member named 'readHumidity'
Can anyone please help me to re-write the code to work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant