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
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. You can read about creating them here
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 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, but thankfully home depot has a good return policy (or they don’t care, ha.) 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.
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?)
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.)
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 a$$ 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.
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 we have to keep varmints (:-p) out.
Would you believe of all the damn parts in homedepot and lowes they 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.
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? Damn straight, 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.
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.
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.
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 sucker in place right?
Enclosure and gear:
This was my outdoor lab. I almost forgot. I also wanted to make is this sucker 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.)
|Mintyboost kit (photo from adafruit.com)
|Lipo Battery (photo from adafruit.com)
|Solar Lipo Charger kit (photo from adafruit.com)
This was me trying to get it all perfect before a thunderstorm was about to roll in, no pressure!
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. See notes at the end of the article for future changes and notes to the project.
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.
|Solenoid for water control (photo from sparkfun.com)
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
|Mosfet breakout (photo from sparkfun.com)
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.
*note* the screw terminals are great for recycling of parts for future projects or easy replacement of wires.
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!
*Notes* Some of these holes that were drilled were placed above the plants in terms of location alignment so that gravity would do the majority of watering. I also angled the hole to ‘shoot’ up and over to reach the sensor placed in the center of the rectangular PVC setup. I utilized some screen material over the hole to increase the pressure as well as maximize the area of the watering. The screen was held on using gorilla tape.
|The simplicity of a completed setup.
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.
- Would like to upload a video of it in action. 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.
//Auto Garden watering with moisture and light sensitivity
#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
pinMode(Solenoid, OUTPUT); // Sets Solenoid Pin to output for sending 5v to mosfet gate
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 ////////////////////////
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.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.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.println(light); //print “light” variable output to serial monitor for diagnostics
delay(1000); //Delay by 1000 cycles light value for easier readability
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
else //alternative if not dry enough for watering
digitalWrite(3,LOW); //set mosfet gate to low to disable or keep the solenoid disabled
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
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