PICAXE - Programmable Automatic Plant Watering Device




Introduction: PICAXE - Programmable Automatic Plant Watering Device

This project is based on a 20X2 PICAXE Microcontroller. It uses a programmable timing circuit to allow the user to program repeated automatic plant watering cycles by controlling a small electric pump that feeds the plant water with 1/4 " tubing. The water reservoir can be anything you like such as a plastic bottle or rain barrel. For this particular version you need 120VAC power, but you could conceivably convert this to battery or solar power. This is a prototype and could also be reduced in size considerably in future versions.

The ideal use for this, and the reason I designed and built it, is to water plants in a plant pot to keep them alive for a few days while you are away on vacation or otherwise occupied. This is actually the second version of this project. The first version was very simple, based on the 08M2 PICAXE, it had no display and was not programmable by the user unless they had the knowledge and tools to change the program code. This new version is much more friendly and allows the user to program in the desired volume of water and time between watering with a potentiometer and set button and then displays the settings and timing status on a 2X16 LCD.

The program puts arbitrary but sensible limits on the volume of water and time. I limited the time to 72 hrs or 3 days, figuring that most plants would need a drink after 3 days. Also water volume is limited to 2.5 liters. Partly this is also to make the math on the microcontroller easier. Large numbers are more difficult to manipulate on the PICAXE because word variable size is limited to 64,000. Regardless, there is nothing stopping you from editing the program to expand these limits if you want to.


Easily programmable by the casual user
Simple programming interface and LCD display
Water volume programmable from 10 to 2500 ml in 10 ml increments
Time between watering cycles programmable between 1 min and 72 Hrs in 1 min increments
Uses 120VAC 60Hz for timing and power
Battery backup and local oscillator for circuit power and timing backup
Water proof IP65 enclosure with transparent lid
On-board PICAXE programming port
LED indicators

Step 1: Demo of the Device in Action

Step 2: Breadboard Prototype

As you see in the photograph I breadboarded this on several boards by building the different major stages of the circuit one by one and getting them working. For example, the first stage was to derive a 60 Hz square wave from the AC power line 60 Hz sine wave by building and testing a zero crossover detector.

It would be a good idea for you to do the same, not only to help you understand how the circuits work, but also in case I have made a mistake in documenting it, or in case you want to modify and improve it, or in case you want to use or experiment with slightly different component types - depending on what you have in your own junk box or parts bins.

Regardless, prototyping it on a breadboard is a good idea to confirm my design is correctly documented and to give you confidence that your own build will work.

Step 3: Circuit Diagram 1 Explanation

Here is a high level explanation of how the circuit in drawing 1 works:

120 VAC is supplied to transformer T1 which converts it to 12VAC (max 1A) centre tap, so we have 6VAC from the center tap to each side of the secondary. This is rectified with D1 and D2 and filtered by large 4700 uF capacitor C1 and this gives us about 9VDC. This is an ideal level for supplying voltage regulators U6 and U5 which provide us with regulated +5VDC and +6VDC for the logic circuit and water pump motor respectively.

A sample of the 6VAC sine wave on the secondary of T1 is supplied via R11 to the zero crossing detector circuit at top left of circuit drawing 1. R1 - R3 pad the voltage down and provide current limiting. D5 and D6 prevent overdriving of U2. This op-amp will have huge open loop gain and so any small difference between the voltages on pins 2 and 3 of the op-amp will cause the output on pin 1 to swing between ground and +5V. These transitions will take place as the incoming sine wave crosses over the zero voltage line, hence the name zero crossing detector. This has the effect of producing a 60 Hz square wave on U2 pin 1. The frequency of the incoming 60 Hz sine wave will vary slightly as the load on the overall power grid varies but over long periods of time it will, on average, be extremely accurate, so our circuit timing will also be very accurate over extended periods of time too.

The 60 Hz square wave on U2 pin 1 is then fed into U3 (74LS93) which is a shift register set up as a divide by ten counter which is then fed into another shift register U4 set up as a divide by 6 counter. So if we take 60 Hz and divide by 10 then by 6, in effect we are dividing by 60. This give us a 1 Hz square wave on the output of U4 (Q3, pin 11). This output is then fed to transistor Q1's collector via R13. Q1's base is connected to potentiometer R7 and so Q1 is controlled by the voltage on R7's wiper. So why is this set up this way?

