Introduction: Automatically Water Your Small Indoor Plant Using Arduino + Pump

Picture of Automatically Water Your Small Indoor Plant Using Arduino + Pump

Have you ever wanted a little plant to brighten up your desk or home, but you're afraid that you'll forget to water it? Fear no longer! Using an Arduino, a scavenged wall-wart, and a peristaltic pump, you can set up your plant to be watered as often as you like, from a jug or any other vessel. To be as accessible to as many people as possible, this tutorial can be done without soldering. That being said, the advantage of soldering is increased robustness and reliability.

Step 1: What You'll Need

Picture of What You'll Need

What you'll need:

(x1) Arduino UNO rev 3 (

(x1) USB cable (

(x1) 1N4001 diode (

(x1) PN2222A transistor (

(x1) 12v 1000mA DC power supply (

(x1) peristaltic pump (

(x2) alligator clip test leads (

(x1) 220 ohm resistor (anything between 125 - 333 ohms will work) (not pictured)

(x1) jug, glass, vase, or any other vessel that can contain water (not pictured)

(x1) a piece of scotch or electric tape (not pictured)

Tools: wire snippers, soldering iron + solder (not pictured)

Step 2: Understand Your Transistor

Picture of Understand Your Transistor

First, figure out what the different pins are on your transistor. The diagram from the datasheet shows you which pins are the base, collector, and emitter. The second picture shows how the pins match up to the circuit diagram. This transistor is awesome because it will allow us to use 5v from the arduino to switch the much higher 12v required by the motor, which would destroy our Arduino if we connected it directly to the pins that we can control with our Arduino code. The PN2222A transistor is great for this purpose because it can handle 5v from the Arduino and then switch the 12v and much higher current drawn by the motor.

Step 3: Protect From the Motor

Picture of Protect From the Motor

Clip a small (1/2") piece of wire from one end of your diode (if you have other similar wire, use that instead) and put it aside for the next step.

Attach your diode in reverse across your motor pins. Reverse means that the negative lead (indicated by the silver band on the diode) connects to the positive pin on the motor, and the positive diode lead connects to the negative pin on the motor. I've done it here by soldering, but if you don't have a soldering iron, you can wrap the diode leads very firmly around/into the holes in the motor pins. This will prevent any potential damage from energy released when the motor is switched off.

Step 4: Wire It Up!

Picture of Wire It Up!

Now wire everything up. Conveniently, we can just stick the transistor directly into the Arduino.

The emitter pin goes to GND, and the base pin (in the middle) goes to Analog Pin 0 but with a 220 ohm resistor in series between them. You'll need to solder or otherwise attach the 220 ohm resistor to the base pin, and then stick the other end of the resistor into Analog Pin 0. If you don't use the resistor, it may shorten the life of your Arduino.

Bend the collector pin out so it won't touch the Arduino, and attach an alligator clip to it. This pin will receive the electricity coming through the motor and allow it to keep flowing. Connect the clip on the other end to the negative pin on the motor.

Take the little piece of wire we cut and set aside in the previous step and stick it into the VIN pin hole. Bend it a little so it doesn't touch the transistor.

Connect a clip to the positive pin on the motor, and connect the other end to the piece of wire in VIN. Tape this clip to the board or otherwise secure it so it doesn't move around and touch the transistor pins.

A word of warning: it is possible to destroy the chip in your Arduino if you connect the circuit wrong. Luckily, you can order a new chip for $6 (or much less if you get them in bulk), rather than paying $30 for a whole new Arduino board. But you're more likely to destroy the transistor, which isn't too bad if you got the 10-pack.

Once you're sure you've got it right (check the picture one more time!!), connect the power from your 12v adapter to your Arduino. If you've done it right, nothing will happen. If you've connected it backwards (reversed the collector and emitter) the motor will weakly spin. If that happens, your transistor is probably now dead. You can try using it again, but it may not work properly. I would just get another one.

Step 5: Program Your Arduino

Conveniently, the code is incredibly simple. Copy and paste the code into your Arduino code editor, choose how long you want to water, and how long you want to wait between watering. If you're in an air-conditioned office, the air is usually very dry, which causes the soil to dry out quickly. In that case, you may want to water a little bit several times throughout the day.

Unplug your 12v cable and connect the USB cable between your Arduino and your computer.

Upload your code, then disconnect the USB cable.

Connect the 12v cable to your Arduino, and the motor should immediately run for 5 seconds.

This code also turns on the built-in LED during watering. If your LED turns on but the motor doesn't, something isn't connected right.

int motorPin = A0; // pin that turns on the motor
int blinkPin = 13; // pin that turns on the LED
int watertime = 5; // how long to water in seconds
int waittime = 60; // how long to wait between watering, in minutes

void setup()
	pinMode(motorPin, OUTPUT); // set A0 to an output so we can use it to turn on the transistor
	pinMode(blinkPin, OUTPUT); // set pin 13 to an output so we can use it to turn on the LED

void loop()
	digitalWrite(motorPin, HIGH); // turn on the motor
	digitalWrite(blinkPin, HIGH); // turn on the LED
	delay(watertime*1000);        // multiply by 1000 to translate seconds to milliseconds

	digitalWrite(motorPin, LOW);  // turn off the motor
	digitalWrite(blinkPin, LOW);  // turn off the LED
	delay(waittime*60000);        // multiply by 60000 to translate minutes to milliseconds

Step 6: Implement

Picture of Implement

Now that you've got a working setup, it's time to put it in place so your plant can get its water.

Get a jug or glass or whatever you'd like, and put the input (the sucking end) of the pump hose in it.

Put the output of the hose in your plant.

Put the Arduino somewhere where it won't get wet.

As far as aesthetics are concerned, I kind of like the wires because people come over and see them and say "What's with the wires... wait, is that some kind of watering contraption?!" and then I get to tell them all about it and show them how it works. If you prefer something more discreet, you can put everything into a box and run the tubes through holes. You could even put the box under the plant as a stand. Your imagination is the limit.

Step 7: Optimize

You're basically done, but the last thing you should do is check the soil periodically and see if it's too wet or too dry, and adjust your code accordingly.

If it's too wet, go in and either decrease the 'watertime' variable to water for less time, or increase the 'waittime' variable to wait longer between waterings.

If the soil is too dry, do the opposite. Be patient, as it may take a few days to see if your changes are optimal.

Thanks for reading! I plan on writing more Instructables, so please let me know if you have any feedback. I love sharing what I'm working on, and it makes me happy when something I've made can be useful to someone else.


AtomicSaber made it! (author)2017-09-26

Hey osmithy,

Could you update the instructions to include connecting the 220ohm resistor to the base pine of the transistor? I made this instructable without looking at the comments, and everything worked fine. I happened to come back to this page to see all the comments that I should indeed add a resistor. I did see it in the parts list, but I think having an explicit step will help others avoid and issues.

Thanks for this tutorial! I'm planning to extend this to water 12 plants :D I've posted about it on Here's the link:

theOctoProgrammer (author)2017-08-24

Dude, awesome project! I'm in the middle of it right now but CAUTION BEGINNERS: DO NOT TRY THIS WITH JUST ANY 12V ADAPTER!!! Most commercial adapters clock in with at least a volt or two more than it says on the label. I suspect this is why so many people on this page keep frying their arduinos; arduinos can handle up to 12 volts, but no more. @osmithy you might want to edit this into the text of your instructable. Great job though

Another word of warning: don't try this with an arduino nano or any other board that has a wimpy voltage regulator. This piece is essentially a parallel circuit between the arduino and the pump, where the arduino side controlls the pump side (pretty ingenious actually). Since the pump will typically have more resistance than the arduino, the arduino will get the brunt of the amperage. Your voltage regulator needs to be able to cope with that.


maxxluvnlf (author)2017-08-14

Why would it be that the motor only works when I have the Arduino plugged into both the 12V 1000mA Power source and a computer?

JoshuaK47 made it! (author)2016-05-10

I made this with a few other instructables, so mine has a soil moisture sensor $3, connected to pin A5 and using an ethernet shield and set up a very simple website to monitor the moisture status of my plant. code below,

#include <SPI.h>

#include <Ethernet.h>

byte mac[] = { 0x00,0x1F,0xF3,0xD7,0x09,0x4C }; //physical mac address

byte ip[] = { 10, 0, 0, 253 }; // ip in lan (that's what you need to use in your browser. ("")

byte gateway[] = { 10, 0, 0, 1 }; // internet access via router

byte subnet[] = { 255, 255, 255, 0 }; //subnet mask

EthernetServer server(80); //server port

String readString;

int relay1 = 2; //relay1 on pin 2

int soil=0;

int motorPin = A0;


void setup() {

// Open serial communications


pinMode(relay1, OUTPUT);

// start the Ethernet connection and the server:

Ethernet.begin(mac, ip, gateway, subnet);


Serial.print("server is at ");



pinMode(motorPin, OUTPUT);


void loop() {

/*========================================Soil sensor / pump mechanism============================================

using a 12v pump on 9v analog pin pump is triggered when moisture value falls within certain threshhold.and stops

immediately once it is satisfied.


// read the input on analog pin 5:

int sensorValue = analogRead(A5);

sensorValue = constrain(sensorValue, 485, 1023);

// print out the value you read:

if (sensorValue > 900)




else digitalWrite(motorPin,LOW);

//map the value to a percentage

soil = map(sensorValue, 485, 1023, 100, 0);

// print out the soil water percentage you calculated:



delay(1000); // delay in between reads for stability

// Create a client connection

EthernetClient client = server.available();

if (client) {

while (client.connected()) {

if (client.available()) {

char c =;

//read char by char HTTP request

if (readString.length() < 100) {

//store characters to string

readString += c;



//if HTTP request has ended

if (c == '\n') {

Serial.println(readString); //print to serial monitor for debuging

client.println("HTTP/1.1 200 OK"); //send new page

client.println("Content-Type: text/html");




client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");

client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");

client.println("<link rel='stylesheet' type='text/css' href='' />");

client.println("<TITLE>SMART Home Control</TITLE>");



client.println("<H1>VENUS CONTINGENCY home page</H1>");

client.println("<hr />");

client.println("<br />");

client.println("<H2>home to the Arduino-Based Self-Regulating Venus Flytrap</H2>");

client.println("<br />");

client.println("<a href=\"/?potmoisture\"\">Refresh pot% </a>");

if (readString.indexOf("?potmoisture") >0){

client.println("<H3>current soil level is ");




client.println("<a href=\"/?waterlvl\"\">Refresh waterlvl% </a><br />");

client.println("<br />");

client.println("Created by Joshua Kiefer and Jacob Kiefer");




//stopping client


//controls the Arduino if you press the buttons

if (readString.indexOf("?potmoisture") >0){

digitalWrite(relay1, HIGH);


if (readString.indexOf("?lamp1off") >0){

digitalWrite(relay1, LOW);


//clearing string for next read







mark_mark (author)JoshuaK472017-06-13

Thank you for sharing this.
I am trying to do exactly as you have done. I have already ordered the components. I don't know much about programming. So, please help me here. Do I have to create a separate website as well or does the code provided by you take care of everything.

Genew308 (author)2017-04-14

Many thanks for a great post, well explained. I was able to learn more about driving motors with transistors from you. Thanks for taking the time to put it together. I have a small hydroponic garden [ebb & flow] that works because of some of the details you explained here.

Grumpy Mike (author)2015-07-10

You said:-

The PN2222A transistor is great for this purpose because it can handle 5v from the Arduino without any resistors.

This is total and utter rubbish and will result in the Arduino being damaged. The Arduino has a pin limit of 40mA that is the limit of what it should supply, not the limit of what it can supply. It is likely that the base current without a resistor is being limited to about 80mA by the internal impedance of the Arduino pin and that is stopping the transistor from frying. This current is twice the level where damage to the Arduino is being done. You NEED a resistor, 1K should be fine. No doubt you will say it works, but your Arduino will fail a lot sooner that it otherwise would have.

osmithy (author)Grumpy Mike2016-03-06

I see that you live up to your name. But thanks for catching my mistake! I've updated the Instructable.

NnennaI (author)osmithy2017-04-10

was just passing by but had to say @osmithy that was a classy reply! thumbs up :)

FrancisM44 (author)osmithy2016-06-22


Here, 1K prevented the pump to get enough current. I had to use a 220 resistor to make it work.

osmithy (author)FrancisM442016-11-30

Ah, good catch. I think you are correct in general -- the datasheet gives an example of saturating the transistor with only 15mA, so with 5v you'd want a maximum of 333 ohms. To limit the current to only 40mA to protect the Arduino, use a minimum resistance of 125 ohms. So 220 is great because it's a common resistor and is between 125 - 333.

AlexR349 (author)2017-03-26

well done job, but you have to install at least 180 Ohm resistor between Arduino pin and base of N2222 transistor to prevent ruining both - your Arduino board and transistor

mik123 made it! (author)2017-01-13

How do you stop the transistor from burning?

osmithy (author)2016-11-30

Since this Instructable has been getting a decent amount of traffic, I'm going to update it soon with a proper schematic, so no one else fries their boards. Thanks for enjoying it despite all the issues!

MohamedS412 (author)2016-11-27

Dear author,

can i use a normal and cheaper aquarium pump instead of peristaltic pump since I am planning for a demo only. Urgent Please, as we have a science project next week.

osmithy (author)MohamedS4122016-11-27

If your aquarium pump runs on 12v, then yes. If it's the type you plug into a wall socket, then no (you'd need to use a relay or PowerSwitch Tail, which would be as expensive as the peristaltic pump). Best of luck with your project!

BrixG (author)2016-11-10

Is there any alternative for PN2222A ??only japan models are available here HELP!

ock86 (author)2016-11-08


Can someone help with this 1K resistor issue ? I'm a total newbie in electronics. As a proof, I fried my Adruino in attempt to set this up :(

If there's anyone can tell me a dummy's guide in connecting the resistor. What wattage should I get for the 1K resistor ? and if it's not connected to the A0 pin, what should I change in the code to make it work ?

Thanks a lot!

NgariK (author)2016-10-20

Great tutorial, but my transistor gets extremely hot and smells like it is burning. Any idea what's happening? I am new to electronics so forgive me if it is a simple issue but I just cant figure it out.

NgariK (author)NgariK2016-10-21

Never mind I figured it out by myself. I did notice that connecting the resistor base to A0 did not do anything so I connected it to digital pin 2 and altered the code a tiny bit and everything works perfectly.

MuhammadBaqar1016 made it! (author)2016-09-30

Very Easy instructions...Thank u for Letting us make this project

mehmetsukru (author)2016-07-10

good job!

FrancisM44 (author)2016-06-09

I made this - thanks a lot for the inspiration! But with me, the 1k resistor was too much, so it wasn't working. I changed to a 220, and then it worked. I hope this won't fry my arduino...

saurabhr2 (author)2016-04-26

I need a program which can start a 5v relay automatically daily in 4 pm of arduino uno

mh2933 (author)2016-03-05

I fried the board (cheep copy anyway), and now I know why as you can see in the specs down below of max current the different pins can handle, and as a couple of people have noted. This motor draws about 300mA. My projects has to fill about half a liter of water and the time of running the motor is therefor about 10 min.

I gonna try to switch a transistor on and of instead so the motor will work on a separate circuit. Will share when I succeed.

osmithy (author)mh29332016-03-06

Sorry you fried your board! You weren't trying to run the motor directly off the board itself, right? This design already uses a transistor. That being said, people more knowledgeable than myself are saying to use a 1k resistor in series between the board and the base pin of the transistor, so make sure you do that.

mh2933 (author)osmithy2016-03-07

No worries it cost me 10 bucks :), it was worth it. Yes I connected it as described so the 12v 300mA if Im understanding it correct had to travel thru the board, ground to collector and + to Vin. I red that post and put the 1k resistor on. But I have seen schematics that are using the arduino as a trigger of the base of a transistor which then control a bigger load and the ground is the only common place so to speak to somewhat isolate the circuit.

I had a timer on as well, in the wall and a transformer(12v) going to the board, so when I started to fiddle with the timer something sparked and it smelled burned. May have something to do with BackEMF from the timer Im guessing and the overload of the pin.

I need to control the pump so it pumps about a liter of water three times a day. I gonna try another approach.

osmithy (author)mh29332016-03-11

Ah, I see what you mean about the Vin pin. But with a genuine Uno, the Vin pin appears to be connected directly to the incoming power supply with nothing in between:

But yeah, 3 liters per day is a lot. Best of luck!

TomGee (author)2015-07-10


"The PN2222A transistor is great for this purpose because it can handle 5v from the Arduino without any resistors."

Sorry that is wrong, the Veb is 6V, this is the reverse bias breakdown voltage of the 2N2222A not the forward drop which is 0.6 to 0.7Vdc

Please!!!! Place a 1K resistor between the output of the arduino and the transistor base, to limit base current.

You are very lucky if you do not have a base resistor to not have caused damage to your arduino and or 2N2222A.


osmithy (author)TomGee2016-03-06

Thanks for the info, I've updated the Instructable to reflect the 1k resistor.

pallavip2 (author)2015-09-06

hello, first of all i want to thank you for such a helpful information. Sir, i m from computer faculty so i want to innovate this idea with mobile app. Can you help me out for basic idea about what should i do for these.

osmithy (author)pallavip22015-09-06

I would use a Particle Core or Particle Photon. They're essentially wifi-connected Arduinos that you can program and control via the web. Once you understand their API, it should be no problem to integrate it into an app.

vivek008 (author)2015-07-19

alrite, i made it. but what can i do to check water level in the container. am using a submersible pump that should not be used without it being completely submerged. so it helps to have some way to check if the water in the reservoir is getting depleted

daugguy (author)2014-05-03

You have a great project, I like it when its simple. I have a problem with your code though, I can't get wait time beyond about 30 seconds. I think its limited to 32767 ms, but with the ()'s it should go farther. What version of Arduino are you using.

rob.ert.7568 (author)daugguy2015-03-04

instead of just delay(waitTime) you can use:

int waitTime = 32000;

int cycle = 0;

void loop(){


while(cycle<1000){ //if you waited waitTime x Cycles you can go on

delay(waitTime); //wait 32 seconds
cycle+=1; //increase cycle by 1




osmithy (author)daugguy2014-05-04

Hmmmm good point, you may have to use a long instead of an int.

billbillt (author)2014-04-27

I just love it when a GREAT project such as this is posted how all of the "experts" pop up to give advice on how to "do it better"...

osmithy (author)billbillt2014-05-02

I'm very glad you like it! I actually appreciate all the comments on how it could be improved, because it opens my eyes to things I hadn't thought of, and broadens my perspective.

yzerbeat (author)2014-04-28

Great project! Nice job.

I did not want to sacrifice my arduino for it, and made one with these parts :

an aquaruim waterpump and a 5volt powersupply.

Let it grow !

osmithy (author)yzerbeat2014-04-30

Great idea, and very cheap! I didn't realize that sensor could operate without an arduino. Did you have any trouble calibrating it so the soil had the right moisture level?

yzerbeat (author)osmithy2014-04-30

There is a little blue potentiometer on the board, it was very easy to calibrate the relay.

dougstrickland (author)yzerbeat2014-05-02

You should consider writing an instructable for your project!

hunsnowboarder (author)2014-04-29

Very nice and good tutorial! Congrats on it!

However there is one thing of which I am concerned. I checked the data sheet of the pump and found out that the current of the pump motor is 200-300 mA. Arduino max current output is 30 mA. Will not the motor destroy Arduino? Please explain if I am wrong (I would like to learn! :))

Thank you and congrats again!

imjosh (author)hunsnowboarder2014-05-01

The current limits for the Uno are 40mA from any one I/O pin or 200mA from all I/O pins combined, and 50mA from the 3.3V supply pin.

The only I/O pin he is using is A0 to drive the transistor which will be very well under 40mA.

I'm not sure exactly what the current limit for the 5V supply pin is. I think it might be 1.5amps, but it's at least 500mA which is the most that can be drawn over a standard USB port.

However, he is not using the 5V supply pin to power the pump (which would be bad because dropping 12-5=7volts @ 300mA would require dissipating 2.1 watts of power which would definitely overheat the voltage regulator)- he is using the Vin pin which he is supplying with 12V. That is, the same 12V supply that is powering the Arduino through the 5V regulator is directly connected to one side of the transistor. The pump is connected to the other side and when A0 goes HIGH, the pump will draw current directly from the 12V supply. More explanations:

osmithy (author)hunsnowboarder2014-04-30

You would be correct if we were powering the pump directly from the arduino. However, we are only using the arduinio to switch on a transistor. The transistor can handle much higher current and voltage than the arduino.

hunsnowboarder (author)osmithy2014-04-30

Dear osmithy. Thank you for your reply. I don't understand then. :) What is powering the pump? From the schematics I see that the pump is powered from the arduino 5V pin and the transistor is controlled by the A0 analog pin. I don't see any other power source. I am confused. Please help.

diy_bloke (author)2014-04-28

Nice project. I think though that the container you are using might be empty pretty soon :-)

osmithy (author)diy_bloke2014-04-30

Thanks! The container runs out in about a week which is not bad.

diy_bloke (author)osmithy2014-04-30

not too bad :-)

About This Instructable




More by osmithy:Pier 9 Guide: Othermill "I Made It" PCB ProjectHow to Take Ember ApartUpgrading Older Ember Hardware for Pattern Mode
Add instructable to: