Automatically watering your plants with sensors, a Pi and webhooks
Chris Hannam, Product Engineer at Server Density.
Published on the 19th December, 2013.
Monitoring is the first step to understanding and fixing almost all issues. As a hobby I have been growing my own chillies with varied success; my issue has been remembering to water the poor things. So after countless disappointing harvests, I decided to monitor my chilli plants and automate their care as much as I could by using cheap, off the shelf components. This post will detail my experiments with electronics, APIs and the Server Density monitoring tool.
Chilli Irrigation System
My first step was to set up the technology behind the components, for this I needed a Raspberry Pi and an Arduino board. The Raspberry Pi to connect the Arduino to my network, and the Arduino to add analog inputs to the setup (which the Pi is unable to do). Although there are converters and hacks to give the Pi an analog reading, none of them seemed 100% reliable and I had an Arduino Nano spare.
Once I did that, it was time to have a look at the basic sensors I was able to attach to the Arduino board, that would help to prolong the life and improve the yield of my plants:
- Temperature – averaged from the humidity and pressure sensors
- Humidity – detect water vapour level in the air
- Moisture – two prong sensor embedded into the soil and into the water reservoir
- Light – light dependent resistor
- Pressure – barometric air pressure (not directly related to plant health but fun to graph)
When I started I had little experience with electronics and Arduino boards, luckily there are a lot of very simple guides available for using each of the sensors – let me Google that for you. I was able to mount the Arduino directly into the breadboard to make it easier to connect up the sensors. Below is a close up of the board:
The Arduino connects to the Raspberry Pi via USB and sends the data back over serial in a JSON string. The cable powers the board and provides a serial link to allow the data to come back from the sensors. A plugin then runs in the Server Density agent which reads the serial device until a complete set of readings is received (or 20 seconds is exceeded) – then the PI’s WiFi dongle allows it report the data back to Server Density for graphing.
Once the basic monitoring was in place and working reliably I added a pump to automatically water my chilli plants. It would draw water from a reservoir, that holds roughly a litre of water. From this point, I wanted the following to happen:
- When the soil becomes too dry, the pump is triggered.
- Once the water level is too low in the reservoir, I get an email alert from Server Density.
- I fill the reservoir back up.
So far this has worked very well despite some early issues with pump performance. The pump is cheap kids kit from Maplin as luckily it fitted the pipes I had.
I purchased some bhut jolokia peppers and removed the seeds to grow my own plants. With a few failed attempts with seeds already, I set out to monitor as much as possible. Using a basic incubator box I added light and temperature sensors inside and out, along with 2 moisture probes in the soil. I also added an LCD panel so I could view the internal settings at a glance.
Basic Environment Monitor
I decided to extend the monitoring to the basic environment my chillies were in. I had a spare temperature and light sensor which I hooked up to a Arduino Nano clone. With minimal code I was able to create a basic set of sensors connected to an old laptop. The laptop has the Server Density agent running and using a plugin reports the output back for graphing. The Nano I used is a Chinese clone from eBay of the Arduino. It needed the headers soldering and the bootloader to be installed, but at £4.50 instead of £20 (ish) for a genuine board, it was worth the effort.
Once the headers were soldered on, I installed the bootloader using this. It didn’t work initially, but after dropping
-U flash:w:blink.hex" from the command:
avrdude -c arduino -b 57600 -P /dev/tty.usbserial-A501S641 -p atmega328p -vv
(N.b. Connecting to the board required the latest ftdi drivers for my Mac.)
PC with light and temperature sensors reporting to Server Density
Again, I started these fairly basic projects with no real background in electronics, and owe a great deal to some of the excellent tutorials available. All of the parts were bought from eBay mostly for less than £2.
Light Dependent Resistor
For light measuring I used a basic LDR connected to the analog input on the Nano. With help of this post I was able to convert the analog 0 to 1024 value into lux. It’s an approximate measurement but close enough for this project.
Pressure Sensor BMP085
The BMP085 is a great little board that contains a pressure sensor and a temperature sensor. It must be connected to the analog pins 4 an 5 on the Nano to work correctly. Adafruit have a great tutorial for setting it up, again a simple case of hooking up power and the signal connections. Using the pressure reading and the temperature it’s possible to calculate your current altitude with your current sea level pressure but that was a bit beyond what I needed.
Soil Moisture Hygrometer
I used a basic sensor, a simple two pronged device that is pushed into soil. This model has an LED on it as well that is either red for dry or green for moist. You can use it either analog or digital mode. I used analog and connected directly to the analog port on the Nano.
This gives the percentage of water in the air using this guide. It also has a temperate sensor which I average with the temperature from the BMP085.
Sound LM393 Electret Microphone
I am waiting for this to arrive. Noise was the last aspect of the environment I could think of to measure. I am hoping to adapt this to read the decibel level and log it.
The main limiting factor at the moment is the Arduino board needs to be connected to some thing with a network connection. Ideally I would like to build in some wireless protocol so the boards could be placed anywhere. Xbee looks like a valid solution but each transmitter costs twice as much as all the sensors and Nano board combined!
Monitoring soil PH is another sensor I am investigating. I have bought this, a basic soil monitor and am hoping I can take it apart and log the soil PH values.
Thanks for reading. It’s been really fun experimenting with our software outside of the realms of infrastructure – it’s incredible how important and useful monitoring can be and how available the technology is to buy now. It’s also proven to be a rather addictive hobby – so there’s plans to keep on monitoring and I’ll keep you posted on how we get on! In the meantime, what are you monitoring with your server density account that isn’t a website or server?
- http://bildr.org/2012/11/photoresistor-arduino/?utm_campaign=automatically-watering-your-plants-with-sensors-a-pi-and-webhooks-2013-dec&utm_medium=post&utm_source=blog Light Sensor
- http://arduino.cc/?utm_campaign=automatically-watering-your-plants-with-sensors-a-pi-and-webhooks-2013-dec&utm_medium=post&utm_source=blogen/Tutorial/LiquidCrystal Liquid Crystal Display
- http://learn.adafruit.com/dht/using-a-dhtxx-sensor?utm_campaign=automatically-watering-your-plants-with-sensors-a-pi-and-webhooks-2013-dec&utm_medium=post&utm_source=blog DHT 22
- http://learn.adafruit.com/bmp085?utm_campaign=automatically-watering-your-plants-with-sensors-a-pi-and-webhooks-2013-dec&utm_medium=post&utm_source=blog/wiring-the-bmp085 BMP 085
- http://www.maplin.co.uk/p/amazing-h2o-pump-a90jg?utm_campaign=automatically-watering-your-plants-with-sensors-a-pi-and-webhooks-2013-dec&utm_medium=post&utm_source=blog Water Pump