When we lose AC power and the circuit switches to battery backup, we still want it to keep time. U1 in combination with the resistors, capacitors and crystal connected to pins 9 and 10 of U1 create a local oscillator that provides a 2 Hz signal even when we only have DC battery backup power. This 2 Hz signal is fed into the spare register on the U4 shift register to provide a 1 Hz signal derived without the benefit of the incoming 60 Hz signal. When 120VAC is present 6VAC power from T1's secondary is rectified by D4 and filtered by C4. There will be about 8 to 9 VDC across R7 when this is done. Potentiometer R7 can be adjusted so that there is approximately 4.6 to 4.8 VDC on the wiper of R7. This voltage is fed to the reset pin of U1 and to the base of Q1. So this voltage acts to indicate indirectly if AC power is present.

When AC power is present, U1's reset pin (pin 12) is held high and this local oscillator is shut off. Meanwhile Q1's base is high and it is turned on. The 1 Hz signal derived from the power line (from U4 pin 11) then appears on Q1's emitter and is fed into the microcontroller for timing. Should the incoming 120VAC power go out, then U1's reset pin will go low and it will start up and begin to supply the local timing signal. Meanwhile Q1 will be turned off. So if pin 11 of U4 happens to be in a low state at the instant AC power is lost, it cannot also pull the line supplying the local 1 Hz signal (U4 pin 12) low and prevent it from working. So when AC power is lost the voltage on R7's wiper goes to zero, U1 starts up and Q1 is shut off ensuring that the signal from U4 pin 12 keeps clocking the microcontroller unimpeded. Note that the LED indicator on U1 is connected to pin 3 the source of the 2 Hz signal. This is deliberate, if U1 is active this LED blinks at twice the rate of the normal operating 1 Hz LED so that it is visually easier to notice.

A note on setting pot R7; before connecting U1 pin 12 to the wiper of R7, connect a voltmeter from ground to R7 wiper and adjust the pot until you read between 4.6 and 4.8 VDC. This ensures we don't put too high of a voltage on U1 and damage it. Also to protect U1, we don't want to adjust the voltage all the way to +5V to give some leeway in case there is a surge on the power line causing it to exceed the 5V limit for U1.

Battery BAT1 consists of 3 AA cells in a battery holder which gives us a 4.5VDC battery backup. When the 120 VAC supply is present and +5VDC is supplied by U6, then diode D3 will be reverse biased and virtually no current will flow out of the back up battery. If the 120VAC hydro goes out, as it often does due to summer thunderstorms in my area, then the +5VDC supply from U6 will drop to the point where D3 begins to conduct and we will supply approximately 3.8VDC to the logic line. This is enough to keep our logic running for a short time, however not enough for U8 the LCD to present a display. So this battery backup is just intended to keep the microcontroller running and keeping time during short power outages or power bumps.

Step 4: Circuit Diagram 2 Explanation

Now let's discuss the circuit in drawing 2:

The 1 Hz (1 cycle per second) signal which comes in from the shift register section is connected to U7 pin C.6. This signal is used to count real time by the microcontroller. Depending on the inputs preset by the user, it is then used to count and display the time elapsed between pump cycles as well as the length of the pump on cycle.

J1 in combination with R16 and R19 provide a programming jack for U7 the PICAXE 20X2 so that we can program the microcontroller at any time. Pot R17 connected to U7 pin C.7 and the Setup button connected to U7 pin C.2 are used to setup the desired water volume and timing cycle. When the circuit is first powered up instructions will appear on the LCD screen asking the user to set the desired volume and interval between pump cycles in hours and minutes.

Whenever the timing cycle is running, pressing the Test button connected to U7 pin C.3 will command the microcontroller to turn on the pump until it is pressed again. Because the maximum current that can be output from a PICAXE I/O pin is about 20 ma we need the combination of Q2 and Q3 transistors to turn on the pump which will draw anywhere from 0.25 to 0.5 Amps. The values of R24, R25 and Q2 and Q3 gain are selected such that approximately 0.25 A will flow through M1 when U7 pin C.4 goes high and Q2 and Q3 are turned on.

