#include <OneWire.h>
#include <DallasTemperature.h>
#include <Servo.h>
#include <LiquidCrystal.h>
// Pin assignments
#define TEMP_PIN 2 // Pin for temperature sensor (DS18B20)
#define RELAY_PIN 8 // Pin for relay controlling heater
#define TEA_SERVO_1_PIN 9 // Pin for tea bag 1 servo
#define TEA_SERVO_2_PIN 10 // Pin for tea bag 2 servo
#define SUGAR_SERVO_PIN 11 // Pin for sugar dispenser
#define MILK_SERVO_PIN 12 // Pin for milk dispenser
#define STIRRER_PIN 13 // Pin for stirrer motor
#define PELTIER_PIN 6 // Pin for controlling Peltier cooler
#define BUZZER_PIN 30 // Pin for buzzer or LED
#define STEEP_TIME 180000 // Steep time in milliseconds (3 minutes)
#define SUGAR_AMOUNT 1 // Amount of sugar (adjust servo angle or time)
#define MILK_AMOUNT 1 // Amount of milk (adjust pump time or servo angle)
#define STIR_TIME 5000 // Stirring time in milliseconds (5 seconds)
// Peltier cooling control
#define COOLING_TIME 30000 // Cooling time for iced tea in milliseconds (30 sec)
// Setup for the temperature sensor
OneWire oneWire(TEMP_PIN);
DallasTemperature sensors(&oneWire);
// Servo objects
Servo teaServo1;
Servo teaServo2;
Servo sugarServo;
Servo milkServo;
Servo stirrerServo;
// LCD setup (optional)
LiquidCrystal lcd(22, 23, 24, 25, 26, 27);
void setup() {
// Initialize components
Serial.begin(9600);
sensors.begin();
teaServo1.attach(TEA_SERVO_1_PIN);
teaServo2.attach(TEA_SERVO_2_PIN);
sugarServo.attach(SUGAR_SERVO_PIN);
milkServo.attach(MILK_SERVO_PIN);
stirrerServo.attach(STIRRER_PIN);
pinMode(RELAY_PIN, OUTPUT);
pinMode(PELTIER_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
// Set initial states
digitalWrite(RELAY_PIN, LOW); // Heater off
digitalWrite(PELTIER_PIN, LOW); // Cooler off
teaServo1.write(0); // Initial tea bag position
teaServo2.write(0); // Initial tea bag position
sugarServo.write(0); // Initial sugar dispenser position
milkServo.write(0); // Initial milk dispenser position
stirrerServo.write(0); // Initial stirrer position
lcd.begin(16, 2); // 16x2 LCD
lcd.print("Tea Machine Ready");
delay(2000);
}
void loop() {
// Step 1: Menu selection (Hot or Iced Tea)
lcd.clear();
lcd.print("Select Tea Type:");
lcd.setCursor(0, 1);
lcd.print("1.Hot 2.Iced");
int teaType = waitForTeaSelection(); // Wait for user selection (hot or iced)
// Step 2: Heat water to target temperature (Hot tea: 85°C, Iced tea: 70°C)
lcd.clear();
lcd.print("Heating water...");
int targetTemp = (teaType == 1) ? 85 : 70;
heatWaterToTemperature(targetTemp);
// Step 3: Steep tea for a specific time
lcd.clear();
lcd.print("Steeping tea...");
if (teaType == 1) {
steepTea(TEA_SERVO_1_PIN); // Hot tea from tea bag 1
} else {
steepTea(TEA_SERVO_2_PIN); // Iced tea from tea bag 2
}
// Step 4: Add sugar
lcd.clear();
lcd.print("Adding sugar...");
addSugar(SUGAR_AMOUNT);
// Step 5: Add milk
lcd.clear();
lcd.print("Adding milk...");
addMilk(MILK_AMOUNT);
// Step 6: Stir the tea
lcd.clear();
lcd.print("Stirring tea...");
stirTea(STIR_TIME);
// Step 7: If iced tea, activate Peltier cooling
if (teaType == 2) {
lcd.clear();
lcd.print("Cooling iced tea...");
coolTea(COOLING_TIME);
}
// Step 8: Notify the user that tea is ready
lcd.clear();
lcd.print("Tea is ready!");
notifyUser();
delay(30000); // Wait for 30 seconds before restarting the process
// Reset the system for the next tea brewing cycle
teaServo1.write(0);
teaServo2.write(0);
lcd.clear();
lcd.print("Ready for next brew");
delay(10000); // Wait before next brewing cycle
}
// Function to heat water to the target temperature
void heatWaterToTemperature(int targetTemp) {
while (true) {
sensors.requestTemperatures(); // Get temperature reading
float currentTemp = sensors.getTempCByIndex(0);
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(currentTemp);
lcd.print("C");
if (currentTemp >= targetTemp) {
digitalWrite(RELAY_PIN, LOW); // Heater off
break;
} else {
digitalWrite(RELAY_PIN, HIGH); // Heater on
}
delay(500);
}
}
// Function to steep tea
void steepTea(int teaServoPin) {
Servo teaServo;
teaServo.attach(teaServoPin);
teaServo.write(90); // Lower the tea bag into the water
delay(STEEP_TIME); // Steep for 3 minutes
teaServo.write(0); // Lift the tea bag back up
teaServo.detach();
}
// Function to add sugar
void addSugar(int amount) {
for (int i = 0; i < amount; i++) {
sugarServo.write(90); // Dispense sugar
delay(1000); // Wait 1 second (adjust for more or less sugar)
sugarServo.write(0); // Reset sugar dispenser
delay(1000);
}
}
// Function to add milk
void addMilk(int amount) {
for (int i = 0; i < amount; i++) {
milkServo.write(90); // Dispense milk
delay(1000); // Wait 1 second (adjust for more or less milk)
milkServo.write(0); // Reset milk dispenser
delay(1000);
}
}
// Function to stir the tea
void stirTea(int stirTime) {
stirrerServo.write(180); // Start stirring
delay(stirTime); // Stir for the specified time
stirrerServo.write(0); // Stop stirring
}
// Function to cool the tea (iced tea)
void coolTea(int coolingTime) {
digitalWrite(PELTIER_PIN, HIGH); // Turn on cooler
delay(coolingTime); // Cool for the specified time
digitalWrite(PELTIER_PIN, LOW); // Turn off cooler
}
// Function to notify the user that tea is ready
void notifyUser() {
for (int i = 0; i < 5; i++) {
digitalWrite(BUZZER_PIN, HIGH); // Buzzer on
delay(500);
digitalWrite(BUZZER_PIN, LOW); // Buzzer off
delay(500);
}
}
// Function to wait for user to select tea type
int waitForTeaSelection() {
// Simulated tea selection for now, return 1 for hot tea, 2 for iced tea
delay(2000); // Simulate user input delay
return 1; // Change this to 2 for iced tea simulation
}