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!
Problems To Date:
1. Logistics are a nightmare; I placed my first order on July 21st, but some of the parts I ordered were UK Stock and I'm in California. This ones my fault.
2. I ordered a soil moisture sensor from DX.com, and it been 8 weeks with no delivery ...
Progress:
So, I've built the circuit to interface my soil sensor to my Raspberry Pi. I modified the previous circuit to work with the B instead of the B+ because I couldn't get my B+ to recognize my USB keyboard. It's slightly weird because the B recognizes the keyboard. I've included a picture in Figure 1 that shows the soldered modifications. I needed to access some of the GPIO of the RaspPi, and the female header is surface mount. This means I cannot solder wires to the back of the board, or simply replace the header and extend the pins through the board. Note, the picture shows one wire soldered to GPIO17, but I didn't notice that pin is reserved for the RTS of the UART. After noticing this, I moved the wire to GPIO22.
Figure 1: Modifications to the EnOcean Pi board. One wire was originally connected to GPIO17 but was moved to GPIO22.
The modified lines are soldered to the following signals:
- 3.3 Volt line
- Ground
- GPIO4 -> Pump Activation
- GPIO22 -> Low threshold (Shown as GPIO17 in the picture and modified after the picture was taken)
- GPIO27 -> High threshold
In the picture below we can see the modified EnOcean PI placed back on the Raspberry Pi header and in a case I purchased from Amazon. I really like this case because you can access the header even with the lid on. Notice I marked my wires. You only have to make that mistake once and you'll tag your wires from then on.
Figure 2: EnOcean Pi back on the Raspberry Pi in its case. Wires are labelled as they exit the case.
Figure 3 shows the modified circuit diagram of the comparator interface board. A fuse was added to the pump for protection and the header is now for a B unit instead of a B+. Some pullups were added to the output of the dual comparator (U1) because it has open collector outputs.
Figure 3: Modified circuit. A few changed were made from the original circuit: a fuse was added, pullups were added to U1's outputs, and the header was swapped for a B instead of a B+
Here is the board I made based on the circuit in Figure 3. On the left side is the heat sink for the regulator that powers the pump. The USB connector on the right side goes the pump and the round black piece below that is the fuse (removable). The IC is the dual comparator and the two potentiometers on the top control the high and low threshold levels. I have not received my soil moisture sensor from DX.com yet (it's been over 8 weeks), so I wired a potentiometer to act as the input voltage. You can see that pot in the lower right corner.
Figure 4: Constructed comparator board. Note the large heat sink. I blogged about the heat sink previously.
I included the shot in Figure 5 to show the work in wiring that circuit. I only have three wire colours in my collection right now, so red is positive voltage, black is ground, and yellow is signal. It's definitely not a stretch of the imagination to see why they call it a Rat's Nest.
Figure 5: A picture showing the bottom of the board. Not hard to figure out where the term Rat's Nest comes from ...
Having the circuit wired, it was time to write some code. I decided to start by testing with a Python script. The script below checks the input levels and decides when to water the system. I started with a flag. If we are below the low threshold, the plant needs to be watered until the high threshold is reached. The plant does not need to be watered again until the low threshold is crossed.
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setup(27, GPIO.IN, pull_up_down = GPIO.PUD_UP) #low GPIO.setup(22, GPIO.IN, pull_up_down = GPIO.PUD_UP) #high GPIO.setup(4, GPIO.OUT) #pump GPIO.output(4, GPIO.LOW) #make sure pump is off wateringFlag = 0 print("Starting Up") while True: if(GPIO.input(27) == 0): wateringFlag = 1 GPIO.output(4, GPIO.HIGH) print("Low threshold") time.sleep(30) #water for 30 seconds print("Watering") GPIO.output(4, GPIO.LOW) print("Watering Wait") If (wateringFlag == 1): if( (GPIO.input(27) == 1) and (GPIO.input(22) == 0) ): GPIO.output(4, GPIO.HIGH) print("Watering") time.sleep(30) GPIO.output(4, GPIO.LOW) print("Watering Wait") if(GPIO.input(22) == 1) wateringFlag = 0 print("Watering Finished") if(GPIO.input(22) == 0) print("High Threshold") time.sleep(300) GPIO.cleanup()
The output from the system is shown below.
pi@raspberrypi ~/openHAB $ sudo python wateringSystem.py Starting Up Low threshold Watering Watering Wait High Threshold Low Threshold Watering Watering Wait Watering Finished
So, after a little bit of debugging IT WORKS! The system waters for 30 seconds and checks for watering conditions every 5 minutes. My next steps will be to record a video of the system working and work with the openHAB GPIO binding to interface the watering system into openHAB.