Particle Core based project in charge of taking care of my green plants
This readme is subject to evolve.
Basically, I am using 5 parts and a few meters of water hose
- [A I2C soil moisture sensor] (https://www.tindie.com/products/miceuz/i2c-soil-moisture-sensor/)
- A Particle Core
- [A water flow meter] (http://www.dx.com/p/hs01-high-precision-flow-meter-white-black-226937#.Vo2cj1JN8Vc)
- [An USB submersible water pump] (http://www.dx.com/p/at-usb-1020-usb-powered-pet-fish-tank-submersible-pump-black-dc-3-5-9v-337664#.Vo2ckFJN8Vc)
- An USB power switch (Mosfet, Relay, Integrated switch IC, ...)
The program (at the time of writing, version is 1.0.0 ) does some kind of trivial task:
-
- Initialize the hardware
-
- Wait some time
-
- Proceed to a moisture measurement
-
- if moisture under threshold, goto 2), else goto 5)
-
- Turn the pump ON, wait until the desired quantity of water has been watered AND check that timeout did not happen
-
- Turn the pump OFF, goto 2)
The water pump will not work with a voltage under 5V. In order to power it, I soldered a wire straight on the VUSB pin of the USB header. The following picture illustrates where to solder the wire on the former Arduino Nano. You can do the same with the Particle Core diode (black component between the USB header and the VIN pin).
Actually the wiring is straightforward. Remember that on the Arduinos as well as on the Particle Core, you can not use any pin in interrupt mode. Here, I used D3 to count the pulses coming out the water flow meter. You will also notice the 2 10k pull-up resistors on the I2C bus. They are mandatory, do not forget them.
When the electric wiring is done, you can now assemble the parts along the water hose (5mm think, respective to the diameter of the Water pump and flow sensor). (Note, you can pick up some hose on Amazon like this one) .
Since revision 0.3.0, the CLI is implemented. It allows to interract with the system through the USB Serial port. Since revision 0.4.0, the luminosity sensor is supported Since revision 0.5.0, the entire project has been ported to a Particle Core
The CLI is based on two main mechanisms:
- synchronous request-response
- asynchronous notification
Responses coming from the Particle Coree are JSON objects passed as strings.
Synchronous request-response CMD list:
The requests are of the form "sw"+.
- "sw info"
- "sw temp"
- "sw moisture"
- "sw start"
- "sw lumi"
- "sw lastFeed"
Asynchronous notification:
As for the synchronous mechanism, the answers are JSON-formatted. There are a few fields, helping the JSON parsing when interracting with multiple objects: "device": "sw" (means Smart Watering) "type": "data" (this is currently the only notification type) "dataPoint": the effective datapoint included in the notification "dataValue": the value of "dataPoint"
example:
{"device":"sw","type":"data","dataPoint":"moisture","dataValue":"365"}
{"device":"sw","type":"data","dataPoint":"pump","dataValue":"ON"}
{"device":"sw","type":"data","dataPoint":"systemError","dataValue":"Pump problem"}
The Particle Core proceed to a moisture measurement every WATERING_TIMEOUT [ms], sends the measured value to the serial port, then proceed to a watering, if needed.
You can see in the following picture what the CLI looks like:
A specific "CloudRequest" ressource allows a user to interract remotely with the device. By POSTing to https://api.particle.io/v1/devices/[DEVICE_ID]/CloudRequest , user can basically interract the same way as for the CLI, with a specific request parameter: args={COMMAND}, COMMAND being one of the strings below
- "temp" : retrieve the soil temperature
- "lumi" : retrieve the ambiant luminosity
- "moisture": retrieve the soil moisture
- "start": start a watering cycle
- "lastFeed": know when happened the last watering
This will output the values for moisture. Other arguments are temp and lumi.
(iwr https://api.particle.io/v1/devices/MYDEVICEID/CloudRequest?access_token=MYACCESSTOKEN -Method POST -Body @{args="moisture"}).Content
Have a look at a sample script which retrieves all values and outputs them in tableform: https://github.com/jrnker/SmartWatering-PS-retriever/blob/master/GetSensorValues.ps1
In order to prevent any damage or flood, I made a prototype around a jug of water. The USB water pump rests at the water bottom. The end of the hose directly flows into the jug. As the moisture sensor is not put into water, it will sense something like a "dry earth", and therefore the system will trigger a watering cycle every WATERING_TIMEOUT [ms].
From code version 1.0.0, every desired feature is implemented. It's now time to enclose every wire into my brand new watering can.