MAKER:Bobby Leonard / Translated by: Cherry
If you have some plants at home, you may encounter the problem of not being able to water them when you go out for a long holiday. The automatic irrigation system introduced below can not only solve this problem but also allow you to apply these techniques to DIY other similar automation devices.
This automatic irrigation system is implemented based on Python, which can collect sensor data through wireless network, record data, and write it into Google Sheets. It retrieves precipitation forecasts from the weather website Darksky to decide whether to activate the water pump for irrigation, and can also push data to your mobile phone.
All the code is available in the project repository. http://maker.quwj.com/project/78
The MicroPython devices mentioned in the text refer to a class of micro-devices that support running Python code, such as WemosD1 mini, NodeMCU, etc.
They are responsible for collecting data from sensors and controlling relays, accessing the Flask server set up on the Raspberry Pi via HTTP requests.
Materials List
Hardware:Raspberry Pi 3 Model B×1 NodeMCU ESP8266 Breadboard×1 Everything ESP Wemos D1 Mini×1 DFRobot Capacitive Soil Moisture Sensor×1 Ultrasonic Sensor – HC-SR04 (General)×1 Relay Module (General)×1 Resistor 1k ohm×1 DHT11 Temperature and Humidity Sensor×1 Photoresistor×1 Jumper Wires (General)×1 Breadboard (General)×1 Android Device×1
Software:Slack Google Sheets Darksky Weather API
Working Principle
1. Example of using MicroPython devices to read sensor data. 2. Using Python running on Raspberry Pi to analyze sensor data effectively.
Code examples include: measuring water level distance, controlling the relay (pump), soil moisture (capacitive soil moisture), temperature and humidity (DHT11), and light level using a photoresistor.
The code running on the Raspberry Pi (available for download in the repository) shows how to send push notifications, how data is written to Google Sheets, how to retrieve weather forecast data from Darksky, and how to monitor and exchange data with MicroPython devices using web applications via HTTP.
3. Build a code framework to allow quick and easy modifications to MicroPython projects in the future. Set MicroPython as a sub-relation, Flask as the main body, enabling complex functionalities.
This framework includes a standard boot.py for sub-items (connecting to WiFi, using NTP to set the time) and a definition list that needs to be added to the main web application to allow new devices to connect.
Features
MicroPython nodes can transmit information between them using HTTP requests, for example: one expansion board retrieves soil moisture and reports it to the server, then another expansion board requests that information and reads it to decide whether to run the pump.
Regarding water-saving issues, the pump controller can also request weather forecasts from the Raspberry Pi. When the Raspberry Pi receives this request, it will ask Darksky for the probability of precipitation in the next 24 hours.
The pump controller again uses this information to determine whether to run the pump, that is, if it rains before the watering cycle tomorrow, there is no need for the pump to run.
I used a small USB aquarium pump. It is a submersible pump, and it will burn out if it is not in water. To prevent this, I placed the HC-SR04 ultrasonic sensor at the top of the tank to measure the distance to the water surface.
If the pump operates at a low water level, the MicroPython board will request the Raspberry Pi, which will then send a notification to my phone via Slack.
This project is an extension of my previous project, similar to that one, all sensor data is saved to Google Sheets, with each board having a separate worksheet.
Notes
The code I wrote supports continuous operation, for example, if the network times out and causes the board to stop abnormally, the board will remain in deep sleep and reset until it can run again.
This is good, but it prevents you from entering commands in REPL, and the only way to change files on the expansion board seems to be to erase the flash and reinstall MicroPython, then load the edited file.
You need to change the IP address included in the MicroPython files to the IP address of any machine running the Flask server.
To use Google Sheets, you need to follow the instructions below:
https://gspread.readthedocs.io/en/latest/oauth2.html
To get the Darksky API key, go to the link below and register:
https://darksky.net/dev
To set up Slack, visit this website and register, then install it on your phone:
https://slack.com
MAKE Resources
1. NodeMCU DHT11 Temperature and Humidity Sensor, Light Sensor Wiring Diagram.
2. Soil Moisture Sensor Wiring Diagram.
3. WemosD1 Pump Controller System Wiring Diagram
Code Resources
The code running on the Raspberry Pi is available for download in the project repository. http://maker.quwj.com/project/78
rpi3pythonserver_py.py Flask service on Raspberry Pi, running in Python3 environment.
main_py_WemosD1.py Pump control program on WemosD1 mini, used to control the relay and HC-SR04 ultrasonic sensor.
main_py_nodemcu_soil.py Soil sensor driver on NodeMCU.
main_py_nodemcu_dht11.py Temperature and humidity sensor driver on NodeMCU.
This project repository address:
http://maker.quwj.com/project/78
via hackster.io/bobbyleonard84/python-micropython-iot-framework-example-auto-irrigation-6286ae
Links in the text can be clicked to read the original text at the end
More Exciting Content
UltraV: Portable UV Index Meter
DIY Smart Lock with Arduino
Step-by-step Guide to Producing Arduino Nano
DIY WI-FI Remote Control Boat with ESP32 Development Board
DIY a Hot Item: Flame Throwing Gauntlet
TensorFlow 1.9 Officially Supports Raspberry Pi!
Leave a Comment
Your email address will not be published. Required fields are marked *