Our forum user Paddy helped me to make following codes but i have one problem when i press button liquor /wine start pouring and flowmeter start counting pulses than when it read desired pulse such as MEASURE_SMALL = 80 it send signal to first solenoid to stop pouring than there is 2nd solenoid clean = LED(25) which should turn on for 2 seconds then stop. but when it comes to turn on 2nd solenoid my relay start fluctuating. no matter what i do even led will be flickering also it does not stop in 2 seconds it keep running more than 5 seconds. there is also auto stop function to stop solenoid LED(17) in 10 seconds just incase if flowmeter failed to send pulses.
i am using resistors and NPN transistor to turn on relays.
Project : liquor / wine dispenser
any idea what could be wrong ?
Code: Select all
from gpiozero import Button, LED from signal import pause from time import sleep import threading import time pulse = Button(23) # flowmeter pin button_small = Button(18) # first button to pour small button_medium = Button(21) # 2nd button to pour medium button_big = Button(22) # 3rd button to pour big solenoid = LED(17) # first solenoid to start pour clean = LED(25) # second solenoid to clean tap and flowmeter. GAS_PAUSE = 2.0 TIME_OUT = 10.0 MEASURE_SMALL = 80 MEASURE_MEDIUM = 130 MEASURE_BIG = 200 def pour_small(): start_pour(MEASURE_SMALL) def pour_medium(): start_pour(MEASURE_MEDIUM) def pour_big(): start_pour(MEASURE_BIG) def kill_loop(): global kill_time while True: if time.time() > kill_time: solenoid.off() time.sleep(1.0) kill_time = 0.0 t = threading.Thread(target=kill_loop) t.daemon = True t.start() def start_pour(amount): global count, count_cut_off, kill_time count_cut_off = amount count = 0 solenoid.on() kill_time = time.time() + TIME_OUT def count_pulse(): global count, count_cut_off count += 1 if count >= count_cut_off: solenoid.off() clean.on() # run flow meter cleaning solenoid with food grade gas sleep(GAS_PAUSE) #keep clean mode for 2 second clean.off() # turn off clean mode enjoy drink pulse.when_released = count_pulse button_small.when_pressed = pour_small button_medium.when_pressed = pour_medium button_big.when_pressed = pour_big count = 0 count_cut_off = MEASURE_MEDIUM import tkinter as tk root = tk.Tk() root.wm_title('Wine Dispencer') button_frame = tk.Frame(root) button_frame.pack(fill=tk.X, side=tk.BOTTOM) small_button = tk.Button(button_frame, text='Pour Small', command=pour_small) medium_button = tk.Button(button_frame, text='Pour Medium', command=pour_medium) big_button = tk.Button(button_frame, text='Pour Full Glass', command=pour_big) button_frame.columnconfigure(0, weight=1) button_frame.columnconfigure(1, weight=1) button_frame.columnconfigure(2, weight=1) small_button.grid(row=0, column=0, sticky=tk.W+tk.E) medium_button.grid(row=0, column=1, sticky=tk.W+tk.E) big_button.grid(row=0, column=2, sticky=tk.W+tk.E) root.mainloop() # do this instead of the pause() used in the gpiozero code