plant watering

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
johnv
Posts: 25
Joined: Sun Nov 10, 2019 6:01 pm

Re: plant watering

Post by johnv » Sun Dec 15, 2019 6:01 pm

so its working!

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

btw cant upload the mp4 video :(
Attachments
WhatsApp Image 2019-12-15 at 6.41.43 PM.jpeg
WhatsApp Image 2019-12-15 at 6.41.43 PM.jpeg (219.49 KiB) Viewed 32805 times

johnv
Posts: 25
Joined: Sun Nov 10, 2019 6:01 pm

Re: plant watering

Post by johnv » Fri Dec 27, 2019 1:59 pm

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!

safetyfactorman
Posts: 28
Joined: Sat Jan 24, 2015 10:34 pm
Location: vancouver/kelowna/lethbridge

Re: plant watering

Post by safetyfactorman » Tue Jan 07, 2020 9:23 pm

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.

johnv
Posts: 25
Joined: Sun Nov 10, 2019 6:01 pm

Re: plant watering

Post by johnv » Thu Feb 13, 2020 7:22 pm

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?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: plant watering

Post by pythoncoder » Fri Feb 14, 2020 5:48 pm

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())
Peter Hinch
Index to my micropython libraries.

johnv
Posts: 25
Joined: Sun Nov 10, 2019 6:01 pm

Re: plant watering

Post by johnv » Sat Feb 15, 2020 6:44 pm

i apreciate your help, sir! have a great weekend!

Mikki
Posts: 9
Joined: Sun Feb 23, 2020 12:07 pm
Location: Halle (Saale), Germany

Re: plant watering

Post by Mikki » Wed Feb 26, 2020 3:40 pm

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?

User avatar
MostlyHarmless
Posts: 166
Joined: Thu Nov 21, 2019 6:25 pm
Location: Pennsylvania, USA

Re: plant watering

Post by MostlyHarmless » Mon Mar 02, 2020 5:21 am

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.

Mikki
Posts: 9
Joined: Sun Feb 23, 2020 12:07 pm
Location: Halle (Saale), Germany

Re: plant watering

Post by Mikki » Mon Mar 02, 2020 12:12 pm

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.

User avatar
MostlyHarmless
Posts: 166
Joined: Thu Nov 21, 2019 6:25 pm
Location: Pennsylvania, USA

Re: plant watering

Post by MostlyHarmless » Sat Mar 07, 2020 5:29 am

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

Post Reply