Things used in this project

Hardware components:
R8326274 01
Raspberry Pi 2 Model B
Soil Humidity sesnor
Temperature and Humidity sensor
Ambient light sensor
Water pump
Philips hue 431650 bulb single lg. v370602166
Philips hue


Img 0188


Watering systemPython
This is a code that run as a service on Raspberry Pi 2
#! /usr/bin/env python

# Python Code to communicate with MCP3008

#Import SpiDev wrapper and Sleep function from time
import sys
import spidev
import Adafruit_DHT as dht
from datetime import datetime
from time import sleep
from phue import Bridge
import logging
import RPi.GPIO as GPIO
GPIO.setup(23, GPIO.OUT)
GPIO.setup(24, GPIO.OUT)
# Taken from phue Basic Usage guide
b = Bridge('') # IP of my Hue Bridge
# If the app is not registered and the button is not pressed,
# press the button and call connect() (this only needs to be run a single time)
#Establish SPI Connection on Bus 0, Device 0
spi = spidev.SpiDev(),0)
filename = "results.txt"
def check_plant(channel):
    #Check valid channel
    if((channel > 7) or (channel < 0)):
        return -1

    #Perform SPI transaction and store returned bits in 'r'
    r = spi.xfer([1, (8+channel)<<4, 0])
    #Filter data bits from returned bits
    adcout = ((r[1]&3) << 8) + r[2]
    percent = 100-int(round(adcout/10.23))
    #Print 0-1023 and percentage
    #print("ADC Output: {0:4d}   Percentage: {1:3d}%".format(adcout,percent))
    #print # of flower & soil humidity %. % is reversed.
    print("Flower ", channel, ". Soil humidity is: {1:3d}%".format(adcout,percent))
    print >> f, 'Flower ', channel, ". Soil hunidity is: {1:3d}%".format(adcout,percent)
    #checking level of soil humidity
    if(percent < 55):
        print("Soil humidity is low. Activating water pump.")
        print >> f, "Soil humidity is low. Activating water pump."
        GPIO.output(23, 1)
        GPIO.output(24, 0)
        #waiting for 5 seconds to complete watering & switching pump off
        GPIO.output(23, 0)
        GPIO.output(24, 0)
        print("Plant watering is finished")
        print >> f, "Plant watering is finished"
        print("Soil humidity is ok.")
        print >> f, "Soil humidity is ok."
def check_temperature(channel):
    #Check valid channel
    if((channel > 7) or (channel < 0)):
        return -1
    #Reading parametrs from temperature/hunidity sensor
    h,t = dht.read_retry(dht.DHT11, 4)
    print ("Temp={0:0.1f}*C Humidity={1:0.1f}%".format(t,h))
    print >>f, "Temp={0:0.1f}*C Humidity={1:0.1f}%".format(t,h)
def check_light(channel):
    #Check valid channel
    if((channel > 7) or (channel < 0)):
        return -1

    #Perform SPI transaction and store returned bits in 'r'
    r = spi.xfer([1, (8+channel)<<4, 0])
    #Filter data bits from returned bits
    adcout = ((r[1]&3) << 8) + r[2]
    percent = 100-int(round(adcout/10.23))
    #checking current time
    current_hour =
    #if it is night - printing a message that light are switched off
    if((current_hour < 10) or (current_hour > 21)):
        print("Light is swithced off during night")
        print >> f, "Light is swithced off during night"
        b.set_light(6,'on', False)
        #If amount of light is low - switching on the light bulb to max brightness
        if(percent < 70):
                b.set_light(6,'on', True)
                b.set_light(6,'bri', 254)
                print("Lights are switched on")
                print >> f, "Lights are switched on"
        #else - switchng light bulb off
                b.set_light(6,'on', False)
                print("Lights are switched off")
                print >> f, "Lights are switched off"
while True:
    f = open(filename, 'w')
    print >> f,



Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback


Similar projects you might like

Sorting Hat: Circuit Playground Express Starter Project
  • 136
  • 3


Which Hogwarts House do you belong in? A quick first project for this beginner-friendly board from Adafruit.

Winforms+Lattepanda=Control Everything With Your Mouse!
  • 1,151
  • 7


If you use other things instead of the LED, then you can use your mouse to control everything!!

Housing for Raspberry Pi 3
  • 203
  • 3

Full instructions

The housing I used for my Raspberry Pi I bought broke during assembly due te bad design. Ik can make a better version of it.

Secure Simple Remote Access for Camera Viewing
  • 2,796
  • 12

Full instructions

Turn your RPi into a full featured camera with remote access, end2end encryption, and easy user enrollment.

One Small Step For a Yedi, One Giant Leap for Mankind
  • 168
  • 4

Work in progress

Counting your steps with the Calliope Mini. Hearing the Star Wars theme is always a huge motivator.

Smartphone Connected Home Door Lock
  • 434
  • 4

Full instructions

An internet-connected, servo-driven deadbolt actuator that can be operated remotely using a smartphone.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login