Home Contents Start Prev 1 2 3 Next

Software

The software has three control inputs and 3 outputs. One of these (temperature) was not implemented in hardware but the software was written to support it.

The lighting in the box is meant to be the sole means of lighting. It was decided to turn the lights on for 15 hours and off for 9 to simulate a summer's day. These values are set by parameters so could easily be reprogrammed if necessary.

The soil moisure will be monitored approximately once per minute. If too dry, the pump will turn on for 2 seconds to push water into the drip feed system. The moisture level will be sampled 1 minute later and more water added if required. This mechanism allows water to seep into the soil therefore adding some hysteresis to the measure/pump control system.

The temperature will be measured approximately once per minute. If too cold, then the heating element will be turned on for 60 seconds. There will be a delay of 1 minute before the temperature is sampled again. Like the watering system, this adds some hysteresis to the system.

In pseudo-code, the software will do this:

while (true) 
{
	if (soil_is_dry) 
	{
		turn_on_pump_for_two_seconds();
	}
	
	if (too_cold) 
	{
		turn_on_heat_for_60_seconds();
	}
	
	turn_lights_on_for_15_hours();
	turn_lights_off_for_9_hours();
	
	sleep(60);
}

The above pseudo code does not illustrate background processing as all of the above checks can be done in 'parallel', the only serial constant in the sleep(60) which is used by the moisture and heat routines to wait until they check their sensors again.

The software was written in assembler, mainly so I could get to grips with the underlying PIC architecture. Since we need delays of many hours, I chose the low frequency internal clock of 32kHz as a reference and used TMR0 to generate interrupts every 60 secs. This was used as the background processing clock for many of the routines and the main control loop honoured the 60 second sleep. Using the 32kHz clock will not be at all accurrate, an external resonator would give more accurrate results but this project does not require this accurracy. What does it matter if the sensors are monitored every 90 secs rather than 60secs ? Same goes for the lighting timing, we may end up with more or less that 24 hours in the day but the relative periods of on-to-off should be the same. The full source code is listed later.

Turning it on

I planted 4 types of seed in the soil. Some carrots, some midget tomatos, some peppers and some chillis. Admittedly, this means I can only grow 12cm carrots but I thought it would be interesting to compare root vegetables versus top-growing plants.

As with most electronics/software projects, each part was tested in isolation and then assembled as a whole. I ran it through the MPLAB simulator and all looked good. The PIC was programmed in-place using the PICKIT 2 programmer. On switch-on, a relay clicked and the lights turned on. After a minute or so, the pump turned on and squirted water into the box. It kept doing this for an hour or so, every minute, a 2 second burst of the pump. I had to refill the reservoir twice; about 5 litres of water ended up being pumped into the box, I was worried something was broken. However, the pumping did eventually stop and the box was now considerably heavier!

I left it for two days and saw the inside of the box was wet with condensation. At this rate, I'd end up growing mold, if not mushrooms. I propped the lid open at one end and the condensation disapated over a day. After 5 days, the tomatoes started to sprout, followed quickly by the carrots. The chillis and peppers took a little longer but those have now started to sprout. So far, the water pump has laid dormant. At first I thought something was broken, but pulling a nail out of the soil caused the pump to operate during its one minute cycle. The soil is still damp below the surface so I need to be patient and wait. I suspect as the plants become larger and start to draw more water from the soil, the pump will see more action. Once this happens, it should be possible to put plant-food into the water reservoir occasionally to replenish minerals taken from the soil.

So it is early days yet, but it seems my mini-eden is working as expected. An interesting project that has enabled me to delve deeply into the PIC architecture and hopefully I'll never have a dead sunflower again once I modify it for outdoor use.

sprouts

A small tweak

When the soil had started to dry out, I found the pump kicked in repeatedly, many times a day. It emptied the reservoir but the soil was getting wet in patches (but not where the sensors were). On inspection, this was because the water pipe emptied back into the reservoir after the pump finished. When it kicked in again, it had to move lots of air through the pipe and only a small spash of water was hitting the soil, and then, only right next to the drippers. I installed a one-way valve in the pipe and it now pushes out a reasonable amount of water each time it pumps which gets distributed much better. I also adjusted the trimmer pot to make the soil stabilize with less water in the soil, now the seeds have taken.

Update: March 2011:

Well, it'3 nearly 4 weeks down the line and I have a problem. The plants have gone banzai, especially the chillis. They are reaching the roof of the box and spreading out in all directions. In order to keep them going, it will be necessary to replant them in separate pots. In one respect, I'm delighted that my artificial eden has worked so well. However, the whole point was to avoid the need to to any gardening, switch on and forget so I've just ended up making work for myself! I guess, I just need to choose smaller plants next time :-)

grow

February 2011


Home Contents Start Prev 1 2 3 Next