Intelligent Tea Maker

An intelligent device that helps you to drink a hot, tasty tea.

IntermediateFull instructions provided2 days2,672
Intelligent Tea Maker

Things used in this project

Story

Read more

Schematics

breadboard

20180209 063115 gqqakvatof

Code

TeaMaker

Python
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import logging
import os
import glob
import time
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

DVDmotorA=23
DVDmotorB=24
DVDmotorE=25

electricalKettleRelayPin= 18

waterPumpRelayPin= 17



GPIO.setup(DVDmotorA,GPIO.OUT)
GPIO.setup(DVDmotorB,GPIO.OUT)
GPIO.setup(DVDmotorE,GPIO.OUT)

GPIO.setup(electricalKettleRelayPin,GPIO.OUT)

GPIO.setup(waterPumpRelayPin,GPIO.OUT)

GPIO.output(DVDmotorA,False)
GPIO.output(DVDmotorB,False)

GPIO.output(electricalKettleRelayPin,False)

GPIO.output(waterPumpRelayPin,False)

global teaTemp
global teaStrongness

os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')

base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'

def read_temp_raw():
    f = open(device_file, 'r')
    lines = f.readlines()
    f.close()
    return lines

def read_temp():
    lines = read_temp_raw()
    while lines[0].strip()[-3:] != 'YES':
        time.sleep(0.2)
        lines = read_temp_raw()
    equals_pos = lines[1].find('t=')
    if equals_pos != -1:
        temp_string = lines[1][equals_pos+2:]
        temp_c = float(temp_string) / 1000.0
        temp_f = temp_c * 9.0 / 5.0 + 32.0
        return temp_c
	
	
def DVDmotor(cmd):

	if (cmd == 'open'):
		print ("Turning motor on")
		GPIO.output(DVDmotorA,GPIO.HIGH)
		GPIO.output(DVDmotorB,GPIO.LOW)
		GPIO.output(DVDmotorE,GPIO.HIGH)
		return

	if (cmd == 'close'):
		print ("Stopping motor")
		GPIO.output(DVDmotorA,GPIO.LOW)
		GPIO.output(DVDmotorB,GPIO.HIGH)
		GPIO.output(DVDmotorE,GPIO.HIGH)
		return

	if (cmd == 'stop'):
		GPIO.output(DVDmotorA,GPIO.LOW)
		GPIO.output(DVDmotorB,GPIO.LOW)
		GPIO.output(DVDmotorE,GPIO.LOW)
		return
		
def waterPumpMotor(cmd):

	if (cmd == 'start'):
		print ("Turning motor on")
		GPIO.output(waterPumpRelayPin,True)
		return

	if (cmd == 'stop'):
		GPIO.output(waterPumpRelayPin,False)
		return		

def makeTea() :

	print('starting !')
	temp = read_temp()
	if temp<75 :
		print('water is so cold , please wait')
		GPIO.output(electricalKettleRelayPin,True)
		while temp<75 :
			sleep(1)
			temp=read_temp()
			print (temp)
	GPIO.output(electricalKettleRelayPin,False)
	print('well,the water temp is high')
	print('start sucking water')
	GPIO.output(waterPumpRelayPin,True)
	waterPumpMotor('start')
	sleep(10)
	GPIO.output(waterPumpRelayPin,False)
	waterPumpMotor('stop')
	i=0
	while i<10:
		DVDmotor('open')
		sleep(2)
		DVDmotor('close')
		sleep(5)
		i = i+1
	DVDmotor('stop')
	print('ok')

# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                    level=logging.INFO)

logger = logging.getLogger(__name__)


# Define a few command handlers. These usually take the two arguments bot and
# update. Error handlers also receive the raised TelegramError object in error.
def start(bot, update):
	update.message.reply_text('Hi..Whats up ? you are so tired.right ? i help you to drink a good tea !')
	update.message.reply_text('Please Select your preferd tea Hot or Warm ? Enter Warm for warm and Hot for a hot tea !')


def help(bot, update):
    """Send a message when the command /help is issued."""
    update.message.reply_text('Help!')


def getInfo(bot, update):
    """Echo the user message."""
    update.message.reply_text(update.message.text)
    temp = update.message.text
    if (temp=='Warm' or temp=='Hot'):
		if(temp=='warm' or temp=='Warm'):
			teaTemp = 75
		else :
			teaTemp = 80
		update.message.reply_text('Good! Now Tell Me About Tea Stringness . Strong for a strong tea and Light for a light tea')
    else:
		if(temp=='Strong' or temp =='strong') :
			teaStrongness = 15
		else:
			teaStrongness = 10
		update.message.reply_text('Well! your tea is in making process ! please wait until i notify you !')
		makeTea()
		update.message.reply_text('Your Tea is Ready MyLord ! Please Come and Drink it')
def error(bot, update, error):
    """Log Errors caused by Updates."""
    logger.warning('Update "%s" caused error "%s"', update, error)


def main():
    """Start the bot."""
    # Create the EventHandler and pass it your bot's token.
    updater = Updater("509298071:AAEkyahfx-tEYYUeXXKph4TWQhMM8YK8iQ4")

    # Get the dispatcher to register handlers
    dp = updater.dispatcher

    # on different commands - answer in Telegram
    dp.add_handler(CommandHandler("start", start))
    dp.add_handler(CommandHandler("help", help))

    # on noncommand i.e message - echo the message on Telegram
    dp.add_handler(MessageHandler(Filters.text, getInfo))

    # log all errors
    dp.add_error_handler(error)

    # Start the Bot
    updater.start_polling()

    # Run the bot until you press Ctrl-C or the process receives SIGINT,
    # SIGTERM or SIGABRT. This should be used most of the time, since
    # start_polling() is non-blocking and will stop the bot gracefully.
    updater.idle()


if __name__ == '__main__':
    main()

Credits

Mohammad Ghamary

Mohammad Ghamary

1 project • 10 followers
Contact
Ehsan Aerabi

Ehsan Aerabi

18 projects • 42 followers
Researcher on IoT and Embedded Systems
Contact
MehrdadHosseini

MehrdadHosseini

1 project • 1 follower
Contact
Erfan Saghabashi

Erfan Saghabashi

1 project • 15 followers
Contact

Comments