#include <ESP8266WiFi.h>
#include <RBDdimmer.h>
#include "DHT.h"
#include "FirebaseESP8266.h"
#include "timer.h"
#include "HCSR04.h"
#define HOST "YOUR FIREBASE HOST"
#define AUTH "YOUR FIREBASE AUTH"
#define _SSID "YOUR WIFI SSID"
#define _PASS "YOUR WIFI PASS"
DHT dht(D2, DHT22);
dimmerLamp dimmer(D7, D6);
FirebaseData firebase;
FirebaseJson json;
float distance;
float temp, hum;
uint8_t timeCount = 0 , cond = 0, state = 0;
void transmitData() {
Firebase.setFloat(firebase, "/temp", temp);
Firebase.setFloat(firebase, "/hum", hum);
Firebase.setInt(firebase, "/cond", cond);
Firebase.setInt(firebase, "/state", state);
Firebase.setInt(firebase, "/time", timeCount);
}
void setup() {
Serial.begin(115200);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
WiFi.begin(_SSID, _PASS);
Serial.print("Connecting to wifi");
while (WiFi.status() != WL_CONNECTED) {
digitalWrite(D4, LOW);
delay(100);
digitalWrite(D4, HIGH);
delay(100);
}
digitalWrite(D4, HIGH);
Firebase.begin(HOST, AUTH);
Firebase.reconnectWiFi(true);
ultrasonicInit();
dht.begin();
dimmer.begin(NORMAL_MODE, ON);
}
void loop() {
//Pengecekan awal mesin
temp = dht.readTemperature();
hum = dht.readHumidity();
transmitData();
//Deteksi Biji kopi
while (distance > 15) {
distance = readDistance();
digitalWrite(D4, LOW);
}
cond = 1; state = 1;
// Proses pengeringan
if (distance < 10) {
while (1) {
startTimer();
Serial.println("Drying");
dimmer.setPower(100);
analogWrite(D3, 1023);
temp = dht.readTemperature();
hum = dht.readHumidity();
timeCount = countTime();
transmitData();
flashLED();
Serial.println(temp);
Serial.println(hum);
Serial.println(timeCount);
if (temp >= 50) {
dimmer.setPower(0);
analogWrite(D3, 0);
Firebase.setInt(firebase, "/state", 2);
Firebase.setInt(firebase, "/cond", 2);
Firebase.setInt(firebase, "/time", timeCount);
while (1) {
Serial.println("Drying finished successfully");
while(1);
}
}
}
}
}
Comments