Three-ways Automatic Watering System PIC16F84A

Help me to develope
If you find this project interesting, give it a like and share it!
If you are interested in buffering for a short time frame (ex. a holiday) this is the right solution for you, otherwise go to the project BP005 for a self-controlled watering system that operates 365 days per year.


Fig.1 – The three-ways automatic watering system's central unit

Fig.1 – The watering system’s central unit

Some years ago I had the opportunity to spend a whole month holiday in Portugal. I didn’t want to ask my friends, or neighbours, to water my plants everyday for me. I thought therefore to build a system for that purpose using the most common microcontroller PIC16F84A.

I thought and tested lots of different solutions in order to find the best one. Reliability was the most important aspect to ensure: a fault could have killed my plants or, worse, flooded my neighbour’s house. Once the system was built, only a few days remained before my departure. So, I set the irrigation timing as best as I could, I asked a friend of mine to go and check once if everything was fine and I left the house crossing my fingers.

Fig.2 – Detail of my balcony at present

Fig.2 – Detail of my balcony at present

When I came back to Milan, I surprisingly found all my plants incredibly grown and healthy. From that moment, I decided to use the system for the whole year. To do that, it was necessary to change the irrigation timing in the code and reprogramming the PIC each time depending on the different seasons and temperatures.

Fig.3 – Another view of my balcony

Fig.3 – Another view of my balcony

According to my initial purpose, it was not necessary to provide a “user friendly” way for that. A display and others devices around it, would have made the project uselessly complex, more expensive and longer. In the end, I realized that reprogramming the PIC from time to time was not a big hassle and allowed me to use it in every condition. I abandoned my watering can for ever.

As you can see in figure 2 and 3, the system is still today providing water to all my plants in the balcony making me very proud. In particular, in figure 3 you can see where I put the central unit board with the PIC16F84A.


My simple, cheap and quick solution

As you probably know, it is better not to water plants and trees when the sun is high. So, the goal of this project was to find a simple, cheap and quick solution to water all my plants every night, splitting the balcony in three zones with an individual irrigation timing each.

Fig.4 – The solenoid valve I used

Fig.4 – The solenoid valve I used

By using a LDR (light dependent resistor), it is possible to activate the watering process after the sunset. This solution avoids the use of a clock that is not the easiest device to make in DIY.

The core of the project is the PIC16F84A. Its task is to control, in automatic or manual mode, all the solenoid valves according to the timing set in the code inside it.

The most expensive components in the projects are the solenoids. By surfing on eBay, I found a very cheap 24V AC model, made to be installed in washing machines, that suited my requirements perfectly (figure 4).

Relays are quite expensive too but I had some small 12V ones at home; otherwise by using some 5V ones, the LM7812 in the schematic below is not necessary but the LM78L05 must be substituted with the LM7805.

Fig.5 – The three-ways automatic watering system's schematic

Fig.5 – The three-ways automatic watering system’s schematic


What the PIC16F84F is programmed to do

The system ensures watering your plants every night but you can also decide to irrigate manually the three different zones pressing the corresponding push button. The PIC16F84A is the core and controls everything.


Fig.6 – Solenoid valves and LDR's timeline during the night

Fig.6 – Solenoid valves and LDR’s timeline during the night

The program inside the microcontroller is normally halted during the day. After the sunset the LDR unblocks it and 64 minutes later the PIC16F84A begins to water the zones one at a time.

The graph in figure 6 displays the peculiar sequence adopted to open and close the solenoid valves. This method ensures to maintain the water pressure low in any condition through the pipes increasing the system’s safety.

You can see practically what the microcontroller does by playing the video below.


Fig.7 – The components placement in the central unit board

Fig.7 – The components placement in the central unit board

By pressing a push button the system starts to water the corresponding zone for one minute or until you will press that button again. The process of opening and closing the solenoid valves is the same described for “the night cycle” in figure 6. Note that the code, as is written, allows you to water manually only during the day when the program is halted.

In the drawing in figure 7 you can identify where LEDs, push buttons, clamps and the other main components are placed in the central unit board.


Fig.8 – The LEDs' time left code

Fig.8 – The LEDs’ time left code

The four LEDs show the system activity;

  • During the day: the red LED is fixed on;
  • After the sunset: the red LED blinks (50% duty-cycle) and the three green ones display, in binary notation, the renaming time according to the scheme in figure 8;
  • Watering in action: the red LED blinks rapidly, the corresponding LED zone is on;
  • When the watering is completed the red LED pulses (20% duty-cycle).


Practical realization and testing


Building the water piping system is very easy. You need to connect pipes (figure 9), nozzles (figure 10) and junctions (figures 11 and 12) together.

Fig.9 – Ø16 mm rigid pipes and soft ones

Fig.9 – Ø16 mm rigid pipes and soft ones

