Previous Posts:
Epidode 1: Forget Me Not: Application
Episode 2: Forget Me Not: The Best Laid Plans ...
Episode 3: Forget Me Not: Setup EnOcean with openHAB
Episode 4: Forget Me Not: Medication System
Episode 5A: Forget Me Not: Using Notify My Android with OpenHab
Episode 6: Forget Me Not: Plant Watering System Design
Episode 7: Forget Me Not: Medication System Demo
Episode 8: Forget Me Not: Using Twitter
Episode 9: Forget Me Not: Sunshine, Lollipops, and Rainbows
Episode 10: Forget Me Not: It's so hot!
Forget Me Not: Episode 11A: Watering System Construction
Forget Me Not: Episode 11B - Soil Sensor Design
Forget Me Not: Episode 12: An Update
Introduction
If you've been following along, you know that I originally wanted to use a two threshold system to activate and run my watering system. After completing my initial design, the RPiSoC boards became available to the Forget Me Not Challengers. The RPiSoc system has an analog to digital converter, something which the RPi lacks. At that point I decided to create a soil sensor that could read the soil moisture level directly and offload the rest of the complexity to software. That is, all thresholds and any other implementation would be completely in software. I spent some of my time designing a soil sensor based on a constant current source, but I lack the parts to build the sensor at this moment. So, in order to move forward I have decided to revert to the two threshold system from my original design. That soil sensor (Funduino) that I ordered from DX.com has still not showed up. It's been almost three months now. I've been in contact with them; the experience was terrible. Therefore, I used a simple resistive divider I mentioned in this post. The non-linear response won't matter for the two threshold system.
The System
Having said all that, I have a watering system that works. I just need to tweak the threshold values over the next few days. Figure 1 shows a photo collage of the Watering System.
Figure 1: [Left] Complete watering system in action (laboratory action) Sump & Reservoir, Sensor, and Watering Controller are shown. [Upper Right] Photo showing the preparation of the watering controller enclosure (Rubbermaid dish - not all of us have 3D printers ). [Middle Right] Watering Controller photo showing the internal circuitry. [Bottom Right] Soil Sensor made from a resistive divider.
The Sump & Reservoir are simply a container for water and a sump pump. The sump pump delivers water through the tubing when activated. The Water Controller consists of a custom board, Raspberry Pi B, and a TDK LAMBDA LS5012 AC to DC power supply. OpenHAB is running on the Raspberry Pi with the EnOcean Pi installed.
GPIO in OpenHAB
This part was, by far, the most time consuming and frustrating for me. I noted early in the competition some other challengers using python scripts and Arduinos to interface to the Raspberry Pi. There is an exec binding for openHAB that allows one to execute commands via the line interface. So, if you wrote a script in python or any other language you like, you could call it from openHAB. I also noted there was a GPIO binding for openHAB that allows the user to directly access the GPIO of the system. The GPIO binding essentially brings in inputs as contact switches and outputs as switches.
Enabling GPIO
1. To enable the gpio binding you have to copy two files into the addons folder:
- org.openhab.io.gpio-1.5.0.jar
- org.openhab.binding.gpio-1.5.0.jar
2. You also have to modify the config file as such:
################################# GPIO Binding ##################################### # Optional directory path where "sysfs" pseudo file system is mounted, when isn't # specified it will be determined automatically if "procfs" is mounted gpio:sysfs=/sys # Optional time interval in miliseconds when pin interrupts are ignored to # prevent bounce effect, mainly on buttons. Global option for all pins, can be # overwritten per pin in item configuration. Default value if omitted: 0 gpio:debounce=10
3. Add this line to your start.sh file after java
-Djna.boot.library.path=/usr/lib/jni
The Implementation
I added three items to my system. A pump control, low threshold, and high threshold. The code added to my item file is as follows:
Switch PumpControl "Pump Status" { gpio="pin:4 debounce:10 activelow:no" } Contact LowThreshold "Low Threshold" { gpio="pin:27 debounce:10" } Contact HighThreshold "High Threshold" { gpio="pin:22 debounce:10" }
Again, note the PumpControl is an output and it's a Switch in the code. The three attributes setup GPIO pin 4 as active high with a debounce of 10 ms. The switch has two states: ON and OFF. For example, to check the state against ON, try:
if (PumpControl.state == ON)
If, however, you want to change the state use:
sendCommand(PumpControl, ON)
Here is a video demonstrating the use of the PumpControl switch through OpenHAB (warning I meant to say MOISTURE SENSOR):
Once again, I meant to say Moisture Sensor in the video ...
The LowThreshold and HighThreshold contacts are the inputs. This is where it gets weird. Contacts have two states: OPEN and CLOSED. So, in my system I'm checking to see if the LowThreshold and HighThreshold are OPEN or CLOSED. Weird right?
OPEN is OFF, and CLOSED is ON. Below is the implementation of the two threshold system. It checks every hour for watering. I will eventually modify this so that it mimics the behaviour of my original design, but this serves to illustrate the working hardware.
rule "Watering Check" when Time cron "0 34 * * * ?" then if (LowThreshold.state == OPEN) { wateringFlag = 1 sendCommand(PumpControl, ON) } if (wateringFlag == 1) { if ((LowThreshold.state == CLOSED) && (HighThreshold.state == OPEN)) { sendCommand(PumpControl, ON) } if(HighThreshold.state == CLOSED) { wateringFlag = 0 } } end rule "Watering Off" //Check every 30 seconds to turn off the pump when Time cron "15 * * * * ?" then sendCommand(PumpControl, OFF) end
I've tested this system in my "lab" using a cup of water (100% moisture) and in open air (close to 0% moisture). I'll be installing the unit on my deck in the next few days. Should be interesting to see how it behaves.
The last thing I wanted to mention was a quirk I noticed when I reboot my Raspberry Pi. The pump turns on, because gpio 4 floats. Adding a pulldown fixed the problem.