1

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:

enter image description here

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.

Rohit Gupta's user avatar
Rohit Gupta
6342 gold badges6 silver badges21 bronze badges
askedJul 5, 2023 at 2:47
NyK's user avatar
6
  • 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.CommentedJul 5, 2023 at 4:03
  • What does your code output to Serial?CommentedJul 5, 2023 at 6:19
  • @st2000 i use it in 5 voltsCommentedJul 5, 2023 at 8:31
  • @StarCat it says connected and print the temp&humidityCommentedJul 5, 2023 at 8:32
  • @jsotola yes its my bad, i have edited my questionCommentedJul 5, 2023 at 8:32

0

Know someone who can answer? Share a link to thisquestion viaemail,Twitter, orFacebook.

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.