loading

Step 7: Test and Calibrate Your Sensors

I loaded this code onto my Arduino to read sensors connected to analog pins 0, 1, and 2 and output values to screen:

int moistureSensor = 0;
int lightSensor = 1;
int tempSensor = 2;
int moisture_val;
int light_val;
int temp_val;

void setup() {
Serial.begin(9600); //open serial port

}

void loop() {
moisture_val = analogRead(moistureSensor); // read the value from the moisture-sensing probes
Serial.print("moisture sensor reads ");
Serial.println( moisture_val );
delay(500);
light_val = analogRead(lightSensor); // read the value from the photosensor
Serial.print("light sensor reads ");
Serial.println( light_val );
delay(500);
temp_val = analogRead(tempSensor);
Serial.print("temp sensor reads ");
Serial.println( temp_val );
delay(1000);

}

Here are some values I maintained from my sensors:
moisture (nails fully into soil at opposite ends of milk jug:
nails touching each other: 985
nails in air, not touching: 0
soil that seems too wet: 889
soil that's totally dried out: 0
soil that's starting to seem too dry: 707
soil that seems about right: 826

light:
indirect sun: 949
ambient indoor light at night: 658
ambient indoor light at night, hand casting shadow over sensor: 343
~2 feet from grow light, at night: 832
~2 feet from grow light, at night, hand casting shadow over sensor: 797

temperature (used temperature lead on multimeter to calibrate):
61 degrees Fahrenheit = 901
90F = 949
51F = 877
32F = 796

On soil moisture, it's kind of guesswork unless you get a fancy probe to compare its values to what your Garduino is outputting. Or, you could add a fixed amount of water to a known quantity of soil to figure out how resistance value varies with changes in water added... if you do, you'll want to mount the nails some fixed distance from each other (with some nonconductive material, obviously). Let me know if you do this!
<p>Using the probes that directly contact with the soil and pass a current through it to measure moisture content it a pretty poor setup long term.</p><p>The probes tend to corrode really badly (mine lasted a little over a month), and they don't give reliable or stable voltage readings.</p><p>Either of the capacitive sensors here:</p><p>- <a href="https://www.tindie.com/products/miceuz/i2c-soil-moisture-sensor/" rel="nofollow"> https://www.tindie.com/products/miceuz/i2c-soil-m...</a></p><p>- or here <a href="https://www.dfrobot.com/wiki/index.php?title=Capacitive_Soil_Moisture_Sensor_SKU:SEN0193" rel="nofollow"> https://www.dfrobot.com/wiki/index.php?title=Capa...</a></p><p>Will do a much better job. I use the dfrobot ones in my setup, with one of these boards <a href="https://www.abelectronics.co.uk/p/56/ADC-Pi-Plus-Raspberry-Pi-Analogue-to-Digital-converter" rel="nofollow"> https://www.abelectronics.co.uk/p/56/ADC-Pi-Plus-...</a></p><p>They give a range between 0-1v (1v is open air), and the voltage decreases as moisture content increases.</p><p>So far they work pretty well, and read pretty consistently uncalibrated, as in two sensors will give about the same value if placed in the same location in one of the planters.</p><p>The one thing i've found which throws them off is variances in the resistance of the solder joins in the sensor cables... Considering replacing them with the I2C sensors for that reason. But the non-I2C probes are considerably cheaper, even with the ADC board, when you've got a bunch of planters to monitor.</p><p>My setup is bigger than the one here, with seven planters, and 20 gallons of water storage. Water is pumped directly to the plants using a 12v diaphragm pump, with 12v solenoid valves to control distribution, and soaker hose buried in the planters. Controller is a raspberry Pi, with code written in C.</p>
<p>Ah, and for anyone thinking of using a diaphragm pump directly into soaker hose, I highly recommend some sort of expansion vessel. Even a 1.5l pop bottle half full of air will do.</p><p>Running the pump directly into soaker hose, is a recipe for busted pipes/pumps, found that out the hard way :)<br><br>Also tried a gravity feed, where the water was pumped up, about 2M above the planters, and fed back down, but there wasn't enough pressure to make it efficient.<br><br>Now I have an expansion vessel, and just blip the pump for 2 seconds, leaving the valve on the planter open for 15. The air in the expansion vessel is compressed by the pump, and then forces the water through the soaker hose for the period the valve is open. Works well, and the pump doesn't seem to mind the short duty cycles.</p>
this is helpful; thanks! any chance you can add photos of your setup?
<p>I can post some in a few weeks. Away for the month... That's actually the primary reason for automating the watering :)</p><p>Here's one pre-automation. I added another long planter to that.</p>
<p>Here's some basic ones... will send some more detailed ones when i'm actually there, and not photoing by proxy.</p>
<p>can we use g5led-1-vd relay?</p><p>if we use grove, how do we connect it in our system? </p><p>can we contact you through email?</p>
Hey. Would it be possible to use another relay other than Omron G5LE-1 coz it isn't available in my country. Been looking everywhere for it...
modules from sparkfun or seeed should work too; just make sure they're able to handle the amperage of your pump. example: https://www.seeedstudio.com/Grove---Relay-p-769.html
<p>I've also been thinking about the nails corroding becouse I'm also making my own version of garduino. It will be in soil, so non hydro. A few things I'll try to do: only measure once in about 3 hours. I will not feed the + nail with Vcc but with a digital-out pin, so most of the time there will be no current flowing so i guess the nails will corrode slower. First set the pin HIGH, a few seconds before the readings. Take an average of about 1000 samples. Then code 'if less then' or 'if higher then' to enable the pump if nessecary. (still haven't written a single line of code, I'm in the thinking process :) ). Set pin LOW, wait a few HOURS. Loop to begin (set high a few seconds before...) and so on...</p>
<p>Hi! The link you provided to the water pump doesn't seem to be working (or maybe it's out of stock). Can you please share the specs on the water pump? Thanks!</p>
<p>How do you use a nail to measure humidity? I don't really understand the concept. Thanks!</p>
<p>The idea is to drive current into one nail and see how many electrons jump over to the second nail. The higher the moisture content of the soil, the higher the electron count moving through it. Moisture improves conductivity. In essence you are measuring the resistance of the soil.</p>
<p>Noticed that you used two nails. Unfortunately, I have had my fair share of trying to build sensors out of nails, but they all corrode very quickly (in one case it corroded in less than a week). One solution that i have seen was using gypsum, but that can get painfully annoying at times. Would it be possible to fully insulate it like this <a href="http://www.vegetronix.com/Products/VH400" rel="nofollow">soil moisture sensor</a>? If so, I might consider building another sensor and giving it a go... Just don't want to have to deal with another corroding sensor...</p>
<p>Hi. I had the same problem. But my solution was quite simple. I used two stainless screws with also stainless bolts. The copper wires were crimped in terminals, so they don&acute;t get in touch with the soil. I also used the same method to make a sensor inside a water tank. So my garduino works only this sensor says there water in the tank.</p><p>Best Regards</p>
<p>I made the same as this but with some alterations, its currently reading the vegetable garden and turns a pump on when it needs watering and a valve, I have two sensors and two valves so they are individually controlled by the same Arduino. The water is passed through leaky hoses to water the garden. I also take 10 reading 3 seconds apart and divide this by 10 to get the average reading, This prevents spurious readings causing the system to start watering for no reason. My soil readings are uploaded to a web site at <a href="http://kentwoodcraft.co.uk/garden_watering/garden_watering.php" rel="nofollow">http://kentwoodcraft.co.uk/garden_watering/garden_...</a></p><p>I am still testing the resistors as I would like it more sensitive, at the moment I am using a 5 Meg resistor. </p><p>My probes are made from 8mm copper tubing which are flattened and tinned which have so far been all ok but this is a new project. </p><p>I will hopefully update an instructable once i have it all working ok. Great to see you one up and running. I will post my code on the web site soon</p>
<p>Any chance you still have the code? I'd love to have a look at it.</p>
<p>Could be please explain the working mechanism for the soil moisture sensor. As you are using copper probes what is the working principle for it. Please reply, my professor is asking for it as i have proposed the same system to him.</p>
<p>it might be too late for your professor, but here is the answer... just in case someone else is wondering.<br>the moisture sensor is nothing more than 2 probes that together with the sol in between form a resistor. If the soil is wet the resistance goes down.<br>That resistor is then put in a voltage divider (i.e. another transistor is put in series) and the voltage of the junction of the 'real' resistor and the 'soil' resistor is measured.<br>In reality the sensor doesn't measure true moisture but ion concentration in th ewater </p>
<p>Really like seeing growing and technology in the same place.</p><p>1. Can this be used to open and close a Linear actuator for the roof vent?</p><p>2. Turn on &amp; off a gable vent fan??</p>
<p>Sorry, but Jameco diode link is down, found this: </p><p>http://www.radioshack.com/1n4004-micro-1-amp-rectifier-diode/2761103.html#.VSqYDqGiLWI</p>
<p>I'm going to make it, and I'll put some improvements. Per example, I'll use an AtTiny and connect it to the Arduino by RF, which will have the Ethernet Shield or put the Garduino a Wi-Fi Module to connect to the Internet, making an IOT Garden controller. I'll call it the Gardtiny.</p>
<p>Very nice project. Thanks for sharing</p>
<p>This is an awesome tutorial. When I first created my moisture sensors they were reading values in the 600-700 range, which seemed okay to me. I picked the system back up about a month later when I moved somewhere where I actually have sun, and now they will only read values between 1-50. I tried replacing the nails and double checked the circuit but I can't seem to find a fix. Any ideas what the problem might be?</p>
<p>Nice!!!</p><p>see my -large- project : http://www.instructables.com/id/Watering-Garden-with-GARD-A-WATER-Arduino-Project/</p>
<p>hello again, i also have couple of additions/ideas if you don't mind... assuming we have changed the lights to high power led.s, everything running thru arduino, FIRST suggestion is to bring back the gravity idea for watering, i think the water pump is unnecessary electricity and taking up outlet space, noisy and too big, we are already adding water to the tank manually, so the placement of a miniature water tower above the plants and using arduino to manually open a faucet or chamber - using aquarium tubing only probably. i feel like this will be a safer design. we should also add SECOND suggestion here; a smoke detector that shuts off everything instantly. mixing gardening and all these electronics could easily be lethal but cheaply fixable just thru smart designing. i know you put it together very fast and i know you are more than careful, but not everyone will be...</p><p>also check out my almost finished 7W custom LED plant arm, a newer addition, i'm just learning to use arduino, thanks to you very fastly. especially for what I need</p><p>love &amp; peace</p>
<p>liseman, a great project once again. may I suggest using a different setup for the lights? check it out; i'm in the process of combining the two technologies...</p><p><a href="http://www.instructables.com/id/USB-powered-LED-plant-light-20/" rel="nofollow">http://www.instructables.com/id/USB-powered-LED-pl...</a></p>
<p>I was reading your Instructable as I am working on a similar project. Just wanted to let you know there is a very minor logic error when you do your sensor comparisons. For example, if you run through your code with light value of exactly 850 you'll see that scenario does not match any condition. Simple fix to add an = comparison to one of the other scenarios. </p>
Hi, I'm writing a blog post about cool Arduino based projects and your's is going to be there. Do you allow me to use one or two of your pictures in the post? I'm linking the references to the project back to this page. <br> <br>Thanks in advance! <br> <br>Manoel Lemos
Hi Manoel, <br><br>Feel Free to reuse however you'd like!<br><br>Thanks,<br>Luke
great. as regarding the reading of yr moisture sensors, what i have done in a similar case is to measure the resistance of the earth via my spikes in my plant bed when it was moist enough and calculated a voltage from that which told me the reading I was going to get from the arduino. used that as an irrigate or not threshold in my program. Worked well. <br>Keep in mind that two spikes in the earth, also give off a small voltage that can innfluence yr settings :-)
PROBLEM:<br><br>//establish start time<br>start_time = DateTime.now();<br>seconds_elapsed_total = 0;<br><br>Wont comply as &quot;DateTime&quot; was not declared in this scope.<br><br>Even though i added the file to arduino complier.
For anyone who's trying to do this and has had the same problem. I followed these steps to solve it: <br>1. Download the Time library: http://playground.arduino.cc/uploads/Code/Time.zip <br>Put it in your libraries folder. On my setup, Lubuntu, is in home/#username#/sketchbook/libraries. (You may have to create the folder.) <br>2. Change the &quot;#include &quot; to &quot;#include &quot; (without quotes) <br>3. Change 3 instances of &quot;DateTime.now()&quot; to &quot;now()&quot; (again no quotes) <br>Should compile now. <br>Hope this helps.
i am having the exact same issue. any thoughts????
please double-check that you can run separate, simpler datetime functions to confirm you have the datetime file in the correct folder. if that doesn't work (or does), let me know!
Lisemsan, how do i do that? I haven't really done much work with my arduino since i bought it and i am not to found of programming...
hey liseman, <br><br>From what I can tell, excellent tutorial. I am kind of new to arduino but I really want to try this one out, I figure Im a fast learner. <br><br>But the 2nd link on your materials list is broken, or at least doesn't link me to a product that still exists. Just wanted to make sure I got the right diodes. If you could point me in the right direction I'd appreciate it. But then again, I dont even see where you used them, unless I missed something. Thanks again.
I am working on replicating a similar project and have spent most of the day getting the water pump figured out. This is where you need the diodes. I am setting up a drip hydroponic system that turns the pump on and off with a set time interval. What I understand is that when the motor turns off it sends a high voltage shock through the system. I have unfortunaly / naively been using only a 50v diode which was not enough to protect the system from the voltage generated by the 120 volt water pump. I am new to electrical systems. Does anyone know what diode I should be using.
When you put DC on the wire coil in a relay, solenoid, motor, etc., it creates a magnetic field that pulls the armature or plunger, spins the motor, etc. When your control circuit switches the DC off, the magnetic field that's still in the coil collapses into the coil, turns its energy back into electricity and sends a very brief, reverse-biased, high-voltage pulse back down the wire (reverse EMF, or Electro-Magnetic Field).<br> <br> <strong>The diode must be reverse-biased</strong> (positive lead on the negative supply wire, negative lead/band on the positive wire) to short this pulse out. If you don't do this, the reverse EMF can blow up the low-voltage semiconductor that's controlling the solenoid or motor. If you connect the diode &quot;the way you'd expect&quot; it simply shorts the control voltage (very bad). The diode should be as close to the coil as possible for maximum effectiveness. 1N4004 (400 Volts @ 1 amp) diodes are cheap and plentiful, motor controllers are not.<br> <br> If you're ordering a relay, you may find that you can get one with a built-in diode on the coil. If you're powering your motor or other coil with a mechanical switch (like metal relay contacts) instead of a semiconductor device, you don't need the diode.
Never mind. A 1N4004 diode should be good for 400v.
Here's my effort - it only does the watering side of things, but includes code to provide live monitoring via a web based graph.<br> <br> <a href="http://theon.github.com/plant-watering-with-arduino.html" rel="nofollow">http://theon.github.com/plant-watering-with-arduino.html</a>
You should post this on Farmhack.com, It's a community of DIY farming and gardening technologies!
Farmhack.com is a domain for sale at godaddy. would you mean Farmhack.net?
Yes, my bad.<br> <a href="http://www.farmhack.net/tools" rel="nofollow">http://www.farmhack.net/tools</a>
Hey! <br> I was wandering if someone already tried to calibrate moisture sensors like you proposed? Yes, and did someone use similar system for hydroponics? <br>I'm just starting to build my own system and but I will probably switch to hydroponics. Really cool idea and implementation!
Hello. <br /> <br />Im bringing garduino back to life, I want to play with the ethernet shield. <br /> <br />However, Im getting an error, saying 'DateTime' was not declared in this scope. <br /> <br />Would you know how to fix this? <br /> <br />Thanks <br />
How's it working over time?&nbsp; Almost everyone tries nails first, then moves to gypsum or the like, and if they want accuracy, they end up with a tensiometer.<br /> <br /> Also, DC is known to be a problem for moisture sensors over time - have you considered AC or are you just replacing your probes often?<br />

About This Instructable

425,032views

763favorites

License:

Bio: bicycles, gardening, and other important stuff
More by liseman:3D Print A Splint DIY Factory How To Get A Shipping Container 
Add instructable to: