Arduino Auto Watering Garden Project

by simakerspace in Circuits > Arduino

29807 Views, 116 Favorites, 0 Comments

Arduino Auto Watering Garden Project

IMG_0958.JPG

What your looking at above is my entire project in its' enclosure. I set out to solve a problem when starting this project that was two fold. One it was to familiarize myself with some of the basics of the Arduino environment and the other was to have my organic garden watered automatically based on light exposure and moisture content.

These two variables were very important. I could use some auto timer to water my plants for a specified interval bought at the local hardware store, but that is junk and it's no fun! Think about it. It might stop my plants from being watered during the day, but what if it rains and my plants are watered too often and my plants will just become flooded and expose the roots. Not good. With that in mind lets jump into the details

(My Name is Jarred Sutton and I am a maker at Staten Island MakerSpace www.makerspace.nyc)

The Moisture Sensor Option

2012-05-27 14.16.07.jpg

The first thing I had to do was research how to design a moisture sensor. I've seen nails in the soil held apart without a medium, but I wasn't too keen on that. I found an article online about using plaster of paris to make the sensor. It worked out great and I got a few extra sensors in the process. Above are the tubes I cut from larger sections of tubing. I tried two sizes for fun and experimentation.

The Moisture Sensor Option

2012-05-27 14.22.52.jpg

I didn't have the ability to make holes in a block of wood or brick to hold the tubes of plaster so I opted for my tabletop vise. I used cardboard to distribute the force. You may notice they are curved in some of the pictures. Unfortunately most clear tubing comes on a spool and even leaving heavy text books on the tubes didn't help much. I padded the center a bit more with cardboard to hold the thinner tubes in place.

The Moisture Sensor Option

2012-05-27 15.06.03.jpg

The wax paper was held in place on the bottom by scotch tape and I used long wax paper strips draped over each tube to hold the nails. The problem is the nails I used have a small head on them. Like less than 1mm or so from the shaft of the nail. I pre-cut some of the wax paper holes using a scalpel as the tips of my nails were not sharp enough to pierce the wax paper. A small slash will do.

An important note to make about the types of nails I used. I chose galvanized nails. ONE PROBLEM. According to my meter typical galvanized nails use some polymer like coating that do not conduct a current or voltage. I learned this the hard way. What you will want are 'hot dipped' galvanized nails. These WILL conduct. I was the weirdo in homedepot with his multi-meter to find this out personally.

The Moisture Sensor Option

2012-05-27 16.12.52.jpg

These are the resulting moisture sensors. Don't they look great? Thankfully none of them were shorted and varied in resistance. I was really fascinated how the resistance varied from 7Mohms to 20Mohms. The official resistance will vary until they completely set over a day or so. You get used to buying cheap 6cent resistors, but actually making your own is pretty darn cool (geeky?)

The Moisture Sensor Option

2012-05-27 16.15.54 (1).jpg

Don't worry if your nails slip into the mix. One of my sensors experienced this and at first I panicked and tried to get them out with tweezers. I went for one nail and the other slipped further, haha. I soon realized when it dries I can use my scalpel to chisel out the tops of the nails. A little shorter then the other sensors, but it still works just fine. Keep the nails 1cm or more from the bottom of the tube (cut the tube to accommodate.)

Alternative Moisture Sensor Option

2012-06-21 20.42.51.jpg

This was the other option I played with for a sensor. It is very basic and can be made with found parts. It is two screws, something to hold them a distance apart and wire. This is prone to quicker moisture changes in the soil, but in some cases it was more ideal. Keep in mind when soldering to nails and screws higher heat may be needed to compensate for the dissipation of heat and also be mindful of the types of metal you are soldering to.

Attaching Wires and Connections

2012-05-27 23.36.40.jpg
2012-05-27 23.55.04.jpg
2012-05-27 23.37.07.jpg

I soldered the wires to the sensors using a high temperature to get enough of a hold. Make sure to cover these terminals in hot glue as well to water proof the terminals. Almost every connection I wanted to run I utilized these JST connectors. I figured it would be a real pain in the butt if I had to re-solder wires and splice it all together. This way things can be exchangeable. I utilized heat-shrink on all connections exposed to the elements. Not only does it make things look neat, but here it also helps to insulate the connector and protect it from the rain.

PVC Setup

2012-05-27 18.32.33.jpg

Then came the idea for the frame. I sorta just made this up in my head. You should have seen me in homedepot playing with pvc and picturing what I would need and how I wanted to present it (make sure to measure the plot at least.) I debated which setup would be better. Should I build a figure 8? design it from the center to water outward or go with my setup and water inward. Utilizing one sensor I decided on the setup you see in front of you. The right angle from the T-connector is to hop over the plastic fence I have to keep varmints (:-p) out.

PVC Setup

2012-05-27 18.32.52.jpg

Would you believe of all the darn parts in the local hardware stores don't have a threaded 3/4" pvc coupler stepping down to a 1/2" pvc smooth connector? I looked so hard and eventually made one out of several parts. See the problem is the solenoid I used for water control is 3/4" and its kind of wide to provide all that water and still maintain pressure over the garden which is approximately 12' x 4'. So I used 1/2" piping for the rectangle loop and extension.

All the cutting was performed using a dremel rotory tool. Make sure to sand down the burs and level the connectors for the best fit. Also keep in mind to do this outside and with protection (eye and respiratory) is the best idea. The pvc burs get everywhere and the glue/solvent I used is dangerous in its regular application state.

Solenoid Valve Setup

IMG_0938.JPG

This is where the action happens. What you are seeing here is the 25' garden hose (the cheap 6' hose was just too short of course) connected to the solenoid via an adapter and a 3/4" threaded coupler. The other side of the solenoid utilizes a half threaded and half smooth 3/4" coupler, connected to a few inches of 3/4" pvc pipe, connected to a 3/4" adapter to 1/2" threaded adapter, connected to a 1/2" screw to smooth adapter; which connects to the pvc rectangle. Too many parts? yep, but I had to make it work. I also used teflon tape (pink of course!..) to make sure ever screwed joint is leak resistant.

The solenoid has two wires saturated in hot glue to waterproof the terminals. Also to note I needed an adapter for the garden hose to fit into the 3/4" adapter. Why you ask? Well apparently a garden hose (mine at least) has a beveled edge. This does not screw into the pvc coupler so I needed to get an adapter to fix that.

Solenoid Joint Support

_JMS8760.jpg

T-connecter? Nope. In a pinch I took some extra pipe and some gorilla tape and slapped it together. I had enough of the solvent application and plus I didn't want to split the water flow again.

Splitting Water Supply

046878677456xl.jpg

Last thing you will need is a y adapter for the hose. of course this isn't needed if you have nothing connected to your spigot.

Light Sensor

2012-05-29 17.30.09.jpg
2012-05-29 17.29.51.jpg

For the light sensitivity I decided on a photo-sensitive resistor. I needed to create a port hole in the enclosure in order to expose the sensor to the sun. I bought a cheap sheet of clear plastic from the hardware store and cut a small piece from it to make this work. The inside ring is hot glue and the outside ring is silica caulk for extra waterproofing. I also hot glued the sensor to the clear plastic sheet and enclosure to prevent movement and to add further waterproofing. It also holds the piece in place right?

Enclosure

IMG_0937.JPG
IMG_9697.jpg
liionpack6600_LRG (1).jpg
usbdcsolarcharger_LRG.jpg

