Garduino: an arduino-sort of- for your garden


Not really an Arduino this time, but one of the smaller chips (Attiny45) that is used to control the watering of the garden. However, the Arduino was used to develop the software Glimlach.

The schedule is quite simple: The connector at the left is attached to a humidity sensor. Together with R1 that forms a voltage divider that feeds into physical pin 3 of the Attiny which is analog pin 2. The voltage on that pin is then compared to the voltage on physical pin 2 (which is analog pin 3).

If the soil is dry, the resistance between the two poles of the sensor will go up and thus the voltage on pin 3 will drop below the value set with P1. This will make the software in the chip turn Digital I/O 2 (physical pin 7) high. This will signal LED1 and switch on SolidState relais IC2.

In fact, with this the function of the Attiny has not been much different from an Op-Amp comparator such as the 741. The circuit here however has a few extra possibilities  in combination with the software.
Garduino PCB DIY

A problem that surrounds most soil humidity sensors is corrosion. Being in the soil is not such a good environment for metals to begin with, but as a constant current is flowing through the sensor, the subsequent elektrolysis, will speed up the corrosion.
With the Jumperblock (that could be a 3 pins rather than a 4 pin block), the humidity sensor could be fed from pin 5 (Digital 0) and as such only be switched on when a reading is taken. On the print design, there is no actual jumperblock. Using the Vcc or the output of a digital pin to feed the humidity sensor is a matter of cutting a copper track at one place and adding a wire somewhere else.

Download PCB

With a microprocessor it is also very easy to let a pump flow for a set amount of time which with an opamp circuit wld require another IC such as a 555 or at least an RC network.
One could also use pin 1 (analog 1, digital 5) to attach say an LDR to ensure that all irrigation is only to take place at night or in the morning.
Also, there is a level switch attached to pin 6 (Digital 1). This switch is mounted in the water reservoir  in which the punp (M1)  is situated. When the water level goes too low -endangering the pump to run dry- the microprocessor will not switch on the pump anymore. Currently there is no optical indication for this, other than looking into the reservoir, but an LED with a 330 R resistor could be mounted parallel to R5 and thus give an optical indication of the low waterlevel. The float switch I am using is no more than a reed contact at the outside of the container and a magnet attached on a floating device. You could also use a mercury tilt switch, or a micro switch that is handled by a floating lever.

Diode D1 is a 5V1 Zenerdiode and protects the port against surges that might be carried over long lines to the humidity sensor.
The choice for the SolidState Relay was a practical one. It was rather cheap and I could not find a small relay that could switch 230 Volts with just a 5 volts input. I know they exist coz I used them before, just could not quickly find them this time and I had the 39FM22. There is always a question wether an SSR is a good choice to switch an inductive load, but it works for me

The Sensor

DIY humidity sensor
A lot has been written on how to construct a humidity sensor, but what has always worked for me is just two pieces of galvanized iron. These could be nails, but dont rule out old clothes hangers that are often from galvanized material as well.
Forget about the constructions with Gypsum: tedious, slow acting and within a few months in the soil these will fall apart.
Soldering to galvanized iron may be a bit difficult, but what works is to just file off a bit of the surface, wrap a wire around that and solder that. Then cover it with heatshrink tubing.

Though you could just stick the two pieces of  galvanized iron in the soil, I prefer to attach them to eachother so they have a somewhat fixed distance from eachother. A piece of plastic electra pipe is well suited for this.

With regard to R1, the resistor that forms the lower half of the voltage divider with the humidity sensor, 10 k works for me, but it is best to measure the resistance of the humidity sensor when it is inserted in your soil that has the proper humidity. It is best to choose a resistor that is more or less equal to the resistance of your humidity sensor in that soil. Setting P1 halfway then should already bring you fairly close to the proper switch point.

In principle it is possible to use stainless steel as well, but that is just very hard to solder on, but a clamp connection might work just fine.
It is unwise to use copper for the humidity sensor. Put two copper wires in the soil and you most likely will measure a relatively substantial voltage over these. With that the reading on your arduino could become instable and could be dependent on polarity as well. Galvanized iron has this problem to much lesser extend.

The Software
/* Garden 3
april 2012
-Humidity spike on analog pin2

* Schematic:
*[Ground] -- [10k-pad-resistor] -- | -- [Spikes] --[Vcc]

*                                Analog Pin 2
ATTiny pins
Physical  Analoog  Digital
1           0          5   Reset, PinChange Interrupt
2           3          3   INT0,3
3           2          4   INT0,4
4           Ground
5                      0   INT0,0
6                      1   INT0,1
7           1          2   INT0,2
8           Vcc
//Pin definities
int levelPin= 3; //analogue Pin3  ->Physical pin2  set level int humidPin=2;  //analogue Pin2  ->Physical pin3  Humidity sensor
int pumpPin =2;  //digital  Pin2  ->Physical pin7  Pump int emptyPin=1;  //digital  Pin1  ->Physical Pin6  waterlevel
int spikePin=0;  //Digital  Pin0  ->Physical Pin5  Extra for intermittent switching of spike
// Variable setting
int moist=0;    //float is not necessary
int irrigate=0;   //level for irrigation
int level=0;
//The following function, "setup", must always be present
void setup()
pinMode(levelPin,INPUT);// set level
pinMode(humidPin,INPUT);// measures humidity
pinMode(emptyPin,INPUT);//measures reservoir
pinMode(spikePin,OUTPUT); //for alternative supply to spikes
pinMode(pumpPin,OUTPUT);//  Output for Relay
digitalWrite(pumpPin, LOW);
digitalWrite(spikePin, LOW);
//uncomment for Attiny13

void loop() //This function must always be present
level=  digitalRead(emptyPin);
First read the level set with P1 on the levelPin and store that in 'irrigate'
irrigate=sample(levelPin); /*

Then we read the Humidity sensor.
We'll first have to set the spikePin to HIGH, in case that is used to feed the sensor. 
After the reading we set it back) If the value read ('moist') is smaller than what is 
considered dry ('irrigate') then the pump should be switched on for a specific time. 
This is done by indicating a higher treshhold for switching the pump off
digitalWrite(spikePin, HIGH);
moist=sample(humidPin);  //read humiditySensor
digitalWrite(spikePin, LOW);
level=  digitalRead(emptyPin);
if (moist <= irrigate) digitalWrite(pumpPin, level); if (moist >= irrigate+5) digitalWrite(pumpPin, LOW); // prevents  Jitter
//end loop 
int sample(int z)
/* This function will read the Pin 'z' 5 times and take an average. 
Afterwards it will be mapped by dividing by 4
int i;
int sval = 0;
for (i = 0; i < 5; i++)
{     sval = sval + analogRead(z);// sensor on analog pin 'z'
sval = sval / 5;    // average
sval = sval / 4;    // scale to 8 bits (0 - 255)
return sval;
Getting the code in the Attiny

Plenty of tutorials have been written about that, but you could have a look here.


What soil you use is up to you but you may want to consider ‘Mel’s Mix’: 1/3 of vermiculite, 1/3 of peat, 1/3 of compost

Other Uses for plants

Due to the seasonal change, this device would sit idle in the winter when I am not really growing anything and leaving a pump outside in a bucket of water is a foolish thing. However, it has a different use then. I bring it inside, replace the humidity sensor with a thermistor and use it to switch on a 25 watt lamp that I use as a heating element in my propagator.

When the temperature drops the resistance of the thermistor goes up and therefore the voltage on pin 3 drops. When that drops below the point that is set with P1, the SSR closes and the lamp switches on.

Useful links


Arduino on 1.5 Volt


Compilation of 3 previous articles with an Atmega328 running on 1.5 Volt and an adapted Led circuit around D13. Instead of an AA battery you could also use a 1.2V NiCad cell and add a solarcharger to that.

The HT7750A can deliver 200mA. The HT7750 only 100.

Note: There is a mistake in the circuit: the 4.3 Mhz Crystal should be a 16 Mhz