Fig.10 – Nozzles for rigid and soft pipes

Fig.10 – Nozzles for rigid and soft pipes

Fig.11 – Junctions to connect rigid pipes together

Fig.11 – Junctions to connect rigid pipes together

Fig.12 – Junctions to connect soft pipes to rigid ones

Fig.12 – Junctions to connect soft pipes to rigid ones


For my balcony i decided to use Ø16mm of rigid pipes that suit perfectly the solenoid valves I bought. With them I “bring” the water from the kitchen’s tap to the three zones. For the lower pots I installed directly the nozzles on them; otherwise for the upper ones I connected soft pipes to the rigid ones in order to make flying nozzles.

I hope the scheme below explains better how I built the piping system for my balcony.

Fig.13 – The water piping system placement in my balcony

Fig.13 – The water piping system placement in my balcony



Fig.14 – The irrigation timing section in the file code.c

Fig.14 – The irrigation timing section in the file code.c

First you need to open with a text editor the code written in c,  called “code.c”, available in the compressed file. Set your irrigation timing by changing the values shown in pink in figure 14. Now compile the code by using the XC8 compiler in MBLAB’X IDE (both downloadable for free from the Microchip’s website). In the end, program the PIC16F84A with your software programmer (I use PICPgm).


Fig.15 – The watering system's PCB layout

Fig.15 – The watering system’s PCB layout

A single side board with some jumpers was sufficient to realize this project. For that reason building the PCB is quite simple.

Once you have soldered all the components, install a small heat sink to the LM7812 and the programmed microcontroller onto its socket.

Now it is the time to test the circuit. Connect a transformer (24V AC – at least 15W) to the circuit and the solenoid valves to the output clamps. If everything works fine, the red LED should be on; by obscuring the LDR, the LED should start blinking.

Fig.16 – The watering system's PCB bottom-mask

Fig.16 – The watering system’s PCB bottom-mask

Test now the solenoids by pressing the push buttons that should open and close them according to the process explained before in the manual irrigation section.

So far, so good? Well, let’s test the automatic night cycle. Obscure the LDR until the red LED starts blinking. As explained before, the watering will start only 64 minutes later and in the meanwhile you should see the green LEDs display the remaining time (figure 8). After that, if the night cycle has gone fine until the end you are ready to install the central unit board into the piping system.  Otherwise, if the program resets after having watered the first zone, you will need to substitute C4 with a 2200µF 10V capacitor as I needed to do (as noticeable in figure 1).


The last step is to set the right timing for your zones.  This is the procedure I suggest:

  1. water manually each zone until you are satisfied and write down the three timings. Leave the system switched off;
  2. the day after, program the microcontroller using the measured timings (from point 1) and plug the system on. During the night the system will water your plants;
  3. in the following days monitor the system and, if necessary, do some fine adjustments of the timings by reprogramming the PIC;

Finally set the LDR sensitivity by the R14 trimmer and enjoy!


Download the project

Pressing the button below you can download a compressed file with all the necessary material to build this project:

  • the PIC16F84A, the LM7812 and the LM78L05 data sheets;
  • the pictures of the final project, the schematic, the code, the PCB mask and the PCB layout as shown in this post;
  • the schematic and the board files in Eagle format.

If you need some help please do not hesitate to contact me or leave your comments below. Enjoy it!

BP0001 (5.0 MiB, 224 downloads)


I have decided to share my knowledge and my projects for free, so I have not inserted any annoying ads on Despite this, if you like my website, please help me in developing it by leaving comments and suggestions, or by making a small donation pressing the button below.
Grazie di cuore, Andrea Dal Maso



This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

One thought on “Three-ways Automatic Watering System PIC16F84A

  1. I read with great interest your article, it is very good including attachments download.

    As you use a 20Mhz oscillator, you should specify the reader configuration fuses when programming. (FOSC1 and FOSC0 -> HS Oscillator). Your .hex file is set with XT Oscillator.

    I have two questions: how to correct the time constants if one wishes to use a PIC16F84 04P?
    To use pulse valves (24V AC) I think change the program as follows (exemple for Zone 1 only):

    if (k == 3840) // tps = 64 Min – Zone 1
    RB5 = 0;
    RB6 = 0;
    RB7 = 0;
    RB1 = 1; // Pulse
    RB4 = 1;
    RB5 = 1;
    twosec ();
    RB1 = 0; // Pulse
    RB0 = 1;
    d1 = TimerZone1 * 4;
    for (j = 0; j <j 1; j ++)
    led1blk ();
    RB1 = 1; // Pulse
    RB4 = 1;
    twosec ();
    RB1 = 0; // Pulse
    RB0 = 0;
    RB5 = 0;
    is it right ?

    Again, congratulations for this work.
    Bests regards.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>