December 5, 2010

Christmas-tree water-level sensor

UPDATE, 4 DAYS LATER: Don't build this one. The problem is the sensor: as a couple folk over at Hack-A-Day predicted, the copper sensor strips grow crystals that conduct enough to short out the sensor and give a false "ok" reading. One predicted it'd last a month, which would have been fine, but no... 4 days. That's it. I'll look into other metals (Stainless steel? Platinum? :-) ) as well as other ways of driving the sensor such as the polarity-reversal ideas mentioned by Tom and jpa below. Other suggestions are welcome too, of course.

Meanwhile, it's back to trying to just reach down into the stand to feel the water level.

-- --- ----- ------- ----------- -------------

Well, it's that time of year again. I'm not allowed to go into stores between Thanksgiving and Christmas — it's a long story involving singing Santa dolls, inflatable snowmen, and spandex bike shorts; and I won't tell it here — so since I can't go shopping I use my time more productively. Or at least I do some hardware hacking...

We have a very nice Christmas-tree stand: it's a tall, heavy, cast-iron chunk that does a wonderful job of holding our tree up. The problem is that it's difficult to determine how much water is in the stand, or whether the tree is getting any water at all. Occasionally our tree will drop all its needles, or spontaneously combust, at which point it becomes obvious that the tree needed more water; but it'd be nice to have some earlier indicator.

I discovered MIT's "High-low tech" site recently, and they have a nice tutorial on using the Arduino to program ATTiny45/85 chips. So I decided to use an ATTiny85 to make a Christmas-tree water-level sensor.

The circuit itself is dirt simple: Battery, ATTiny85, LED, resistor, buzzer, and water sensor. That's it.
The battery is a 3-cell AA battery pack (4.5V), and the buzzer is some random piezo buzzer that's been sitting in my parts bins for years.

The sensor consists of a strip of proto-board with three traces: two long, and one cut about an inch shorter. The way the water sensor works is the pull-up resistors in the ATTiny85 (about 20k) hold the inputs high by default. If a sensor wire and the ground wire are immersed, the small current through the water pulls the corresponding input low. If the water covers all three traces, that's good. If the water gets below the level of the short trace then pin PB3 goes high to indicate low water level, and if the water gets below everything then pin PB4 goes high to indicate very low water level.

The program checks the state of lines PB3 and PB4, and makes the LED blink repeatedly if the level is low. Should the level get very low, the program turns on the buzzer as well. Note: if you're making one of these yourself, make sure the difference in length between sensor wires PB3 and PB4 is enough that the tree won't go from "fine" to "buzzer" in one night. Otherwise the thing wakes you up early in the morning!

Here's the device, as I was testing it in a cup of water. The ground strip is becoming slightly discolored due to something electrochemically interesting going on, even with the low voltage and low current of this application. That discoloration should not interfere with operation, though.

To mount the device, I hot-glued magnets to the back of each piece.

The magnets make it easy to mount the sensor and circuit:
Here's the final product, tucked up under the branches at the top of the stand. It's out of sight unless you duck to look under the tree, and it's much easier to check the water level than before!

The same method could be used with an Arduino instead of the ATTiny85, and the program would work with an ATTiny45 or -25 also. (The compiled code uses fewer than 900 bytes.) If you re-wrote the program in PICAXE Basic, a PICAXE-08M would also work.


  1. First, I commend your hardware hacking. I happen to have that same tree stand and so I know the pain you feel in checking the water level.

    Here is a potentially interesting modification to your project to consider. Since most trees will have lights on them (as yours does), simply power the device from the lights instead of a battery. Then instead of a buzzer and blinking LED, have the lights on the tree do a fast flash when the tree is out of water. Then you don't even have to get close to know it is out of water!

    Great work on this!

  2. Detecting the water level with an AC signal will minimise the electrochemical deposits.

  3. The discoloration can become a real issue over time. I once used a similar construction for measuring soil moisture, and the 35µm thich copper was etched away in just a few weeks.

    There is a simple solution though: have the microcontroller reverse the polarity in a loop. For example, connect all traces to IO pins and switch which ones you measure with and which one is GND.

  4. Could this be done with just a 556 (dual 555 package) and the associated resistors and caps, instead of a microcontroller?

    It doesn't seem like it would be too difficult. The water level already acts as a switch that could just be a voltage divider circuit. When the water is high enough, enough voltage is across a very large resistor, turning the 556 off. When the water gets low, it just turns into a one resistor system, dropping all 5 (or 3.3) volts across the 556 power pin.

    Would that work?


    Change it up a bit, I've used this type of sensor before and it has worked for over a year ( i've gotta water my tomato plants... and I Forget often)... set up a simple Voltage divider and you're good.

  6. Nick,

    Yes, this could be done with a 556, eventually... but it gets complicated. By the time you've added two RC circuits, then another 556 to do the "I'm still alive" indicator, and maybe a second LED since the 556s can't use one LED for multiple purposes this easily, you're not saving much.

    Then there's the time factor: this solution took me about 2 hours, including time spent figuring out how to program the ATtiny85 with an Arduino which I'd not done before. Last time I did something this complex with a 556 was for a final project in a college course, and it took me the better part of a week.

    So yeah, a 556 would save a bit of money. About $1.50 for the chip, then less than that when you count the resistors and capacitors and LED and maybe a second 556... It really doesn't seem worth it to me!

    You have a valid point: we've all seen too many projects where someone is using a $30 Arduino in an application for which a $0.30 555 would do the job. I think using the µcontroller is reasonable here, though.


  7. I like this, with all the trouble in the world, you come up with this gem....there is hope for the world.

    I think that Joe's idea of incorporating the tree lights would be very cool; how would you do that?


  8. I like Joe's comment too: it's definitely a good idea, although much more complicated. There are probably several ways of doing it, but the one I'd try first is making an extension-cord box into which one could plug the lights and the sensor. The box would contain the µcontroller circuit, 3V supply running off the mains, and a solid-state relay to switch the lights on and off. One could wrap the box in Christmas wrapping paper, so it looked nice too.

  9. could you reverse this to monitor when like a sump pump pit is getting too full?

  10. You certainly could, although depending on the complexity of the alarm(s) you wanted this might be overkill. Just change the 'if' statements in the program to reflect the different polarity and order of the signals.

    If you just want one alarm, though, a transistor and LED is a much simpler arrangement.

  11. I've used a hacked leak frog to do the same job. Worked great!

  12. I installed a sight glass made of a brass barbed fitting and a short length of transparent flexible tubing. Just being able to see the water level is a great help. I'm considering adding an led and phototransistor to sense the level for an alarm. A fill line was also added to eliminate crawling under the tree.

  13. I just use a ping pong ball

  14. I did a similar one with a PICAXE 08M:
    It actually controlled a small table-top fountain pump, in a 5 gallon pail of water, that fed water through a 1/4" plastic tube to the stand bowl. Ran for a month to a fresh cut tree, and pumped over 50 gallons of water.


  15. Really, it is a great technique. I like this. It seems very useful. Thanks for sharing this kind of information.

  16. I have build a 2-wire sensor that does not seem to corrode much:
    1- it is out of galvanized nails
    2- I only take a few readings a day, outside of that there is no voltage over the two pins
    3- I invoke a cleaning cycle every from time to time in which I reverse polarize the pins.
    They have been in the soil for almost a year and still look fine