I have a problem with my project, the problem is that my Firebase can't detect my DHT11 temperature and humidity sensor from the Arduino.
The code runs without an error but the Firebase can't read my sensor.Here is my code
#include <FirebaseArduino.h>#include <ESP8266WiFi.h>#include <SoftwareSerial.h>#include <ArduinoJson.h>#include <ESP8266HTTPClient.h>#include <DHT.h>#define FIREBASE_HOST "*****-default-rtdb.firebaseio.com"#define FIREBASE_AUTH "WE7YUKBpSMo07nUT8ZWYS*****"#define WIFI_SSID "***"#define WIFI_PASSWORD "****"#define DHTPIN D5#define DHTTYPE DHT11DHT dht(DHTPIN, DHTTYPE);bool light;bool fan;unsigned long previousMillis = 0;const long interval = 10000;void setup() { pinMode(D1, OUTPUT); Serial.begin(115200); delay(500); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); Serial.println("Connecting.."); while (WiFi.status() != WL_CONNECTED){ Serial.print("."); delay(500); } Serial.println(); Serial.print("Connected "); Serial.println(WiFi.localIP()); Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); dht.begin(); delay(2000); if (Firebase.failed()) { Serial.print("Firebase connection failed: "); Serial.println(Firebase.error()); return; }}void readDatas(){ float h = dht.readHumidity(); float t = dht.readTemperature(); Serial.println(t); Serial.println(h); Firebase.setFloat("Data/Temperature:", t); Firebase.setFloat("Data/Humidity:", h); }void loop() { light = Firebase.getBool("LightStates/switch"); Serial.println(light); if (light == true){ digitalWrite(D6, HIGH); } if (light == false){ digitalWrite(D6, LOW); } fan = Firebase.getBool("FanStates/switch"); Serial.println(fan); if (fan == true){ digitalWrite(D7, HIGH); } if (fan == false){ digitalWrite(D7, LOW); } unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= interval){ readDatas(); previousMillis = currentMillis; }}Here is the screenshot of my Firebase for better understanding:
Temporarily, I am using dummy data for the temperature and humidity. Please if you guys know how to fix it, let me know. it will mean so much to me.
- Which Arduino are you using. Actually, better question, are you trying to run this sensor at 3 Volts? I recall some say it runs better (more dependably) at 5 Volts.st2000– st20002023-07-05 04:03:52 +00:00CommentedJul 5, 2023 at 4:03
- What does your code output to Serial?StarCat– StarCat2023-07-05 06:19:21 +00:00CommentedJul 5, 2023 at 6:19
- @StarCat it says connected and print the temp&humidityNyK– NyK2023-07-05 08:32:19 +00:00CommentedJul 5, 2023 at 8:32
- @jsotola yes its my bad, i have edited my questionNyK– NyK2023-07-05 08:32:42 +00:00CommentedJul 5, 2023 at 8:32
