I’m a programmer/systems architect by education and by the way of winning bread, but somehow I got infected with the electronics bug 3 years ago - had a sidejob to upgrade the firmware of a LED display, got into microcontrollers, then made myself comfortable in analog.

Dave Jones has been saying in his videos - go on, make a product. So I’ve made one - even probably built “down to a price” at some extent. It is available for sale on Tindie, but read on…

plant watering alarm - averse

It’s a “plant watering alarm” - you set the dry point, then water the plant and then it starts to chirp when the plant dries out. Chirps are rare at the beginning and more frequent when the water level gets really low. It has a LED hooked up as a light sensor, so it does not make noise at night.

plant watering alarm - reverse

I decided on a capacitive moisure sensing technique as it is superior to the resistive one - the circuit is totally isolated from the soil, thus it avoids problems with corrosion, battery life, electro-chemical effects and is more reliable and repeatable in general.

The first approach I’ve tried was straightforward - charge an unknown capacitance and measure the time it takes to discharge through known resistance. This works really well when building a makeshift capacitance meter for a lab, but wasn’t really suitable for my purposes. The noise was a problem - when capacitance is so low, you have to increase MCU speed and add a rather big resistance to get some decent dynamic range. This high impedance point picks up all kinds of noise that might be impossible to filter out because of aliasing. Another drawback - high speed and filtering in software implies external oscillator - this affects the battery life and BOM cost.

So I went with another capacitive sensing approach where a square wave is fed into a RC filter formed by known resistance and unknown capacitance as a wide track on the board. The filtered waveform is triangle-like. It is a half-wave rectified by a diode and stored into a capacitor that has a bleeder resistor. When the capacitance changes, the peaks of the waveform become lower or higher resulting in changing voltage in the storage capacitor. Go to http://wemakethings.net/2012/09/26/capacitance_measurement/ for a more detailed explanation. The concept can be illustrated by this picture:

Capacitance measurement idea

I’m feeding 1MHz from an internal RC oscillator of attiny44 micro. I measured the capacitance of my sensor to be around 4.3pf - 75pf, used the same board to measure this, so the measurements might be a bit off. I had put some effort to calculate and measure the most optimal filter resistor value, so I would get the widest range and then I looked for the shape of the sensor track so it would give me more range. I decided against using an opamp as I was building this down to a price - as much as possible had to be done in micro and in discrete analog. The range I got is 508 - 833 LSB which is pretty enough for the application.

Isolating the circuit from soil moisture was a bitch - water seeps through almost any stuff eventually. The combination I found to be pretty OK was a piece of scotch tape and some varnish spray designed for electronics. Epoxy works too, but it lowers the range and the thing is not really designed to be covered in it.

The great and interesting challenge was to extend the battery life. I set myself a goal of 1 year on a cr2032 battery and learned many tricks how to get the current consumption down, this was real fun: * slow down CPU speed when doing the slow stuff * sleep all the time with only a watchdog running; I used watchdog interrupt to wake up every 8 seconds and do the measurements every 255 wakeups * turn off every peripheral that is not used at the moment * have a switch to turn stuff external to the microcontroller off

The Chirp can operate in two modes - alarm mode and sensor mode. In sensor mode it does not conserve battery at all and is providing capacitance measurements by I2C. I used a reset trick to switch the modes - the button on the board is tied to reset line, the micro saves a flag in eeprom on boot and clears it after a second. If the flag is not present - the Chirp goes into the sensor mode, so double-clicking the button makes the Chirp a dumb sensor.

Regarding the PCB manufacturing - waiting for orders from China, screwing up with gerber files and playing mail ping-pong between the Western New Year and the Chinese New Year - man, what can I say - this stuff is depressing.

All said, I’m not certain what path should I take with it - the most win for the project would be if it would get cloned by the Chinese, otherwise it’s a somewhat pricy and somehow silly widget. I’m selling it prebuilt on Tindie, but it might be more fun for people to build one, so I’m considering to sell it as a kit, but SMD kits is another silly idea - let me know what you think.

I’m using it myself for a half a year and surprisingly - it still works on the same battery. The flowers have died though, but for other reasons.

plant watering alarm

Published June 07 2013 by miceuz