Simple Soil Moisture with Raspberry

 Hi,

after a long long long long long long time, i'm here again traying to do some stupid things with raspberry.

What i have done today is to implement a soil moisture to check if my plants need water. What we need is:

  • Raspberry (i used Raspberry Pi 3)
  • Soil moisture sensors (check it on Amazon)
  • Some cables

The schema to implement is this:



Connect cables in this way:
  • 5V (Raspberry) --> VCC (sensor)
  • GND (Raspberry) --> GND (sensor)
  • GPIO21 (Raspberry) --> DO (SIGNL on sensor)
almost simple.

And now this is the python code you can use to check signal coming from sensor:


#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import datetime
 
#GPIO SETUP
channel = 21
GPIO.setmode(GPIO.BCM)
GPIO.setup(channel, GPIO.IN)
 

# infinite loop
while True:
        time.sleep(1)

        msg = ""

        if GPIO.input(channel):
                # Input is high
                msg = str(datetime.datetime.now()) + " - No Water Detected!"
                print msg
        else:
                # Input is low
                msg = str(datetime.datetime.now()) + " - Water Detected!"
                print msg

        f = open("soil_moisture.log""a")
        f.write(msg)
        f.close()




This is how it looks like:







Stay tuned for next projects!!

Commenti