Getting Started
Watering a plant isn’t too hard, there are plenty of moisture sensors on ebay and you can get a small pump easily enough also.
A few things I wanted to do:
- Program ADC outputs to be a power supply to the moisture sensor so I could plug it straight in the UNO
- Operate an external pump
- Power down the whole system periodically to save energy and allow it to run off a 9V battery
The hardest issue is the last one, I wanted to have a good battery life when running on a PP3 to make it viable anywhere in the house, not just near a plug socket, so after searching around on the web, I have included some basic functions to manage power.
Moisture first
Reading the moisture is straight forward, although you might need to adjust the watering level and time according to your plant and pump. Setting up the analog pins to supply power is done as follows:
// so we can plug sensor module straight in to UNO analog connector #define VCC_PIN A5 #define GND_PIN A4 #define DLEVEL_PIN A3 #define ALEVEL_PIN A2
pinMode(VCC_PIN, OUTPUT); digitalWrite(VCC_PIN, HIGH); pinMode(GND_PIN, OUTPUT); digitalWrite(GND_PIN, LOW); pinMode(DLEVEL_PIN, INPUT);
Pumping Water
The pump is connected through a L293NE driver chip, just using 1 quarter of the chip as we only need to run forwards – so really just acting as a big power transistor to switch the pump power supply on and off.
Chip enable – Pin 1 is unconnected – it could be pulled high to be sure to enable the chip but floats there anyway. The motor is connected between 3 (the Y output) and ground. Y output passes whatever voltage is connected to pin 8, when the A input (pin 2) is pulled high. This is connected to Arduino digital output 13 – and so this turns the motor on and off.
Piuns 4 and 5 are connected to Gnd always and the chip takes it working supply from pin 16 which is connected to Arduino regulated 5V.
I use the VIN output from the Arduino to get an unregulated supply to the pump – this gives a bit more power.
So the upshot of all that is that raising pin 13 on the Arduino truns the pump on and lowering it turns it off.
Saving Power and Sleeping
A normal 9V battery provides about 600mAh of power, the pump needs up to 3W at 5V which should give 5/3 = 0.6A consumption, so about 1 hour of pumping. We turn the pump on for 3 seconds at a time which gives us 1200 waterings. At 3 a day that would last a year. The power used by the Arduino is low – maybe 40m
The chip is put into sleep mode for 8 seconds at a time and woken by the watchdog timer – which continues to run even in the lowest power down mode of the chip. There are numerous articles on this all over the web, so I just tried to encapsulate a few useful bits:
Here’s all the source code…