Plant Watering With the Spark Core
by vipercmd in Living > Gardening
3337 Views, 8 Favorites, 0 Comments
Plant Watering With the Spark Core
This project was inspired from the original Garduino Instructable. I am using a Spark Core to publish soil moisture about my plants as well as the ability to remotely water each plant. The original Instructable shows that much more may be accomplished using these devices. I will be presenting the configuration for a single plant, the source code, and a sample interactive website. However this configuration will allow for the management of 8 plants on a single Spark.
I have several personal plants at my office and I'm not always there week-by-week to ensure that they remain watered. I could use a soil watering bulb but I'm a software developer with a huge interest in microprocessors -- so the obvious choice was to create a Garduino! However collecting information remotely from an Arduino requires additional layers of hardware and this is where the Spark Core shines with a microprocessor and WiFi built into one little package.
Parts List
I have kept the parts list to a minimum compared to the Garduino Instructable since component boards are now readily available.
Microcontroller Components:
- Spark Core with project breadboard
- One-wire 5V SPDT relay board
- One-wire soil hygrometer board with probes
- ULN2803 inverter
- Male-to-Male breadboard jumper wires
Electrical Components:
- GFCI electrical socket
- Plastic gang box
Watering Components:
- 30 GPH garden water pump
- Plastic bucket
Configure the Breadboard
The wiring of the components is very simple especially when using one-wire components. Start off by connecting the breadboard rails to the power source. While the Spark runs on 3.3V the VIN pin is directly connected to the 5V power source. Connect the VIN to the + and GND to the - on the breadboard.
Let's start off with the soil moisture probe. Connect the two wires from the probe to the sensor. The order of the two wires is not important. Then connect the VCC and GND to the + and - rails on the breadboard. Finally connect the AO pin on the probe to the A0 pin on the Spark. We'll take advantage of the analog values from the probe in the application.
Next is the relay. I added a ULN2803 to invert the signals from the Spark to the relay board. This makes it so that when the D2 pin is set HIGH that the relay flips and supplies power to the water pump. Without inverting the signal would mean that the default state of LOW would trigger the relay to start the water pump. This could cause quite a mess of overflowing water should the power become interrupted to the Spark.
Connect pins 9 and 10 of the ULN2803 to the - and + on the breadboard rails. Pin 9 is GND and Pin 10 is VCC. Next connect D2 of the Spark to Pin 1 on the ULN2803. Finally connect VCC and GND of the relay board to + and - on the breadboard and IN on the relay board to pin 18 on the ULN2803.
Installing the Firmware
The easiest way to program the Spark Core is through the Web IDE. All that needs to be changed is located at the top of the source code. If you're going to add more relays and sensors, just adjust the PLANT definition and add the corresponding pins to the plantSensors and plantRelays variables.
A delay of 2 seconds is applied when a request has been made to water a plant. I did not want to have two functions to begin and end watering should there be network lag or outage. My plants are located in my office with the soil close to the rim of the pot. My idea with the delay is to introduce water to the plant and then to monitor the soil saturation to determine if more water is required.
The status of each plant is published every 15 seconds. The data is a JSON formatted string consisting of the plant ID, a counter for the number of times it has been watered, and the current level as reported by the soil sensor.
Downloads
Sample Webservice
I have included a sample NodeJS webserver which subscribes to the status event stream. The only modification is to enter your access token. Find your access token here. You'll need to configure the dependencies and then just execute the server.js script. The plants object will be automatically populated once the Spark Core(s) begin publishing events.
$ npm install http request url eventsource
$ node server.js
Now just connect your browser to http://localhost:9000/ and view the web page. The contents will refresh every 5 seconds, however there won't be any entries in the table until the Spark has published its first status. If you press a "Water" link on the page, an authenticated request will be made for that specific Spark and the relay to begin watering that plant.
Downloads
Setting Up the Watering System
Following Steps 3 and 10 from the Garduino Instructable would be identical here so I won't cover that part again. I was able to achieve the same results by replacing the base Arduino with a Spark Core with the added benefit of built-in network connectivity at a low-cost. The network connectivity provides unlimited downstream capabilities such as: mash current weather forecasts for ideal watering, graphing between soil moisture and amount of available sunlight (I live in the Yukon which currently has less than 6 hours of daylight), etc.
The other takeaway is that I added a ULN2803 to invert the required signal to the relay to use a HIGH signal from the Spark Core rather than a LOW. The relay boards trigger when the its input pin is LOW and that is the default for all pins on the Spark Core when starting up the Core. As my plants are in an office I must ensure that a power interruption does not cause the pumps to provide water until my Spark Core program can turn them off. The solution was the ULN2803 and to keep the pins LOW from the Core and let the ULN2803 invert them to HIGH to the relay board.
The Spark Core has an amazing platform with the amount of capabilities in such a small form factor. I had originally built this project using an unused Android phone and a Sparkfun IOIO board just for the built-in networking. However the Spark Core beats that configuration in both size and price.