This was my outdoor lab. I almost forgot. I also wanted to make is this project was solar! I am utilizing a tenergy 6600mah battery, Adafruit minty boost and their solar lipoly charger to keep the Arduino setup going. These are solderable kits that Adafruit provides and they work wonderfully. Make sure your solar panel can handle being left in the rain. Turns out mine can (;-).) Although Adafruit sells some awesome panels to use I was keeping costs low and just cut, stripped and soldered a connector to my panel. I also had to elongate all the wires to make them reach the box I put of into the shade. These also all have JST connectors designed with them (my own creation.)

Enclosure Fun

IMG_0942.JPG

This was me trying to get it all perfect before a thunderstorm was about to roll in, no pressure!

Enclosure Innerds and Cable Glands

CableGlandBlack.jpg
IMG_0954.JPG

The guts. The materials were not neatly placed I admit. I made sure there were no shorts and with little time left to get it going and a flight to take in the morning sealed her up.

So how are the cables protected as they are sent into the enclosure? Through the use of what are called cable glands. These are also purchasable through Adafruit. I got them through Mouser.com and also through eBay.com in bulk. Note that when purchasing from mouser It lacked a nut to screw the back on. To see details on how a cable gland works see wikipedia.org here. I used hot glue to secure them.

Enclosure Alternative

2012-06-13 22.59.38.jpg
2012-06-13 22.59.49.jpg
2012-06-13 23.00.17.jpg
2012-06-13 23.02.40.jpg
2012-06-13 23.07.54.jpg
2012-06-13 23.08.45.jpg

In my second version I utilized a pelican case with cable glands to make it water tight!

Solenoid and Mosfet

10256-02.jpg
10456-01.jpg

The last piece of the puzzle was powering the solenoid. A solenoid utilizes the power of magnetism created when sending an electric current through a coiled wire to move, in our case, a metal bolt which will in turn control our valve inside the unit. I purchased the solenoid through sparkfun here as well as the mosfet and a breakboard board for easy use seen here.

Figuring out the mosfet was the hard part at first. Looking at the breakout board there is a 3 terminal side and a 2 terminal side. The two terminal side connects to the solenoid. The three terminal side shared ground with the arduino, the gate is connected to your 5v pin, and the + is connected to the positive of your 12v source. The way everything works is through the use of the behavior of a transistor. There is a Gate that will close the circuit when a 5V signal is sent to the mosfet. This will bridge the gap completing the circuit and sending 12v DC to the solenoid. I used an old hard drive power supply to provide 12v. I cut off the end adapeter and soldered hook up wire to it for easy application.

Software/Programming

code.jpg

For the software part I had to figure out a way to get the arduino to manage the two variables; moisture and light. The way I approached it was through the utilization of what is called a nested loop. The first condition will be based on light as I don't want my plants to be burnt through the heating of water. If the conditions are right then the next loop condition will be based on moisture. If the moisture is lacking then a 5volt signal will be sent to the mosfet allowing the 12v to flow and triggering the solenoid allowing the water to flow.

Make sure that in your code your digitalWrite is setting the pin to LOW when not in ideal conditions or you will have constant watering on your hands.

I utilized the Arduinos analog pins for measuring the resistance of the light sensor and the moisture sensor. The analog pins read voltage in a digital way. In order to 'convert' the analog readings to digital a small snippet voltage reading is taken every certain amount of times depending on your clock cycle being used with your micro-controller. A voltage divider is setup using a 10kohm resistor for the setup to the analog pins.

Make sure to use your serial monitor in order to see the readings if you don't have an LCD to monitor the sensors output. create a "delay(1000);" (at least 1000) so that the monitor isn't over loaded with feedback!

Basic Code

Basic Code:

//Auto Garden watering with moisture and light sensitivity

//////////////Initialization////////////// #include

//include LCD library int MoistSensePin = 0; //Designate moisture sensor analog pin to 0 int LightSensePin = 1; //Designate light sensor analog pin to 1 int Solenoid =3; //Designate solenoid control pin to 3 LiquidCrystal lcd(7, 8, 9, 10, 11, 12); //initialize LCD pins

