The smart plant

The smart plant Titelbild

Folgende Teile braucht ihr für die Anleitung

Smart Plant kit for the Raspberry Produktbild

Smart Plant kit for the Raspberry | 19.95€

The Smart Plant

For the next step we recommend that you have already read and built the examples for the MCP3008, the DHT11, the photoresistors and the soil moisture sensor. You will need the knowledge of each component. Our goal is to read data from each sensor and build our smart plant. You may have noticed there is also a blue LED in the package. This LED will be used to provide a visible signal to show our plants need water. We will also use a cronjob for starting the measurements but first we need to connect the sensors.

The smart plant connected to the pi

Connections Pi Connection Sensoren
3,3V Red Vertical Connections Breadboard
GND Blue Vertical Connections Breadboard
3,3V 1. Pin DHT11
GPIO4 2. Pin DHT11
Resistor 4,7kOhm Between 1. Pin DHt und 2. Pin DHT
GND 3. Pin DHT11
GND DGND
GPIO 8N CS/SHD
GPIO 10 D_IN
GPIO 9 D_OUT
GPIO 11 CLK
GND AGND
3,3V V_REF
3,3V VDD
3,3V + 10KΩ Resistor + Side 1 Photoresistor
CH0 + Side 1 Photoresistor
GND Side 2 Photoresistor
3,3V VCC Soil Moisture Sensor
Analog signal l -> CH1
GND GND Soil Moisture Sensor
GPIO21 long led leg from blue LED
GND shorter leg blue LED

smart_plant.py

import RPi.GPIO as gpio
import Python_DHT
import spidev
import time
import os

# LED
led = 21
gpio.setmode(gpio.BCM)
gpio.setup(led, gpio.OUT)

# DHT11
sensor = Python_DHT.DHT11
pin = 4

# Start SPI connection
spi = spidev.SpiDev()
spi.open(0,0)

# Read Data MCP3008
def analogInput(channel):
  adc = spi.xfer2([1,(8+channel)<<4,0])
  data = ((adc[1]&3) << 8) + adc[2]
  return data

def measurePlant():
  brightness = analogInput(0)
  soilMoisture = analogInput(1)

  if soilMoisture > 650:
    print("You really should water your plant")
    gpio.output(led, gpio.HIGH)
  else:
    gpio.output(led, gpio.LOW)

  humidity, temperature = Python_DHT.read_retry(sensor, pin)
  print("===========================")
  print("Soil Moisture: "+str(soilMoisture))
  print("Brightness: "+str(brightness))
  print("Temperature: "+str(temperature))
  print("Humidity: "+str( humidity)+"%")
  time.sleep(1.2)

measurePlant()

If you start the program, the blue LED should blink when the plant needs water. If the LED remains off, everything is okay. In line 30 you can change the limit for the soil moisture amount. You will need to tweak this value to what is necessary for your particular plant’s nourishment.

Assuming you do not want to go through the hassle of manually running this program yourself each time, the next step is to use a cronjob. A cronjob is a little helper which can be used to schedule a program to run at any time or interval we would like.By using e.g.: @hourly the program runs every hour.

crontab -e
@hourly \home\pi\schlaue_pflanze.py

Noch Fragen oder Feedback?

Bevor du eine Frage stellen kannst musst du dich zuerst Anmelden oder Regestrieren!