Back to Parent

//declaring integers
int val = 0;//variable to store soil value
int soil = A0;//Declare a variable for the soil moisture sensor
int soilPower = D7;//Variable for Soil moisture Power

//We wil use a digital pin to power this sensor, to prevent oxidation
//of the sensor as it sits in the corrosive soil.
//Setup function for the application
void setup()
{
pinMode(soilPower, OUTPUT);//Set D7 as an OUTPUT
digitalWrite(soilPower, LOW);//Set to LOW so no power is flowing through the sensor

//This function is used to get the soil moisture content
int readSoil()
{
    digitalWrite(soilPower, HIGH);//turn D7 "On"
    delay(10);//wait 10 milliseconds
    val = analogRead(soil);
    digitalWrite(soilPower, LOW);//turn D7 "Off"
    return val;
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0