Water level indicator
This is a water level indicator using an Arduino and a 9g servo motor (I am using a Tower Pro). It works for christmas trees, maybe plants, any water level really. Cut a square of cardboard approximately 4 inches by 3 inches and punch a hole big enough for the servo to stick out of. Now cut out a cardboard pointer and attach it to your servo. Color the cardboard green, yellow and red (see photos). If your servo has a bump after the part that turns, push it through so that it is being held by that. If not, make the hole bigger to fit the whole servo. Install pointer. Now the connections.
Yellow servo lead to digital pin 9.
Red servo lead to 5v and sensor lead A (this does not lead to a sensor, it is just a goes into the water).
Brown or black servo lead to Gnd and sensor lead B.
Sensor lead C to analog pin 0.
Place the three sensor leads in the water you want to measure, with sensor lead B 5mm higher than the other three. The code is the same as the code for the Arduino example "servo knob". Here is the code:
// Controlling a servo position using three leads,
//one higher than the other two.
// by Asa Ackerman-Leist
Servo myservo; // create servo object to control a servo
int wirelead = 0; // analog pin used to connect the wire lead
int val; // variable to read the value from the analog pin
myservo.attach(9); // attaches the servo on pin 9 to the servo object
val = analogRead(wirelead); // reads the value of the three wires (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
The code ends here.
Update: I added on a pump, using the servo to push a switch and turn it on, thus watering the tree. I used a mini 3v pump. You will have to find out how to attach your switch. Mine came from a cd player.