#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 20 chars and 4 line display
LiquidCrystal_I2C lcd(0x27, 20, 4);
// Data wire is connected to the Arduino digital pin 4
#define ONE_WIRE_BUS 4
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
// Define the pins for the relays
const int isitici = 8;
const int karistirici = 9;
const int bardakAktar = 10;
const int controlPin = 11; // Pin to start the process
// Time to wait after temperature reaches 95°C
const unsigned long bekleme = 20000; // 20000 milliseconds = 20 seconds
unsigned long startTime = 0;
bool tempReached = false;
bool waitPeriod = false;
void setup(void) {
// Start serial communication for debugging purposes
Serial.begin(9600);
// Start up the library
sensors.begin();
// Initialize the LCD
lcd.init();
lcd.backlight();
// Initialize the relay pins as outputs
pinMode(isitici, OUTPUT);
pinMode(karistirici, OUTPUT);
pinMode(bardakAktar, OUTPUT);
pinMode(controlPin, INPUT_PULLUP);
// Initially turn off the relays
digitalWrite(isitici, LOW);
digitalWrite(karistirici, LOW);
digitalWrite(bardakAktar, LOW);
}
void loop(void) {
// Read temperature
sensors.requestTemperatures();
float temperatureC = sensors.getTempCByIndex(0);
// Display temperature on the LCD
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperatureC);
lcd.print(" C");
// Check if control pin is HIGH to start the process
if (digitalRead(controlPin) == HIGH) {
// Turn on the stirrer
digitalWrite(karistirici, HIGH);
// Check if temperature has reached 95°C
if (temperatureC >= 95) {
if (!tempReached) {
// Start the timer when temperature first reaches 95°C
startTime = millis();
tempReached = true;
waitPeriod = true;
}
// Turn off the heater if temperature is 95°C or above
digitalWrite(isitici, LOW);
lcd.setCursor(0, 1);
lcd.print("Isitici Kapali ");
} else {
// Keep the heater on if temperature is below 95°C
digitalWrite(isitici, HIGH);
lcd.setCursor(0, 1);
lcd.print("Isitici Acik ");
}
// During the wait period, control the heater based on temperature
if (waitPeriod) {
// Display brewing process status
unsigned long elapsedTime = millis() - startTime;
lcd.setCursor(0, 3);
lcd.print("Demlenme ");
lcd.print(elapsedTime / 1000);
lcd.print("/");
lcd.print(bekleme / 1000);
// Check if 20 seconds have passed since the temperature first reached 95°C
if (elapsedTime >= bekleme) {
// After 20 seconds, turn on the cup transfer mechanism
digitalWrite(bardakAktar, HIGH);
lcd.setCursor(0, 2);
lcd.print("Bardak Aktarildi");
delay(5000); // Let the cup transfer mechanism run for 5 seconds
digitalWrite(bardakAktar, LOW);
// Reset flags and state
digitalWrite(isitici, LOW);
digitalWrite(karistirici, LOW);
tempReached = false;
waitPeriod = false;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Bekliyor...");
// Wait for controlPin to go LOW and then HIGH again to restart the process
while (digitalRead(controlPin) == HIGH) {
delay(100);
}
}
}
} else {
// If control pin is LOW, reset all relays and flags
digitalWrite(isitici, LOW);
digitalWrite(karistirici, LOW);
digitalWrite(bardakAktar, LOW);
// Reset flags and clear the display
tempReached = false;
waitPeriod = false;
startTime = 0; // Reset startTime
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Bekliyor...");
}
delay(1000); // Wait for 1 second before next loop
}