Automatic Plant Watering System with Arduino

When going on a trip, I usually ask someone to watch over my plants. Last time I didn't want to bother my neighbor and decided to build an automatic watering system based on an Arduino Uno R3.

My requirements are simple. I needed a system that would water a plant in a vase, once every other day for one week.
Therefore, I built a simple timed system that will comply to these requirements. The system I built is based on a tutorial on the instructables website.

For this project I used the following:
(1x) Arduino UNO R3 from Elegoo
(1x) Small underwater pump
(1x) Silicone pipe (8mm diameter to fit the pump outlet/inlet)
(1x) 9V 1A Power Supply
(1x) Diode rectifier (1N4007)
(1x) NPN Transistor (PN2222)
(2x) Resistor 220 Ohm
(1x) Breadboard
(1x) Water container (I used a 2L plastic water bottle with the top cut off)
(~8x) Jumper cables

Step 1: An Overview of the Components

Pump

I bought a cheap underwater mini pump from Amazon Japan (costed around 10 usd). I was impressed on how small and powerful it is. I went for the underwater pump simply because it was cheaper, but and external one may give you more flexibility.
Going through the comments in Amazon, there were some stories of this specific pump getting damaged when air entered through the inlet. Therefore, to avoid having to build a contraption, I decided to just use it submerged, so that the inlet would have water all the time and air would not leak in. To keep it submerged, I attached a stone to the pump and placed it inside a 2L water bottle container with the inlet in direct contact with the water, without a pipe.

Mini pump with stone attached

Mini pump inside container

Transistor (PN2222)

The transistor is used to switch the pump On and Off. According to the datasheet , the PN2222 can switch 12V and max current Ic of 600mA, using the Arduino's 5V as the control signal. Since our pump specs have 4.2W, max current of 350mA and operating voltage of 5V-12V, this transistor will be enough for the job. Make sure you understand which pins correspond to the emitter (E), base (B) and collector (C) (refer to the figure below).

Transistor pins

NPN transistor representation

Diode rectifier

Used to protect the components from the short high current caused when turning the pump off (if you want to know more about this have a look at this answer in stackexchange).

Resistors

A 220 Ohm resistor between the transistor and the the digital output, in order to protect the Arduino and transistor.
To calculate the value, consider that the Arduino delivers 5V, and usually we want to have around 20 mA flowing from the pin (max 40 mA). Doing a rough calculation using Ohm's law, U = RI, to have a max current of 40 mA we need a 125 Ohm resistor minimum. Using a 220 Ohm resistor we will have a comfortable current of I=U/R=5/220=~22 mA.

2. Make the connections

I used the schematics below to bring all together.
Be careful to connect the transistor and diode correctly (refer to the image describing the transistor pins).

Connection schematics

If you are using a breadboard, refer to the figure below.
Breadboard connections

Step 3. The Code

This a simple timed system which turns the pump ON for 1 second every other day.

The code is very simple, but I added some console logging functionality (feel free to ignore) and used external functions in order to allow for some expansion in the future.

Feel free to check the complete code in github.

The basic code for minimum functioning is listed below:

/* Constants to work easily with units of time */
const unsigned long SECOND = 1000; //1sec is 1000ms  
const unsigned long MINUTE = 60*SECOND;  
const unsigned long HOUR = 60*MINUTE;  
const unsigned long DAY = 24*HOUR;

/* Drive mini pump for plant water feeding */
int motorPin = A0;    // Pump pin  
int ledPin = 13;      // LED pin  
int waterTime = 1*SECOND;    // Watering duration  
int waittime = 3*DAY;  // Waiting time between watering intervals

void setup() {  
    pinMode(motorPin, OUTPUT); // A0 will switch the transistor
}

void loop() {  
    digitalWrite(motorPin, HIGH); // Turn pump On
    delay(waterTime);        // Pump active time
    digitalWrite(motorPin, LOW);  // Turn pump Off

    /* Wait until next watering */
    delay(waittime);        // Delay between watering periods
}

Step 4. Putting All Together

For the water container, I cut off the top of a 2L plastic water bottle. I added the pump, strapped to a small stone to keep it in the bottom, and added a silicon pipe to the pump outlet.
The pump came with a connector, therefore I cut the wire, removed the connector and soldered them to jumper cables that connected to the board.
The Arduino is powered by a 9V 1A Power Supply connected to a wall.

Final setup

Breadboard closeup

The video with of the watering in action:

Step 5. Next steps

This is a simple system and there are several improvements that can be done. For example, you have to fill in the water container from time to time, and avoid making it run out of water, as it may damage the pump and the plant will not be watered. For my use case, the container has water enough for 2 weeks, but I want to add some sort of notification of low water level in the future (a ultrasonic sensor plus a LED should do the trick).

Also, during the period the pump is not working, the Arduino cannot run any commands due to the delay() instruction. I plan to use millis() instead, to have more flexibility. I also plan to add soil moisture monitoring to this system, in order to water the plant when the soil moisture reaches a certain "dry" threshold. I will write this in a future post.