Automated Plant Waterer

Technologies Used:

  • Raspberry Pi
  • JavaScript
  • Express.js
  • MQTT
  • PM2

I love having plants in my home, but I often forget to water them. I wanted to create a system that would automatically water my plants based on their soil moisture levels. In addition, I wanted to be able to monitor the soil moisture levels and water the plants manually if needed. That way, I could better keep an eye on the system and make sure it was working properly over time.

The system is built using a Raspberry Pi, a soil moisture sensor, a water pump, and a relay to control the water pump. The Raspberry Pi runs an Express.js server that serves a web interface that can be called over my local network to get real-time information about whether the plant needs watering and control the water pump. Using the mcp-spi-adc and i2c-bus packages, the Raspberry Pi reads the soil moisture level from the sensor, operates the relay (and thus, the water pump), and makes the data is available through various endpoints on the Express.js server. The node-schedule package, a CRON-like scheduler for Node.js, is used to schedule the watering of the plants at specific times. I also built a Vue Native app that calls the Express.js server to control the system and view the soil moisture levels on my phone.


The biggest challenge for this project was finding the best way to control the water pump. I initially tried to control the water pump using the GPIO pins on the Raspberry Pi, but I found that the water pump drew too much current for the GPIO pins to handle. I decided to use a relay to control the water pump instead. The relay is connected to the Raspberry Pi and the water pump, and the Raspberry Pi controls the relay to turn the water pump on and off.

Another challenge was getting the moisture level data in a usable format. By default, the Raspberry Pi's GPIO pins only provide digital input/output, but most soil moisture sensors (at the hobby level, at least) provide analog output. This required the use of an analog-to-digital converter (ADC) to read the soil moisture sensor. I used an MCP-3008 ADC chip and the mcp-spi-adc package to read the soil moisture sensor from the ADC. The ADC is connected to the Raspberry Pi and the soil moisture sensor, and the Raspberry Pi reads the soil moisture levels from the ADC.

This project also made me consider what's needed to make a hardware device fault tolerant. For example, I had to consider what would happen if the Raspberry Pi lost power. After a thunderstorm, I found that the Raspberry Pi had lost power and the Express.js server didn't automatically restart when the Pi rebooted. I used the 'pm2' package to automatically restart the server when the Pi reboots.