Page 4 of 4

Re: plant watering

Posted: Sun Dec 15, 2019 6:01 pm
by johnv
so its working!

didnt need the relay after all, the 2n7000 did the trick!

btw cant upload the mp4 video :(

Re: plant watering

Posted: Fri Dec 27, 2019 1:59 pm
by johnv
hi, for reading the values and future stuff and controlling, maybe using an app, what is the better way to do it,

learn about mqtt, or a websocket or try building a server???

i'm kinda lost on this subject,

i think there is to much info on this subject,

i end up installing node red on the raspberry, but i would like to learn micropython, so block coding is cool to see things work but not the way i want to go,

also home assistant is a bit overkill, using yaml and implimantations of all kinds,

i like to keep it to python, so i can learn more,

so i would be gratefull, to any help offcourse ;)

i really like to know where to start with this,

kind regards, john!

Re: plant watering

Posted: Tue Jan 07, 2020 9:23 pm
by safetyfactorman
I'm not sure what your requirements are, but you may find the opensprinkler project of interest.

https://opensprinkler.com/product/opensprinkler-pi/

The software has a c/c++ verson and a python version. I am trying to learn the python version, so I can hack it.

https://rayshobby.net/mediawiki/index.p ... Background

The developers sell a card that plugs into the gpio bus on the raspberry pi. It is also possible to have remote stations. The software could be expanded to become a kinda garden scada, using remote embedded micropython devices.

Re: plant watering

Posted: Thu Feb 13, 2020 7:22 pm
by johnv

Code: Select all

import machine
from machine import Pin
from machine import ADC
import time
from time import sleep

moisture = ADC(0)        #declare soil sensor
pump = Pin(4, Pin.OUT)    #declare pin 4 as output, naming it pump
dry_value = 600                #declare dry_value as 600

while True:                                       #create infinit loop till somthing breaks the true statement
    moisture_value = moisture.read()    #when there are readings from the soil sensor put them in 'moisture_value'
    print(moisture_value)                      #show readings from soil sensor
    sleep(3)                                          #wait for ... seconds
    
    if (moisture_value < dry_value):      #when readings from soil sensor is smaller than 600 then ...
        pump.on()                                  #pin 4 high
        print(pump.value())                      #shows pin state 1 (high)
        sleep(10)                                      #wait ... seconds
        pump.off()                                     #pin 4 (0)low
        sleep(10)                                        #wait 10 seconds
    

hi i'm still struggeling, to grasp how i'm supposed to put the data in to mqtt

do i use the " print(moisture_value)" into the publish topic?

Re: plant watering

Posted: Fri Feb 14, 2020 5:48 pm
by pythoncoder
See the official examples such as this one. You will need to convert moisture_value to a bytes instance to publish it, so after connecting to your broker your publication code will look something like

Code: Select all

c.publish(b'moisture', str(moisture).encode())

Re: plant watering

Posted: Sat Feb 15, 2020 6:44 pm
by johnv
i apreciate your help, sir! have a great weekend!

Re: plant watering

Posted: Wed Feb 26, 2020 3:40 pm
by Mikki
torwag wrote:
Tue Nov 12, 2019 6:53 am

Also consider the hardware incidents. If you run out of water, the pump will be turned on after each reading. Thus, your sleep command at the end of the pump could be critical to make sure, the pump has time to cool down and does not overheat.
Same is true if the water never reaches the sensor, etc. You could add some emergency protocol, like checking if the pump was turned on 5 times in a row and if this is the case, stop the entire system as you might expect something went wrong.
I am using a small pump, to carry water from a reservoir.
To prevent the pump from running when the reservoir is empty, I am thinking about a simple sensor.
Two cables, with one end glued to the side of the container, with 1cm spacing from each other and in the height of the pump.
The other ends connected to the pyboard, one as Output and one as Input.

Code: Select all

>>> import pyb
>>> from pyb import Pin
>>> import time
>>>
>>> relay_pump=Pin('B12',Pin.OUT)
>>> res_out=Pin('C6',Pin.OUT) # reservoir sensor OUTPUT
>>> res_in=Pin('C7',Pin.IN,Pin.PULL_DOWN) # reservoir sensor INPUT
>>>
>>> def res_empty():
...     res_out.on()
...     b= not res_in.value()
...     res_out.off()
...     return b
>>>
>>> def pump(t_in_sec):
...     if res_empty():
...         return False
...     else:
...         relay_pump.on()
...         time.sleep(t_in_sec)
...         relay_pump.off()
...         return True
>>>
Would this be safe to use?
I guess, I need a resistor or a diode to prevent a short circuit?

Re: plant watering

Posted: Mon Mar 02, 2020 5:21 am
by MostlyHarmless
Never rely on your program to be fail safe. Always build safety into your circuit.

If there is no water, the whole thing should shut down.

Think like that.

Re: plant watering

Posted: Mon Mar 02, 2020 12:12 pm
by Mikki
Ok, I didn't think this way yet. Thank you.
Do you know how I could implement it in the circuit?
Or which parts I could use, so I can inform myself about these parts.

Re: plant watering

Posted: Sat Mar 07, 2020 5:29 am
by MostlyHarmless
For making sure there is water in the reservoir a simple float switch should do. That switch would be closed if there is water in the reservoir and open where there isn't. Think of the principle of a sump pump or the condensate pump of an air condition system.

The condensate pump of an air condition system activates when there is enough water in the reservoir and shuts down when the water level falls below a certain level. Everything in that thing is mechanical and electrical. Not all circuits need electronics.

If your plant watering control circuit tries to turn such a pump on while there is no water in the reservoir, nothing will happen.

The other danger is that your program or the moisture sensor might fail and leave the pump on, which could lead to flooding. That can be prevented with a similar but inverse float switch. Potted plants are often placed on trays that can prevent a disaster when one waters them a bit too much (water seeping out at the bottom of the pot). A normally closed float switch, that opens if it detects water in that tray, in series with the reservoir float switch ... you get the picture.


Regards, Jan