Introduction: Moisture Sensor Test Plan

The goal of this test plan is to create a sensor that determines whether soil is wet.

Step 1: Materials

The following materials will be needed for this sensor:

Arduino Uno Microcontroller

Soil Moisture Sensor

Two LEDs

Laptop Computer

USB cable to connect the Arduino to the Computer

Breadboard

A beaker of dry soil and a beaker of wet soil

Wires

Step 2: Putting Together the Circuit

First, you are going to need to connect the moisture sensor to the Arduino. To do so, start by connecting the SIG pin on the sensor to the A0 pin on the breadboard, Ground to Ground, and VCC to pin 7.

Then, you need to connect the LEDs to the circuit. One LED should be connected to pin 8 and another to pin 9. Keep in mind that pin 8 will tell you that the soil is dry and pin 9 that the soil is wet. In the second picture, the blue is connected to pin 8 (connected by the white wire), so it lights up when the reading is dry, while the green is connected to pin 9 (connected by the blue wire), so it lights up when the reading is wet. If you encounter issues with the LEDs, make sure that the shorter leg of the LED is first -- meaning the shorter leg is in a lower number spot on the breadboard.

The grounds of these LEDs then need to be connected together on another line (in the second image, 20) so one wire can go from the breadboard to the Arduino ground, completing the circuit. The wires completing the circuit are the orange wires on the breadboard.

First Image Link: learn.sparkfun.com/tutorials/soil-moisture-sensor-hookup-guide?_ga=2.105278851.1884025432.1515505881-540086646.1512480444&_gac=1.11330176.1512480444.EAIaIQobChMIwd2vwrfw1wIVW7XACh1KgQf7EAAYASAAEgJcbvD_BwE#soil-moisture-sensing-basic-example

Step 3: Programming the Arduino

/* Soil Mositure Basic Example
This sketch was written by SparkFun Electronics Joel Bartlett August 31, 2015

Basic skecth to print out soil moisture values to the Serial Monitor

Released under the MIT License(http://opensource.org/licenses/MIT) */

int val = 0; //value for storing moisture value

int soilPin = A0; //Declare a variable for the soil moisture sensor

int soilPower = 7; //Variable for Soil moisture Power

int wetPin = 9; // green LED in 9 pin

int dryPin = 8; // blue LED in 8 pin

//Rather than powering the sensor through the 3.3V or 5V pins,

//we'll use a digital pin to power the sensor. This will

//prevent corrosion of the sensor as it sits in the soil.

void setup() {

Serial.begin(9600); // open serial over USB

pinMode(soilPower, OUTPUT); //Set D7 as an OUTPUT

digitalWrite(soilPower, LOW); //Set to LOW so no power is flowing through the sensor

pinMode(dryPin, OUTPUT); // dry LED is an output

pinMode(wetPin, OUTPUT); // wet LED is an output

}

void loop() {

//Serial.print("Soil Moisture = ");

//get soil moisture value from the function below and print it

Serial.println(readSoil());

if(readSoil()>700){ //if the soil value is greater than 700

Serial.println("Soil is wet"); // print soil is wet

digitalWrite(wetPin, HIGH); // Wet LED on

digitalWrite(dryPin, LOW); // Dry LED off

}

else{

Serial.println("Soil is dry"); // write soil is dry in serial monitor

digitalWrite(wetPin, LOW); // Wet LED off

digitalWrite(dryPin, HIGH); // Dry LED on

}

//This 1 second timefrme is used so you can test the sensor and see it change in real-time.

//For in-plant applications, you will want to take readings much less frequently.

delay(1000);

//take a reading every second

}

//This is a function used to get the soil moisture content

int readSoil() {

digitalWrite(soilPower, HIGH); // turn D7 "On"

delay(10); //wait 10 milliseconds

val = analogRead(soilPin); //Read the SIG value form sensor

digitalWrite(soilPower, LOW); //turn D7 "Off"

return val; //send current moisture value

}

Step 4: Video!