Soil Hygrometer

Tags

, , , , , , , , , , , , , , , , , , , , , , , ,

Hygro_plant

Now, to automate further, we would add a soil hygrometer to know if the soil is dry or wet. This is of great help as one could water plants on need basis. I bought a Y69 (made in china – also comes along Y38).

hygrometer

The connections a fairly simple.

VCC –> Raspberry PI’s 3.3V

GND –> Raspberry PI’s GND

DO –>Pin GPIO 07 of RPi

AO –>Unused

For initial testing to see if the hygrometer is fine, connect about 3 volts DC + to VCC, – to GND and check the voltage between DO and multimeter. You will see that when hygrometer probes are in the open, Voltage would be VCC. As soon as you dip the probes in water, the Voltage becomes 0.

Here is the code to test if the signal received is fine:

#!/usr/bin/env python
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
HYGRO = 7
GPIO.setup(HYGRO, GPIO.IN)
print GPIO.input(HYGRO)

We are almost done. We could use this result to take decisions on when to water the plants. This code can be combined with previous project on solenoid for a complete sensor based plant watering system.

Water the Garden!

Tags

, , , , , , , , , , , , , , , , , ,

Garden_pi

If you have seen the project on watering plants using motor, this should be fairly a minor extension.

Things you require:-

1. Potentiometer

2. Rectifier

3. Solenoid (12 V)

4. Transistors (TIP122)

5. 12 V DC (Make sure it has good current rating. (0.3 or 0.4 Amps or so should so))

6. Wires and breadboard

Q.How to choose a transistor based on solenoid?
I used TIP122, a darlington pair, whose beta is about 1000. This was more than enough to get the required current to drive solenoid. Make sure you read TP122 spec prior to connecting them in a circuit – note the order of Base, Collector and Emitter. In our case collector is connected to one end of solenoid. Base is connected to raspberry pi using a resistor. Emitter is connected to GnD.

Q. How to choose a resistor based on solenoid?
Most solenoid have wattage ratings along with Voltage ratings. One can manually measure the resistance of the coil. Given Resistance, Voltage and Wattage, determine the current. This is the current needed to drive the solenoid.
In my case this turned out to be approximately 300mA (4W, 12 V, 36 Ohm).
Raspberry pi would drive about 8mA (Base current of transistor) and given a huge B of transistor, we would get about 8mA * 1000 = 8A of collector current – that is more than good for solenoid to work!

Circuit diagram:

IMG_20140923_215456530

IMG_20140924_173751694IMG_20140924_173742608

#!/usr/bin/env python
import RPi.GPIO as GPIO, time
GPIO.setmode(GPIO.BCM)
GPIO.setup(SOLENOID_ENABLE, GPIO.OUT)
while 1:
    GPIO.output(SOLENOID_ENABLE, True)
    time.sleep(60)
    GPIO.output(SOLENOID_ENABLE, False)
    time.sleep(3600)

The above bit of code will water for 1 minute every 1 hour.
I suggest you enhance the code as per your requirements. You could also combine the code from the project on watering plants through pump to control the watering from gmail.

Image

Water plants through gmail.

Tags

, , , , , , , , , , , , , ,

This is a small project I did with Raspberry pi to be able to water plants with an email sent to do so!

Untitled

Here is what you need:

1. Rapberry pi

2. Hobby Motor

3. L293D

4. Rubber tube and some bottle cap

Below is the connection diagram between raspberry pi and motor chip (L293D). Credit goes to Adafruit lesson on DC motor. I followed the same connections and used the occidentalis software provided by them.

For the software to extract gmail titles to look for “Waterr” and water the plant, I followed the below code (With due credits to https://pythonadventures.wordpress.com/tag/gmail/)

 


import urllib2

import untangle

#from motor1 import run_motor

import RPi.GPIO as io
io.setmode(io.BCM)

in1_pin = 4
in2_pin = 17

io.setup(in1_pin, io.OUT)
io.setup(in2_pin, io.OUT)

def set(property, value):
try:
f = open("/sys/class/rpi-pwm/pwm0/" + property, 'w')
f.write(value)
f.close()
except:
print("Error writing to: " + property + " value: " + value)

set("delayed", "0")
set("mode", "pwm")
set("frequency", "500")
set("active", "1")

def clockwise():
io.output(in1_pin, True)
io.output(in2_pin, False)

def counter_clockwise():
io.output(in1_pin, False)
io.output(in2_pin, True)

clockwise()

def run_motor():
while True:
clockwise()
set("duty", "99")

FEED_URL = 'https://mail.google.com/mail/feed/atom'

def get_unread_msgs(user, passwd):
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password(
realm='New mail feed',
uri='https://mail.google.com',
user='{user}@gmail.com'.format(user=user),
passwd=passwd
)
opener = urllib2.build_opener(auth_handler)
urllib2.install_opener(opener)
feed = urllib2.urlopen(FEED_URL)
return feed.read()

##########

if __name__ == "__main__":
import getpass

# user = raw_input('Username: ')
# passwd = getpass.getpass('Password: ')
# print get_unread_msgs(user, passwd)

#make sure you change the below to yours
USER = 'USERNAME'
PASSWORD = PASSWORD'

xml = get_unread_msgs(USER, PASSWORD)
o = untangle.parse(xml)
try:
for e in o.feed.entry:
title = e.title.cdata
# print title
if title == "Waterr":
print 'Watering the raspberry pi now'
#Call the motor function here to water.
run_motor()

except IndexError:
pass # no new mail

Send email with subject as “Waterr” to see your raspberry pi watering your plants.

Untitled1

If you want to use cron tab, please follow the blog below (one of the best blogs I know on python)
http://pythonadventures.wordpress.com/2012/03/31/calling-a-python-script-from-crontab/

If you want to execute it every few minutes, it is better to use code such as below than crontab (which is better used for boot time activities).

while true:
<do something>
sleep <sometime>