/* an arduino program using "millis" command for tea-maker.
Servo 2 at pin 8 to move the temperature sensor DS18B20 in at the start and out from the top of the cup at the end.
Servo 1 at pin 3 to move the tea bag into the cup and hold for several minutes and after that out from the cup
void setup: servo 2 at pin 8 is at start position, servo 1 is at start position
void loop: servo 2 will lower sensor DS18B20 at pin 5 measure temperature constinuously and shown in I2C LCD 16 x2 display.
When temperature is between 80 to 70 degree, servo 1 bring tea bag down to water and stay for 2 minutes. LCD display temperature and time lapses since the tea bag is inside water.
After 2 minutes, servo 1 moves to starting position.
servo 2 moves to starting position
LCD display "HAVE A CUP OF POSITIVE-TEA"
End:
*/
#include <Servo.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
Servo servo1; //tea-bag
Servo servo2; //temperature probe
OneWire oneWire(5); // DS18B20 at pin 5
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(0x27,16,2);
int servo1Pin = 3;
int servo2Pin = 8;
int temperature;
int startPosTemp = 90; //start position for temperature sensor
int startPosTea = 0; //start position for Tea bag
int PosTemp = 0; // position of temperature sensor inside water
int PosTea = 90; //position of tea bag inside the water
unsigned long startTime = 0;
unsigned long currentTime = 0;
long timeInterval = 120000; //2 minutes of tea bag inside the water
void setup() {
servo1.attach(servo1Pin);
servo2.attach(servo2Pin);
servo1.write(startPosTea);
servo2.write(startPosTemp);
Serial.begin(9600)
lcd.init();
lcd.backlight(); //Turns backlight on
sensors.begin();
}
void loop() {
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature);
delay(500);
lcd.print(" C");
servo2.write(PosTemp);
if (temperature >= 70 && temperature <= 80) {
startTime = millis();
servo1.write(PosTea);
delay(500);
for (int i = 0; i < timeInterval; i++) {
unsigned long currentTime = millis();
// or millis()
// Serial.print("Current: ");
// Serial.println(currentTime);
int count = currentTime - startTime;
// Serial.print("Differences");
// Serial.println(count);
sensors.requestTemperatures();
float temp = sensors.getTempCByIndex(0);
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print(" ");
lcd.setCursor(0, 1);
//timing countdown
//lcd.print(i);
// prints time since program started
lcd.print("Time: ");
lcd.print(count /1000.0);
lcd.print(" ");
delay(700); // wait a second so as not to send massive amounts of data
//Enter the If block only if at least 20000 millis has passed since last time
if (currentTime - startTime > timeInterval) {
// do action
servo1.write(startPosTea);
delay(500)
Servo2.write(startPosTemp);
delay(500)
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("HAVE A CUP OF");
lcd.setCursor(1, 1);
lcd.print("POSITIVI-TEA ");
lcd.print(" ");
}
}
}
}