DEV Community

Josh Alphonse
Josh Alphonse

Posted on

WFH: Automated plant monitor! Part 1

So I've been working from home for the last few months and I've been looking to get into a new space in tech. To start this off I crawled my way into IOT. I was amazed with all of the new IOT products coming out and they inspired me to create my own!

I remember back when I was in college a professor of mine introduced the Raspberry pi to my class. We built simple web servers and I honestly didn't revisit the device till now and that was years ago! So here we are, now in 2020! I've always wanted to grow my own herbs but I'm also lazy when it comes to maintaining plants. So I decided to build a plant monitor with a Raspberry pi 4 to help.

To get started with part 1 I collected a few items:

  • Raspberry Pi 4
  • DH11 Humidity Sensor
  • Mouse -Keyboard -Monitor -Power Supply -Python version 2.7 and up

Cool so now that we have our supplies lets boot on our raspberry Pi and use the text editor of our liking. I'm using VS Code!

First step is to connect your DH11 sensors to the correct pins on your rapsberry pi. In our case choose pin 1,4 and 6.

Alt Text

Next lets add some code!

import RPi.GPIO as GPIO
import Adafruit_DHT
import time 

dht_sensor = Adafruit_DHT.DHT11
dht_pin = 14

y1_channel = 21
GPIO.setmode(GPIO.BCM)
GPIO.setup(y1_channel, GPIO.IN)

while True:
    humidity, temperature = Adafruit_DHT.read_retry(dht_sensor, dht_pin)
    moisture_reading = GPIO.input(y1_channel)
    if moisture_reading == GPIO.LOW:
        moisture = "Sufficient Moisture."
        moisture_db = 1
    else:
        moisture = "Low moisture, irrigation needed"


    print("Sensor data: Humidity = {0:0.2f} % Temp = {1:0.2f} deg C moisture: {2}".format(humidity, temperature, moisture))



    time.sleep(10)
Enter fullscreen mode Exit fullscreen mode

I installed packages to read the GPIO sensors. Keep in mind that these are digital sensors. If you do have an analog sensor then you need an additional part to convert to digital.

The code is pretty straight forward but as we go to step two things will start to pick up.

Till next time!

Top comments (2)

Collapse
 
abdisalan_js profile image
Abdisalan • Edited

What're you going to do with that humidity reading?? :O

Collapse
 
joshalphonse profile image
Josh Alphonse

I plan on using this project to help grow microgreens and a few other herbs! Some plants need a certain humidity to strive. The DH11 also measure temperature as well so its a double wammy.