void setup() { pinMode(Solenoid, OUTPUT); // Sets Solenoid Pin to output for sending 5v to mosfet gate pinMode(5, OUTPUT); pinMode(6, OUTPUT); Serial.begin(9600); lcd.begin(16, 4); // set up the LCD's number of columns and rows: lcd.print("-Watering Criteria-"); //Prints message in quotes }

//////////Beginning of Loop ////////////////////////

void loop() { float sensor = analogRead(MoistSensePin); //retrieve sensor value float light = analogRead(LightSensePin); //retrieve light sensor value delay(2000); //2 sec delay digitalWrite(5, HIGH); //Set status Led to On delay(250); //2 sec delay digitalWrite(5, LOW); //Set status Led to off lcd.setCursor(0, 1); //Setup txt to follow on the third line lcd.print("Moisture:"); lcd.setCursor(10, 1); //setup txt to follow on the first line lcd.print(sensor); //print "sensor" value to LCD delay(1000); //Delay by 1000 cycles sensor value for easier readability lcd.setCursor(0, 2); //Setup txt to follow on the third line lcd.print("Light:"); lcd.setCursor(7, 2); //Setup txt to follow on the third line lcd.print(light); //print "light" value to LCD delay(1000); //Delay by 1000 cycles light value for easier readability Serial.print("light: "); Serial.println(light); //print "light" variable output to serial monitor for diagnostics delay(1000); //Delay by 1000 cycles light value for easier readability

Serial.print("moisture: "); Serial.println(sensor); //print "sensor" variable output to serial monitor for diagnostics delay(1000); //Delay by 1000 cycles sensor value for easier readability

//////////beginning of the nested loop for solenoid control based on light and sensor values///////////////////// if (light>200) //initialization of loop controlled by the light value to determine day or night for plant safety { if (sensor>190) //if light is safe then ask if the moisture sensor is dry enough to start watering { lcd.setCursor(0, 4); //set starting point of text to second line of LCD lcd.print("!Active!"); //print active to diagnose if watering is determined to be needed digitalWrite(6, HIGH); //Set water status Led to On digitalWrite(3, HIGH); //if watering is needed the solenoid is set to high triggering solenoid delay(60000); //waters for 1min digitalWrite(3, LOW); } else //alternative if not dry enough for watering { digitalWrite(3,LOW); //set mosfet gate to low to disable or keep the solenoid disabled digitalWrite(6, LOW); lcd.setCursor(0, 4); //set starting text to second line of LCD lcd.print("Inactive!"); //print Inactive! to dertime of the solenoid has been disabled } } else //alternative if not dark enough for watering { digitalWrite(3,LOW); //keep the mosfet gate pin to low to maintain off status if not dark enough for watering digitalWrite(6, LOW); lcd.setCursor(0, 4); //set text position to second position lcd.print("Inactive!"); //print "Inactive!" to make aware its not dark enough and Inactive status is maintained } }

Notes

2012-06-26 18.02.32.jpg
2012-06-22 00.05.45.jpg

Notes and changes:

  • Update the case for better insulation using a pelican case and protection. The radio shack enclosures were not as leak protected as I had hoped.
  • Insert a form of status indication for an alive status as well as the status that the Arduino is executing watering commands (possible LED blink for alive status and a 7segment display for watering count or the use of a data logger shield)
  • I painted the black box white and put it in the shade to avoid overheating the battery or components
  • Place the solar panel at a good angle to maximize the charge capability.
  • Soon I hope. Keep pressure in mind as too much can cause the setup to leak and waste water.

WARNING: Please proceed to use any and all of my advice at your own risk. Working with electricity and batteries can hurt or kill you. Please proceed with caution and knowledge.

The Results

IMG_0946.JPG
2012-05-27 18.32.33.jpg
IMG_0945.JPG
IMG_0949.JPG
IMG_0950.JPG
IMG_0960.JPG