Note that D7 and D8 are in place to suppress back EMF from the motor and protect the transistors and other logic in the circuit. C17 is a very important component that must be connected right across the pump motor terminals. These pump motors generate a lot of electrical noise and C17 bypasses this noise to ground. It must be connected directly across the motor terminals and not far away on the circuit board. I determined this value empirically by trying different values. This means you may need to experiment with a value that is effective for the motor you use and the circuit you build. If you find that your circuit is malfunctioning only when the motor is running, for example the 1 Hz clocking runs erratically or too fast it is a sure sign that electrical noise from the motor is getting into the logic section of your circuit. Start by trying a 4.7 uF capacitor across the motor terminals and if that does not work try other common values e.g 1 uF or 10uF. You can also try adding bypass and filter capacitors on the +5V power line. Capacitors C10 through C16 provide +5V power line filtering and a 0.1 uF bypass capacitor at each I.C power pin.

Pot R18 adjusts the LCD contrast. U8 pin 5 is tied to ground so that the LCD always reads instructions from the microcontroller and never tries to write to the controller. U7's pins B provide 8 bit data to the LCD. U7 Pin C.1 controls whether the LCD expects to receive a command or text data while U7 pin C.0 controls execution of commands or display of text.

Step 5: Circuit Construction

The circuit was built on proto board (vector board) using point to point wiring. I used 30 AWG wire wrap wire for logic connections and 22 AWG for power connections. 14 AWG bare copper wire was used for the ground and +5VDC busses. Not beautiful, but it works and keep in mind this is a prototype hobby circuit only. Maybe one day I'll design a PCB, but that's in the future. I placed test pins for troubleshooting on the main power points, gnd etc. Labelling was done with a Brother P-Touch labeller.

Step 6: Construction Continued

Step 7: Enclosure

The box is an IP65 rated electrical junction box with a transparent cover so that you can see the LCD and LED indicator lights when it is operating. The programming pot and set button were placed inside so that they are protected from the weather as I assumed the typical user will program it once and then let it run.

The fuse and test button are by necessity in the wall of the box. Both are a fairly moisture proof types. Because I had to drill several holes in the box for mounting the parts, board, transformer, motor etc and provide holes with rubber grommets for the power cord and water pipes I'm not sure how IP65 rated it is after modification. It is probably wise to place this box somewhere where it is protected from direct sunlight or rain such as under the building eaves up against a wall as complete weather proofing is not guaranteed.

Here you can use hot glue to fix the battery holder to the inside wall of the box. I used countersink screws for the equipment mounting and they are all on the bottom of the box. Cover any screw heads on the bottom of the box with pieces of water proof electrical tape. This will help seal the box against moisture and prevent the screw heads from rusting.

Step 8: Enclosure Continued

The Test switch is accessible from the outside for convenience. It is a toggle switch with a spring loaded momentary position and has rubber boot for protection from the weather. The fuse is also accessible.

Step 9: Enclosure Continued

1/4" clear plastic tubing (from Home Depot) is used for pumping the water. The bottom tube goes to the water reservoir, the top tube to the plant pot. Typically I use a cable tie or bag tie to fasten the feeder tube to the plant stem to prevent it from falling out of the pot.

Step 10: Parts List

1 - 4" x 6" prototype board

1 - 1.5" x 1.5" prototype board

1 - Uxcell 10.4"x7.2"x3.74" ABS Junction Box Universal Project Enclosure w PC Transparent Cover (Amazon)

1 - 120VAC:12VAC CT 1 Amp transformer. Circuit Test 640-122 (Sayal)

1 - Electric motor with integrated water pump. Chihai Motor 3.7-A-6V (SKU 441422 from DX.com)

1 - Toggle switch MOM 1P2T 5A. 125VAC 6.3mm hole. (Sayal)

1 - Waterproof boot for toggle switch Mode Electronics 41-899-3 (Sayal)

1 - Toggle switch SPDT

1 - 5x20mm fuse holder (bulkhead mount) (Sayal)

1 - 5x20mm 1A glass fuse

1 - 120 VAC line cord with 2 pin plug. (Recycled from old appliance)

1 - 3 x AA battery holder (Solarbotics 17010)

3 - AA batteries

1 - 9 volt battery snap connector (Solarbotics BHold9V)

1 - 5 or 10K linear potentiometer (bulkhead mount) with matching knob

2 - 5 or 10K linear trim potentiometer (circuit board mount)

1 - 16X2 Blue & white 1602A LCD Module (DX.com SKU: 151978)

1 - 16 pin female receptacle socket (Creatron CONHD-000016)

1 - 8 pin female receptacle socket (DX.Com)

1 - 6 pin female receptacle socket (DX.Com)

50 - male strip pins (approx)

6 - LEDS (various colors)

