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

Test Your Internet Speed Using a Raspberry Pi + Ubidots
  • 182
  • 4


Use your Raspberry Pi to measure any internet connection speed with Ubidots.

Chicken Coop Livestream
  • 1,821
  • 6

Full instructions

We have two chickens, and their coop is located at the back of the garden. I decided to build a Pi-based streaming device to check on them.

Raspberry Pi Shutdown / Restart Button
  • 5,047
  • 20

Full instructions

Building an installation project? Shut down or reboot your project safely, without a keyboard or SSH!

3d printed case for a RaspPi 3, an Arduino and a 5" display
  • 263
  • 4

Full instructions

A simple and compact frame to mount a 5" monitor, a Raspberry Pi, an Arduino, and a battery, which is extensible for other sensors.

DIY Raspberry Pi Indoor Outdoor Webcam
  • 1,280
  • 6

Full instructions

Ever want to monitor your home but don't want to buy a $100 1080p webcam? Well I did, and you can too!

MPU6050 accelerometer on Windows 10 Raspberry 2
  • 64
  • 1


Using MPU6050 accelerometer data on Windows 10 Raspberry 2 to control model's roll and pitch with DirectX12XTK and ImGui

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog