hello guys i have a problem for my project, the problem is that my firebase cant detect my DHT11 temp and humid censor from the Arduino, the code run without an error but the firebase cant read my censor.
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 DHT11
DHT 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 use a dummy data for the temp and humid. please if you guys know how to fix it, let me know. it will mean so much to me
thankyou