3 - 470uF, 16V electrolytic capacitors

2 - 100uF, 16V electrolytic capacitors

8 - 0.1uF Cap film RDL 63V (Sayal CFAF-1022-4)

1 - 4700uF, 63V electrolytic capacitor

1 - 4.7uF 16V electrolytic capacitor

2 - 22pF ceramic disc cap

8 - 1N4007 Diode

2 - 1N4148 Diode

1 - LM358 op-amp

2 - 74LS93 shift register

1 - CD4060 oscillator-ripple counter

1 - LM7805 5V regulator

1 - LM7806 6V regulator

1 - PICAXE 20X2 microcontroller (Solarbotics 28465)

1 - 32.768 KHz crystal

2 - 2N3904 transistor

1 - 2N5192 transistor

1 – 3.5mm stereo jack (Solarbotics 17850, Sparkfun PRT-08032)

1 - 4 pin push button (circuit board mount) (DX.Com SKU: 148065)

7 - 330 ohm resistors

1 - 430 ohm resistor

1 - 470 ohm resistor

1 - 8.2M resistor

1 - 330K resistor

1 - 4.7K resistor

1 - 22K resistor

9 - 10K resistors

1 - 8 pin IC Socket

1 - 20 pin IC socket

1 - 16 pin IC socket

2 - 14 pin IC sockets

4 - 3/4" standoffs, threaded

1 - 1" C - Bracket for motor (EMT conduit)


AWG 30 wirewrap wire

AWG 22 stranded wire

Heat shrink tubing assorted sizes

Cable ties

Hot glue


Assorted screws, nuts & flathead bolts (various sizes)


20 ft of 1/4" clear vinyl tubing (Home Depot)

Vinyl Electrical tape

water reservoir - plastic bottle or rain barrel

Step 11: Microcontroller Program

The attached PICAXE program is fully commented, so we won`t discuss the full details of how it works. Basically it is set up so that when you power up the device it goes into programming mode and asks for the volume of water you wish to pump during each watering and the amount of time in hours and minutes between watering.

You set the values you want by turning a pot and pressing the set button and following the commands on the LCD screen. Once this information is entered the timer starts to run and displays the amount of elapsed time. Once the preset time is reached the pump is turned on and runs long enough to pump the required volume. Pump runtime is calculated for you by the microcontroller based on the known 750 ml per min pump volume.

While pumping the clock is already running for the next cycle so that the plant is always watered at the exact same interval, there is no slipping forward in time due to the accumulated pump times. So for example if you start the timer at 6 AM before the heat of the day and ask the device to pump every 12 hours so the next cycle is at 6 PM, after the heat of the day, it should maintain this schedule.

Step 12: Downloads

Find attached a zip file with the JPG`s and PICAXE program.

Automation Contest 2017

Participated in the
Automation Contest 2017

Be the First to Share


    • Rice & Grains Challenge

      Rice & Grains Challenge
    • CNC and 3D Printing Contest

      CNC and 3D Printing Contest
    • Puzzles Challenge

      Puzzles Challenge



    5 years ago

    Hello Simon,

    Great project and well done. When you have nothing else to do there are a few additional features you can add.

    1.Real time Clock - You can skip days or hours.

    2. Temperature and Humidity tracker to water only when it's not raining.

    3. Soil moisture tracker. Prevents over watering.

    4. Some kind of alert to notify you when the water reservoir is empty and keeps the pump from running dry.

    Oh well, this should keep you busy for awhile ! Good luck Simon and keep up the great work.



    Reply 5 years ago

    Thanks Dave. Wow that's quite a list! I

    I'll look at incorporating these if I do another improved one. I especially like the idea of a dry reservoir alert and soil moisture measurement.



    5 years ago

    Nice design and layout. But you need to go one step further and design and produce a PC board for it. There are lots of PC design freeware available and you can use one of many to do that effort. That would make it look even more professional and give you some time designing such a board.


    Reply 5 years ago

    I agree. I'm thinking about developing it further and making it solar powered. If I do that, then I'll probably do a proper PCI.


    5 years ago

    Very Nice +1

    But why do you place the water pump inside the IP67 enclosure, there wil be a risk of leakage from the pump and hoses?


    Reply 5 years ago

    The first one I built has been running for years with no leaks. The pressure is really low with this little pump. So I'd say the probability of a leak is low. The electric motor on the other hand needs to be protected from the weather. It would not last long outside of the protection of the enclosure.