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 );
light_val = analogRead(lightSensor); // read the value from the photosensor
Serial.print("light sensor reads ");
Serial.println( light_val );
temp_val = analogRead(tempSensor);
Serial.print("temp sensor reads ");
Serial.println( temp_val );


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

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!

About This Instructable


664 favorites


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: