Hi! Can anyone help me with this? In my case, i want relay and temperature can be work at the same time without any problems, relay supposed to control on Android and temperature should be automatic.
Here's my source code. Thanks in advance!
#include "FirebaseESP8266.h"
#include <ESP8266WiFi.h>
#include <DHT.h>
#define FIREBASE_HOST "smart-cage-esp8266-default-rtdb.firebaseio.com" // Your Firebase Project URL
#define FIREBASE_AUTH "CJowtg0z3jsMvcLBpQXsxSocT8eJHg1nrRW3NHmB" // Your Firebase Database Secret
#define WIFI_SSID "Tebak" // your WiFi SSID
#define WIFI_PASSWORD "akusiapa" // your WiFi PASSWORD
//SUHU
#define DHTPIN D3
#define DHTTYPE DHT11
FirebaseData fbdo;
DHT dht11(DHTPIN,DHTTYPE);
String R1, R2;
int r1, r2;
float t;
void setup() {
pinMode(D0, OUTPUT);
dht11.begin();
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(300);
}
Serial.println();
Serial.print("Connected to IP : ");
Serial.println(WiFi.localIP());
Serial.println();
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);
if(Firebase.setInt(fbdo, "/Hasil_Pembacaan/Relay1", 0))
{
//Success
Serial.println("Relay Siap");
}else{
//Failed, get error reason from fbdo
Serial.println("Gagal");
Serial.println(fbdo.errorReason());
}
}
void loop() {
t = dht11.readTemperature();
// Memeriksa apakah sensor berhasil mambaca suhu dan kelembaban
if (isnan(t)) {
Serial.println("Gagal membaca sensor DHT11");
delay(1000);
return;
}
Firebase.getString(fbdo, "/Hasil_Pembacaan/Relay1");
R1 = fbdo.stringData();
r1 = R1.toInt();
if(r1==0 && t < 31)
{
digitalWrite(D0, HIGH);
Serial.println("Relay OFF");
}
else if(r1== 1 && t > 31)
{
digitalWrite(D0, LOW);
Serial.println("Relay ON");
}
//PENGATURAN KIRIM DATA KE FIREBASE
if (Firebase.setFloat(fbdo, "/Hasil_Pembacaan/Suhu", t)){
Serial.println("Suhu terkirim");
} else{
Serial.println("Suhu tidak terkirim");
Serial.println("Karena: " + fbdo.errorReason());
}
}
hi! i want to use relay control and temperature control in one function, so relay can control from app and also temperature can be run automatically. i'm very sorry for my lack english but i hope you understand
if the relay is 1 (active) and the temperature is above 30, the relay (lamp) is on and if the relay is 0 (inactive) and the temperature is below 30, the relay (lamp) is off.
t = temperature (dht11)
D0 = relay
r1 = to control relay from firebase
the temperature should be automatic and the relay should be manual (controlling by Android and use Firebase).
but when i run it, only one of them can run. for example the relay control can but the temperature can't.
Hello. I have a problem with this, anyone knows what is wrong?
L1 = relay control (from Android)
t = temperature
R1 = convert data relay from string to int
It works fine but when relay was ON automatic, i can't turn it off manually on Android but when relay was OFF automatic, i can turn it on manually on Android. What i suppose to do?
What i want is when L1 == 0 and t < 31 and relay active automatically, i can turn it off manually