Introduction: 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
What you'll need:
(x1) Arduino UNO rev 3 (http://adafru.it/50)
(x1) USB cable (http://adafru.it/62)
(x1) 1N4001 diode (http://adafru.it/755)
(x1) PN2222A transistor (http://adafru.it/756)
(x1) 12v 1000mA DC power supply (http://adafru.it/798)
(x1) peristaltic pump (http://adafru.it/1150)
(x2) alligator clip test leads (http://adafru.it/1008)
(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
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
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!
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
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.
97 Comments
6 years ago
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
Reply 6 years ago
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.
Cheers
Reply 2 years ago
Using a mosfet (using a low voltage transistor seemed a bit risky) and a stable 12v power supply i was able to do what you describe with no issues i left it running for a hour which no heat issues, the idea behind using a diode is to stop the surge from the motor reaching the arduino, im pretty sure people have just been using bodgy power supply's because ive made a few projects that power nano's directly by 12 volt power to the vin and gnd pins and they are still working flawlessly, i have tried making this exact circuit without a diode before and it did not end well burnt arduino.
Question 2 years ago
Hey! A noobie circuit builder here.
Why is a transistor required to power the pump? Looking through the arduino spec sheet, shouldn't the Vin pin allow for a voltage output of between 7-12V when plugged into direct power (not usb)?
Also, how can you determine the voltage amplification the transistor provides? I'm looking through the spec sheet online, but I couldn't find a specific amplification. Is it a ratio of the 220Ohm resistance with the internal resistance of the pump?
Thanks!
3 years ago on Step 7
Please be aware that if you are using a 5V relay with this code that the relay (depending on type) isnt turned on when you use HIGH but rather - is turned on when you use LOW (so the opposite of what you would normally program). so LOW (0n) and HIGH (off)
3 years ago
Could you use a 5-6v perastaltic pump instead of the 12 V one?
3 years ago
I want to tell you thank you for the awesome and clean code. I am using it as part of my research in space biology to water microgreens. This is a awesome and clear posting!
Question 4 years ago on Step 5
great job! I'm doing something a very similar but using a temperature and humidity DHT11 module and I am having trouble to setup the code. The idea is to spray the water when sensor reads an specific temperature and humidity level. Some questions:
Do you have an idea of the coding for this?
I have a 12v pump (windshield washer fluid one) why you are not using any relays?
Answer 3 years ago
did you figure it out? I am working on a project which demands something like you described. Can you please help me with it? Thanks
4 years ago
hello it doesn't work and i don't know what's wrong
i wired everything up then putted to 12V adapter
disconnected and connected it to pc with usb cable to upload the code
then disconnected from pc and connected to 12v a green light "ON" is switched and an orange-yellow of "L - Digital - PWM" which was blinking for 5 seconds and stopped.
but motor doesn't work
Question 4 years ago
Hello, how would I power this with batteries?
What kind of batteries would I need and how long would they last?
Question 4 years ago on Introduction
Can I use a raspberry pi instead of an Arduino? I’ve a school project, but we need to use a ras
5 years ago
hi can i use tip120 transistor to replace the pn222a ?
Tip 5 years ago
A goood tweak for this project would be to add a temperature monitor, or moisture monitor, as controls for how often the soil gets watered..
Question 5 years ago
Hey I'm looking into using this code but I want to pump liquid in 2 directions is there a way I can reverse the pump by adding code or does it require more wiring
Answer 5 years ago
The peristaltic pump could pump in the other direction but would need major rewiring and code additions..
Then is the motor is brushed for one direction it will not turn as well in reverse !
Question 5 years ago on Step 6
How would you be able to modify this to run multiple (3 or 4) pumps
Question 5 years ago on Introduction
Hi! Thank you for this great tutorial. Was just wondering for changing the code for a longer fluid flow time where does it need to be fully changed to work. Also, if I wanted to add an on/off switch rather than unplugging how could I do So?
I am using this as a base to modify for an automated fluid flowing system
6 years ago
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?
6 years ago
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.