onlinegill
Posts: 45
Joined: Sun Oct 14, 2018 1:57 pm

relay or led - fluctuating

Tue Nov 20, 2018 3:01 am

Hi all,
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
Thank you

User avatar
Mortimer
Posts: 923
Joined: Sun Jun 10, 2012 3:57 pm

Re: relay or led - fluctuating

Tue Nov 20, 2018 6:48 am

My guess based on what I can see here is that there is not enough power for the cleaning solenoid to open properly.

Does the program run correctly without the solenoid connected?
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

onlinegill
Posts: 45
Joined: Sun Oct 14, 2018 1:57 pm

Re: relay or led - fluctuating

Tue Nov 20, 2018 3:04 pm

Mortimer wrote:
Tue Nov 20, 2018 6:48 am
My guess based on what I can see here is that there is not enough power for the cleaning solenoid to open properly.

Does the program run correctly without the solenoid connected?
No it does not, if i remove relays and put led”s on breadboard still clean led start flickering and not solid compare to led 1 when i blow air in flowmeter.

onlinegill
Posts: 45
Joined: Sun Oct 14, 2018 1:57 pm

Re: relay or led - fluctuating

Tue Nov 20, 2018 8:13 pm

i also tried to put flow meter, all solenoids relays on external 5v supply which mean i am not using power form raspberry pi at all i still get same issue on clean solenoid. looks like there something wrong in code. i asked another person he said following but still could not figure out what is wrong.

Looking briefly at your code, my guess is that your count_pulse method is firing after you intended for it to stop, and count is greater than count_cut_off, so it repeatedly runs:

Code: Select all

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

User avatar
Mortimer
Posts: 923
Joined: Sun Jun 10, 2012 3:57 pm

Re: relay or led - fluctuating

Wed Nov 21, 2018 11:30 am

Does the flow meter stop spinning and sending pulses when the solenoid is turned off?

I suspect that it may be that when the solenoid closes and the liquid is drained past the flow sensor, the sensor spins for a few more seconds, giving you more counts than you expect.
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

onlinegill
Posts: 45
Joined: Sun Oct 14, 2018 1:57 pm

Re: relay or led - fluctuating

Wed Nov 21, 2018 2:05 pm

Mortimer wrote:
Wed Nov 21, 2018 11:30 am
Does the flow meter stop spinning and sending pulses when the solenoid is turned off?

I suspect that it may be that when the solenoid closes and the liquid is drained past the flow sensor, the sensor spins for a few more seconds, giving you more counts than you expect.
you are right. i removed gas line which is hooked before flow meter and instead of solenoid i connected my wires to LED and my led stay solid and time is accurate that mean it turn off on time. now question is how can i stop flow meter sending more pulses when there is clean mode on ?
Thank You

User avatar
Mortimer
Posts: 923
Joined: Sun Jun 10, 2012 3:57 pm

Re: relay or led - fluctuating

Wed Nov 21, 2018 7:01 pm

I guess - change the code to ignore the flowmeter pulses after the pour has completed.
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

User avatar
Mortimer
Posts: 923
Joined: Sun Jun 10, 2012 3:57 pm

Re: relay or led - fluctuating

Thu Nov 22, 2018 10:09 am

I wouldn't mind betting on the flowmeter actually accelerating when the gas is blasted through it. I reckon the impeller inside will spin much more freely in a gaseous flow, without the viscosity of the fluid to slow it down.

So basically when the gas solenoid valve is opened until possible several seconds after the valve is closed, all pulses from the flow meter should be ignored, as there is going to be a LOT of them and coming in much faster. Which brings into question the use of a interrupt driven thread triggered by the flowmeter GPIO, outside of times when its input is important.
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

Return to “Troubleshooting”