Christmas-tree water-level alert
    Eric Ayars

    This program is for an ATTiny45/85 using an Arduino as programmer (see 
    but it would work just as well with an Arduino, or a PICAXE if you
    can stand to rewrite this in BASIC. If using an Arduino, you would 
    probably want to change the pin numbers in the #defines so you weren't
    on top of the serial lines (0 and 1).

    Two inputs: 
        LPin turns on a flashing LED if not pulled low by the water
        VLPin sounds a beeper if it is not pulled low.
    Two outputs:
    Run wires from pins LPin, VLPin, and ground to the water under the
    Christmas tree, adjusting their lengths so that VLPin and ground are 
    at the lowest permissible water level and LPin is somewhere above that.
    As the water level drops, the LED will start blinking when it gets low,
    and then the buzzer will start chirping it it gets very low.

    If the water level is fine, the LED blinks once every (approximately)
    ten seconds to let you know the battery isn't dead.

#define LPin 3                  // Pin for "low" warning sensor
#define VLPin 4                 // Pin for "very low" warning sensor
#define LED 0                   // LED pin
#define BUZZER 1                // Buzzer pin

// Time intervals, in ms
#define SHORT 250
#define VERY_SHORT 100
#define LONG 10000

void setup() {                
    // initialize the output pins:
    pinMode(LED, OUTPUT); 
    pinMode(BUZZER, OUTPUT);     

    // Activate the input pins:
    pinMode(LPin, INPUT);
    pinMode(VLPin, INPUT);

    // Activate all pull-up resistors:
    for (byte j=0; j<6; j++) {

    // Turn off warning devices
    digitalWrite(LED, LOW);
    digitalWrite(BUZZER, LOW);

void loop() {

    // Check status of signal lines:
    if (digitalRead(LPin)) {
        // "low" has been pulled high, so there must not be water shorting
        // it out. Set off the LED.
        digitalWrite(LED, HIGH);
        if (digitalRead(VLPin)) {
            // "Very Low" has also been pulled high, so set off the
            // buzzer as well.
            digitalWrite(BUZZER, HIGH);
        // Wait a short interval with appropriate devices on
        // Turn everything off
        digitalWrite(LED, LOW);
        digitalWrite(BUZZER, LOW);
        // Wait another short interval before repeating.

    } else {
        // Water level is fine. Just flash briefly to let everyone know
        // that the battery is still working, then wait awhile before
        // checking again.
        digitalWrite(LED, HIGH);
        digitalWrite(LED, LOW);