Creating a Smartphone-Controlled Watering Device with Raspberry Pi

Creating a Smartphone-Controlled Watering Device with Raspberry Pi

Last week, we received a lot of valuable feedback from our survey. One of the most common points raised was the desire for more interesting and practical content. Therefore, I quickly reached out to our think tank – the Tencent Cloud Evangelist team, and thus the “1001 Ways to Use Tencent Cloud” was born. We will be publishing more interesting new practices in this column. If you find it not engaging enough, feel free to continue the lively discussion in the comments section.

Creating a Smartphone-Controlled Watering Device with Raspberry Pi

In the first issue, we found a front-end engineer named adv, who loves greenery and is particularly particular about lifestyle. He has created a watering device that can be controlled via smartphone, ensuring that even when traveling, his plants are well taken care of. Let’s see how he DIYed it.

Creating a Smartphone-Controlled Watering Device with Raspberry PiAuthor of this issue: adv

A front-end engineer who skillfully uses knowledge to care for plants.

Does anyone else have the same concern? Whenever I need to go out for a few days, I always worry that my flowers at home will die from lack of water. So I thought, could I make a “semi-automatic watering device” that can be controlled by a smartphone?

When it can automatically detect soil moisture to water the plants and send watering reports to the owner’s phone, it can be called “automation”. Without further ado, let’s see what hardware and software are needed to tinker with such a device. Those in need must read patiently, as there is a lot of content.Given the complexity of the network, let’s first show my network topology diagram before we start.

Creating a Smartphone-Controlled Watering Device with Raspberry Pi

Part One

Hardware List

1. Raspberry Pi: Since I previously played with the Raspberry Pi for my home NAS, it is the first choice as the smart control center to respond to commands sent from the mobile end.

Creating a Smartphone-Controlled Watering Device with Raspberry PiRaspberry Pi 2B

2. Arduino: This device communicates very conveniently with various smart components, so I use it as the terminal to connect with the small water pump.

Creating a Smartphone-Controlled Watering Device with Raspberry Pi

Arduino Uno

3. 5V Relay: This device is connected in series with the small water pump mentioned below to control the operation and stopping of the pump.

Creating a Smartphone-Controlled Watering Device with Raspberry Pi

5V Relay

4. 5V Small Water Pump: Used to pump water. As shown, I cut off the USB head for convenience and powered it with four AA batteries. Here, a simple modification of the pump’s circuit is required to find the red wire (positive) inside, cut it short, and connect it to the normally open and common terminals of the relay.

Creating a Smartphone-Controlled Watering Device with Raspberry Pi

5V Small Water Pump

5. USB Camera: Used for taking photos at intervals and sending back monitoring images during operation.

Creating a Smartphone-Controlled Watering Device with Raspberry Pi

USB Camera

6. Other devices: a. Plastic hose, but due to the poor control of the directionality of the plastic hose, the water output effect is not good. I plan to replace it with a PVC pipe later. b. Multimeter, c. Electric soldering iron, d. Dupont wires (preferably with male-to-female connectors, female-to-female and pin headers can be homemade) in abundance.

The hardware preparations are almost done, now let’s start wiring. The Raspberry Pi is a complete Linux system (Debian system).

,so the Arduino can be mounted as a USB device and communicate via the serial port. Of course, there are other communication methods; readers can search for solutions if they want to try. The relay’s VCC and GND are connected to the Arduino power’s 5V and GND terminals, and the relay’s IN port is connected to pin 13 of the Arduino.

Part Two

Software List (excluding OS)

1. Minicom: This can set the serial port for communication between the Raspberry Pi and Arduino. Search for usage methods, and after successful setup, running lsusb should show the Arduino device.

2. Python: This is already built into the Raspberry Pi and has a library for hardware operations, making it very convenient to achieve serial communication with other devices or operate the Raspberry Pi’s own pins.

3. Nginx: Used for HTTP request forwarding on the Raspberry Pi.

4. Node.js: Used to handle HTTP requests, call Python programs for serial communication, and control the Arduino.

5. Router: Set up port forwarding on the home router to forward public HTTP requests to the Raspberry Pi’s Nginx.

6. Tencent Cloud VM: Since operations are performed via WeChat, the operations must be done on the public network.

7. Redis running on Tencent Cloud: Due to the dynamic IP generally used by home routers, the program sends requests from the home router to Tencent Cloud regularly to obtain and record this IP in Redis. When performing operations later, first get this IP from Redis, and then bind all requests to that IP.

8. Tencent Cloud Object Storage Service (COS): This step can be omitted, as COS can be used as a CDN. As a front-end engineer, I certainly need to distribute H5 pages, JS, CSS images, and other resources via CDN.

9. Important Arduino IDE: This is used to upload the Arduino program. It can be written on Windows and then uploaded to the Arduino.

Part Three

Key Implementations

1. Serial communication with Python on Raspberry Pi. readline is used to get the Arduino output, and write is used to send commands to Arduino.

2. Arduino code: Used to send commands to the relay (which is just high and low levels) to control the relay’s opening and closing.

Creating a Smartphone-Controlled Watering Device with Raspberry Pi

3. Create a simple mobile interface for control. There are many ways to implement this; I won’t list them here. I used React for the interface and Node.js for the backend. The page’s URL is generated as a QR code for scanning with WeChat (remember to add it to WeChat favorites).

4. Given that network interaction can be quite complex, here is an additional network topology diagram. In the future, any needs can be directly executed within this framework.

Creating a Smartphone-Controlled Watering Device with Raspberry Pi

The watering device is now complete. You can travel with peace of mind, as watering will be taken care of. The device will also send back monitoring images at intervals to help you determine whether to stop watering. Well, perhaps in the 2.0 automation phase, it won’t be so troublesome.

Creating a Smartphone-Controlled Watering Device with Raspberry Pi

Creating a Smartphone-Controlled Watering Device with Raspberry Pi

Listen to your voice, click on “Read the original text” below to participate in the prize-winning survey!

Leave a Comment

×