I tried to automate the watering of the planter with Raspberry Pi

Overview

GROVE's soil moisture sensor and AD converter (MCP3002) measure the amount of water contained in the soil every 5 minutes, and when the amount of water falls below the threshold, operate the kerosene pump to pump water from the water tank and use it as a planter. I tried to make water.

circuit diagram

water_system_回路図.png

IMG_3902.jpg

Read the value of the soil moisture sensor

The moisture sensor outputs a voltage (analog value) according to the amount of moisture. Since the Raspberry Pi can only input digitally, it needs to be converted to digital data and read by an AD converter. This time, I used MCP3002 for the AD converter. For the connection between Raspberry Pi and MCP3002, I referred to the following article. Connect the A / D converter MCP3002 to the Raspberry Pi

The following materials were used for the soil moisture sensor. https://www.switch-science.com/catalog/814/ The sensor is inserted by making a hole in the planter. IMG_4033.jpg

Operate the kerosene pump to water

IMG_4032.jpg

For the watering part, the kerosene pump is operated by connecting the electric kerosene pump and GPIO and turning on GPIO. However, the motor operates the pump, but if you try to operate the motor with GPIO of Raspberry Pi, you will run out of power, so make sure to operate the kerosene pump with the power supply of the battery box of the kerosene pump that is attached from the beginning. Then, the relay switch is controlled from the Raspberry Pi. In order to be able to control GPIO of Raspberry Pi with Python, I referred to the following article. [LED blinking in GPIO (Python)](http://make.bcde.jp/raspberry-pi/gpio%E3%81%A7led%E3%81%AE%E7%82%B9%E6%BB%85python /)

Python code

Measure the water content in the soil every 5 minutes, and when it falls below the threshold, operate the kerosene pump for 30 seconds. If the water tank is empty, the water content will not recover even if the kerosene pump is operated, and after 5 minutes, it will try to water, which will waste the battery of the kerosene pump. Once I water it, I try not to water it for a while.

water.py


import spidev
import time
import datetime
import subprocess
import RPi.GPIO as GPIO

wet_low = 450
water_check_enable = True
water_wait_count = 0
check_reset = 10


def write_log(log_text):
	f = open("/var/log/water","a")
	d = datetime.datetime.today()
	f.write (d.strftime("%Y-%m-%d %H:%M:%S" + "," + log_text + "\n" ))
	#print log_text
	f.close()

def read_wet_level():
	spi=spidev.SpiDev()
	spi.open(0,0)
        resp=spi.xfer2([0x68,0x00])
        value=(resp[0] * 256 + resp[1]) & 0x3ff
        write_log("wet_level:" + str(value))
        spi.close()
        return value

def water():
	write_log("***** water start *****")

	GPIO.setmode(GPIO.BOARD)
	GPIO.setup(16,GPIO.OUT)
	GPIO.output(16,True)
	time.sleep(30)
	GPIO.output(16,False)
	GPIO.cleanup()

	write_log("***** water end *****")

while True:
	wet_level =read_wet_level()

	if water_check_enable == False:
		water_wait_count += 1
		if water_wait_count > check_reset:
			water_check_enable = True
			water_wait_count = 0

	if wet_level < wet_low and water_check_enable == True:
		water_check_enable = False
  		water()
	time.sleep(300)
	

Recommended Posts

I tried to automate the watering of the planter with Raspberry Pi
I tried to move ROS (Melodic) with the first Raspberry Pi (Stretch) at the beginning of 2021
I tried to build an environment of Ubuntu 20.04 LTS + ROS2 with Raspberry Pi 4
I tried to find the entropy of the image with python
I tried to find the average of the sequence with TensorFlow
I tried running Movidius NCS with python of Raspberry Pi3
I tried using the DS18B20 temperature sensor with Raspberry Pi
I tried to automate [a certain task] using Raspberry Pi
I sent the data of Raspberry Pi to GCP (free)
When I tried to do socket communication with Raspberry Pi, the protocol was different
I tried to automate the article update of Livedoor blog with Python and selenium.
I tried to estimate the pi stochastically
I tried to expand the size of the logical volume with LVM
I tried to improve the efficiency of daily work with Python
I wanted to run the motor with Raspberry Pi, so I tried using Waveshare's Motor Driver Board
I tried to save the data with discord
I tried to find 100 million digits of pi
I tried L-Chika with Raspberry Pi 4 (Python edition)
I tried to touch the API of ebay
I tried to correct the keystone of the image
I tried to automate sushi making with python
I tried to predict the price of ETF
I tried to vectorize the lyrics of Hinatazaka46!
I tried to get the authentication code of Qiita API with Python.
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
I tried to automatically extract the movements of PES players with software
I tried to analyze the negativeness of Nono Morikubo. [Compare with Posipa]
I tried to streamline the standard role of new employees with Python
I tried to visualize the text of the novel "Weathering with You" with WordCloud
I tried to get the movie information of TMDb API with Python
I tried to predict the behavior of the new coronavirus with the SEIR model.
I tried to learn the sin function with chainer
I tried to extract features with SIFT of OpenCV
I tried to summarize the basic form of GPLVM
Try to visualize the room with Raspberry Pi, part 1
I tried to touch the CSV file with Python
I tweeted the illuminance of the room with Raspberry Pi, Arduino and optical sensor
I tried to solve the soma cube with python
I talked to Raspberry Pi
Take the value of SwitchBot thermo-hygrometer with Raspberry Pi
Log the value of SwitchBot thermo-hygrometer with Raspberry Pi
I tried to easily visualize the tweets of JAWS DAYS 2017 with Python + ELK
I tried to automate the 100 yen deposit of Rakuten horse racing (python / selenium)
I tried to visualize the spacha information of VTuber
I tried to erase the negative part of Meros
I tried to solve the problem with Python Vol.1
I tried to create a button for Slack with Raspberry Pi + Tact Switch
I tried to automate the face hiding work of the coordination image for wear
The story of making soracom_exporter (I tried to monitor SORACOM Air with Prometheus)
I made an npm package to get the ID of the IC card with Raspberry Pi and PaSoRi
I tried to classify the voices of voice actors
I tried to create a model with the sample of Amazon SageMaker Autopilot
I tried to automatically send the literature of the new coronavirus to LINE with Python
I tried to summarize the string operations of Python
I tried to make something like a chatbot with the Seq2Seq model of TensorFlow
I tried to put out the frequent word ranking of LINE talk with Python
I tried to visualize the characteristics of new coronavirus infected person information with wordcloud
I tried to visualize the running data of the racing game (Assetto Corsa) with Plotly
I tried to compare the processing speed with dplyr of R and pandas of Python
The 15th offline real-time I tried to solve the problem of how to write with python
I want to be notified of the connection environment when the Raspberry Pi connects to the network