Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Fattah
Published

Smart Coffee Beans Dryer (IoT Project)

Dry coffee beans, and send amount of realtime data such as temperature, humidity, and drying time

IntermediateShowcase (no instructions)Over 1 day600
Smart Coffee Beans Dryer (IoT Project)

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Axial Fan, 12 V
Axial Fan, 12 V
×1
220 V Heater
×1
220 V AC Dimmer
×1
AC/DC Power Supply, 12 V
AC/DC Power Supply, 12 V
×1
LM 2596 Buck Converter
×1
Android device
Android device
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

mainCode

C/C++
Coffee Beans Automation V1A
#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);
        }
      }
    }
  }
}

HCSR04

C/C++
Library for HCSR04
#ifndef HCSR04_h
#define HCSR04_h

long _duration;
uint8_t _distance;

void ultrasonicInit() {
  pinMode(D5, OUTPUT);  //Trigger
  pinMode(D8, INPUT);   //Echo
}

uint8_t readDistance() {
  digitalWrite(D5, LOW);
  delayMicroseconds(2);

  digitalWrite(D5, HIGH);
  delayMicroseconds(10);
  digitalWrite(D5, LOW);

  _duration = pulseIn(D8, HIGH);
  _distance = _duration * 0.034/2;

  delay(200);

  return _distance;
}

#endif

Timer

C/C++
Timer library
#ifndef timer_h
#define timer_h

#include <Arduino.h>
uint16_t _fiveSecond = 5000;
uint16_t _twoSecond = 2000;
uint16_t _time = 0;

long _currentTimeOne, _currentTimeTwo = 0;
long _prevTimeOne = 0, _prevTimeTwo = 0;

void startTimer() {
  _currentTimeOne = millis();
  _currentTimeTwo = millis();
}

int countTime() {
  if (_currentTimeOne - _prevTimeTwo >= _twoSecond) {
    _time++;
    _prevTimeOne = _currentTimeOne;
  }
  return _time;
}

void flashLED() {
  if (_currentTimeTwo - _prevTimeTwo >= _fiveSecond) {
    for (uint8_t i = 0; i <= 2; i++) {
      digitalWrite(D4, LOW);
      delay(50);
      digitalWrite(D4, HIGH);
      delay(50);
    }
    _prevTimeTwo = _currentTimeTwo;
  }
}


#endif

Credits

Fattah
15 projects • 17 followers
Electronics Engineer - Embedded System Enthusiast

Comments