Computer Controlled Greenhouse
Submitted by Matt J, Cumbria, UK
actually started because I had just bought a new PC leaving my old one
doing nothing but sitting in a corner. It was still a perfectly good PC
running windows XP at a reasonable speed for all but the most demanding
of applications and I was determined to use it for something. The
something was based on an idea I had some time ago to automate my
greenhouse. I got this idea after fitting electric windows which opened
and closed at the flick of a switch rather than boring old window stays.
It created an opportunity for automating the ventilation function.
As I saw it there were four areas I had to work on to make this project happen.
1. Decide exactly what I meant by automating the greenhouse. i.e. the specifications
2. Choose / design the sensors and actuators
3. Decide how to connect all these to the PC
4. Write the software
Seems simple when you say it quickly ! Anyway, setting about this in pseudo professional style here were my thoughts on the four areas starting with the specifications I decided on.
What it should do.
Temperature: The greenhouse works best when the temperature is not too hot and not too cold. Sounds simple but in the spring and autumn you can easily have a wide range of temperatures from the cold in the middle of the night (especially in March) to the excessive heat of the day when the sun is shining (greenhouse effect and all that !). Currently, when the sun’s out and its starting to cook the tomato plants I usually open all of the windows which has the desired effect. Problem is being there when they need to be opened and not being at the shops or down the pub. Also at night remembering to close them again is, shall we just say, challenging. (Probably amnesia from all that beer down the pub). So, the windows should open automatically whenever the temperature gets to a certain level and close again when it falls to a lower level.
Watering: Surprisingly plants need watering ! Not when you want to water them but actually when the soil they are in starts to dry out. Too many plants are ruined or their growth reduced due to under or over watering.. I’ve tried over the years with various drip delivery systems but they inevitably deliver either too much or too little depending on the ambient conditions and I can never adjust them to get it just right. They also suffer from the hard water in our area causing blockages due to scale build-up. The only solution is to monitor the “dryness” of the soil and automatically deliver water when it gets to an appropriate dryness. (this sounded like it was going to be a tough part of the spec to meet).
Humidity: As any greenhouse gardener will tell you the humidity of the air plays an important role in many aspects of plant welfare. Some plants are very tolerant of an arid dry air while others suffer in this environment. Whilst not as important as the soil dryness I felt that most of my past success with some plants was down to my attention paid to humidity and it should be included in any automated system. Therefore I needed to spray a mist of water into the air whenever the humidity falls below a certain measured level. (again sounded tough).
Connecting to the PC
I decided that the method of connecting my (as yet unspecified) sensors and actuators to the PC should be done first in case I had to choose specific devices to match the interface unit. I opted for a USB board product called a DigiBee which provided a convenient way of connecting 16 inputs and 16 outputs to the PC. I also purchased a switching adaptor board to go with it called a BeeDriver. Although I could have probably made the switching adaptor myself, it offered a convenient way of directly connecting higher current devices via screw terminals. I had considered finding an analogue input device for measuring temperature etc. but decide this was a bit of an overkill since all I wanted to know was when a pre-determined temperature threshold had been reached. Before I firmly decided on the digi-bee I had to be sure I could use this approach for the other inputs. What follows are my designs for all of the required sensors, confirming that all I needed was digital type inputs..
The temperature sensing device used was a simple 5k thermistor purchased from an online store (25p). The circuit I used is shown below.
The principle of the circuit is very simple. The thermistor forms one half of a voltage divider which is connected to one of the inputs to a voltage comparator (1/4 LM339 also from online store(30p) ). The other input to the comparator is a fixed voltage set by the potentiometer. Whenever the thermistor decreases in resistance due to a rise in temperature by enough to make it’s voltage divider produces a voltage greater than the reference one, the comparator output flips from 0 to 5v. This output is connected to one of the digi-bee inputs to be read by the computer. By setting the fixed voltage reference potentiometer I could set the desired switching temperature. I considered using just one threshold (i.e. comparator) but eventually decided on two to allow me to have two levels. One for detecting too hot and one for too cold, with an assumed okay region in between. This avoids the constant on-off switching around the desired temperature. One LM339 was all that was needed since it has 4 comparators in the same DIL package.
Getting a measure of humidity was not as difficult as I had anticipated. I used an SRHR233 sensor (from RS Components (£3.40)) which is a resistive humidity sensor which operates very like a thermistor. i.e. the more humid the air, the lower the resistance. This allowed me to use the same circuit I had used for the thermistor with just a change in the resistance values. Again I decided to use two comparators, one for too humid and one for too dry. This used up the two remaining comparators on the LM339 device. (not bad value for 30p). circuit shown below..
Soil Dryness Measurement
Again the object here is to determine when the soil has dried out enough to warrant watering rather than actually measuring it’s “dryness”. The principle used was based on the fact that dry soil has a much higher electrical resistance than moist soil. To evaluate this I inserted two lengths of copper wire about 10cm long and 1cm apart, into a plant pot and connected my meter to them to measure resistance. The copper wire was simply stripped out of some heavy gauge twin and earth cable I had lying around my garage.
I measured the resistance at about 80K with the soil fairly moist and , when left to dry out, the resistance increased quite sharply to several MegaOhms. Virtually an open circuit. This made the detection circuit fairly easy to design and in fact, was yet again based on the good old LM339 comparator. Essentially it is the same as the circuit used for humidity measurement except the humidity detector is replaced by two copper wires in the plant pot.
Once I had the basic moisture detection sensor working I realised that I should really use a number of them since, like most greenhouses, I have a large number of separate pots, troughs and tubs. It would however be impractical to give every pot it’s own sensor so I decided that the best approach was to put one sensor into each type and size of pot. My assumption was that pots of similar size with similar plants would dry out at similar rates. I also had to try and arrange these pots together in these similarity groups to make it easier to apply watering when that particular group needed it. In the end I managed to “make do” with just four groups (matching the number of comparators on the second LM339).
The controlled outputs in my system were the Motorised windows (3 off) and Solenoid operated water valves (5 off). As far as driving these is concerned it was simply a case of connecting them to some small pcb relays which were then connected directly to the BeeDriver terminals of the digi-bee, taking care to get the polarity correct as shown in the diagram below.
The solenoid operated water valves served two purposes. One was to turn on the plant watering system. The 4 valves corresponded to my 4 groups of “dryness monitored” plants. This allowed me to water only the group that needed it, when it needed it. The fifth water valve was to provide the humidity control. When on , this delivered water to an atomising spray mounted centrally in the apex of the greenhouse. It provided a very fine mist of water vapour, which actually proved quite effective in maintaining a good level of humidity.
When I originally installed the motorised window openers some years ago, I arranged one switch to operate all three windows together. Although I could have left it like this and just used the one control I decided to go one step further by having independent control (partly influenced by the fact that I still had 9 unused outputs on the Bee Driver unit). This would allow me to vary the amount of ventilation/cooling in three stages.
The connection of the motors was identical to the water valve solenoids except that each motor required two relays; one for forward and one for reverse operation. The motorised openers had their own built in over run limit so they automatically disconnected the appropriate input when the window was fully open or fully closed. This meant that all I had to do was ensure they were turned on for “long enough” to reach that limit. This was about 15 seconds (a job for the software).
Connecting the DigiBee to the computer was (in keeping with USB devices) very simple. There wasn’t even a driver to install since Windows XP already has the necessary HID driver installed as standard. I installed the software which was supplied with the digi-bee (LogicLab) which offered a quick way to get up and running with basic combinational logic applied to inputs and outputs. It allowed quite a flexible approach to the control of the digi-bee outputs (if input 1 is on AND input 2 is off THEN turn output 2 ON…… that sort of thing). However I wanted to do my own thing with visual basic software so I used the DLL (dynamic link library) supplied on the installation disk. As a quick test I copied the example VB program on the disk into my Microsoft compiler and fired it up. This was a very simple program that just read the inputs and set the outputs but it let me make a start without any headaches. The DLL provided three functions, InitDgb(), ReadInputs() and SetOutputs(). This was all I needed for basic I/O, the rest was up to me.
Without going into the fine details of my VB program, the basic strategy was to set up a loop which repeatedly reads the inputs, determines the next state of the outputs and then sets the outputs. Where something needed a timed turn-on (eg the window closing) I simply turned it on for a counted number of loops. The loop interval I chose was one second.
Running the System.
When I first ran my program nothing happened. After a moment or two of pondering, I realised that it was not hot enough for the windows to open, dry enough for watering or arid enough for spraying a humidifying mist. I then had to adopt a sensible approach to testing. I selectively disconnected each of the soil sensors in turn making sure the watering system came on each time. I got the hairdryer on to the thermistor and, lo and behold, the windows opened. Each in quick succession. I tried the hairdryer on the humidity sensor but nothing happened. I assumed that hot air could still be humid so I needed a better test. Disconnecting the sensor worked ok (i.e. the atomiser spray turned on) but I really had to wait for better weather to test it properly. All in all I was quite pleased with the functionality of the system but I still needed to fine tune the durations used for watering and humidifying to try and achieve a reasonable soil moisture balance. I also had to fine tune the temperature switching points for opening and closing the windows. I didn’t rush to do this, but rather waited for genuine hot weather conditions to judge the best settings.
After running it for a few months I discovered one or two issues, which I hadn’t initially considered. In the very hot weather even with all of the windows fully open the greenhouse was still too hot and needed the door open. I considered automation this but decided instead to fit a fan to increase the airflow. The four independent dryness sensors were not really enough to represent the varying conditions within different plant pots. eg some plants like tomatoes, take large amounts of moisture very quickly out of the soil while others take much less, even for the same size pots. The solution would be to either fit more sensors or arrange the plants in common pots. I have also considered fitting and controlling a space heater for early season work where the temperature, particularly at night, needs a boost. This should be straight forward but does mean that I have to use an electric heating system rather than my old favourite paraffin.
All in all I can’t say the tomatoes taste any better but the greenhouse is certainly a much more interesting place to spend some time now. I am constantly trying new ideas for sensors and controls which can be easily added to the system in the optimistic hope of getting to the stage of a fully automated greenhouse.
PC Control Ltd: All articles are publish as submitted in good faith but we do not accept any responsibility to the authenticity or content of these articles. Any article breaching copyright will be removed from this website as soon as we are made aware.