Measure soil Moisture with Arduino – Gardening

Needed Hardware

ArduinoUno_r2_front450px

Arduino Uno

Price: less than $30 (Amazon)

A moisture sensor
Price: less than $7 (Amazon)

Simple Way to connect to the Arduino

arduino-uno

code

 

int sensorPin = 0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor
 
void setup() {
  // declare the ledPin as an OUTPUT:
   Serial.begin(9600);  
}
 
void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);    
  delay(1000);          
  Serial.print("sensor = " );                       
  Serial.println(sensorValue);                   
}

Output

Sensot in air: value = 0

sensor = 0
sensor = 0
sensor = 0
sensor = 0

Sensor in dry soil:  0 < value  < 300

sensor = 35
sensor = 41
sensor = 38
sensor = 49

Sensor in humid soil: 300 < value < 700

sensor = 578
sensor = 576
sensor = 582
sensor = 589

Sensor in water: value > 700

sensor = 934
sensor = 940
sensor = 938
sensor = 940

Drawbacks

Using this sensor on this way always makes current cross over the sensor. It can cause corrosion across the probes.

photo

Solutions:

  • Do not left in place the sensor.
  • Stop to power the sensor when is not used (see below)

Keep your sensor alive for a while

Here the aim is to stop to power the sensor when it is not used. Let says we want to get a value each 1min.

PNP_2

Code

int sensorPin = 0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor
 
int sensorVCC = 13;
 
void setup() {
  // declare the ledPin as an OUTPUT:
   Serial.begin(9600);  
   pinMode(sensorVCC, OUTPUT); 
   digitalWrite(sensorVCC, LOW);
}
 
void loop() {
  // power the sensor
  digitalWrite(sensorVCC, HIGH);
  delay(100); //make sure the sensor is powered
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin); 
  //stop power 
  digitalWrite(sensorVCC, LOW);  
  //wait
  delay(60*1000);          
  Serial.print("sensor = " );                       
  Serial.println(sensorValue);                   
}

 Perspectives

This kind of sensor can be used to check plant watering or to auto water a plant.

13 Comments

  1. Hi
    Thx for the NPN trick, I noticed that if you want an accurate value, the delay value must be over 100ms
    np : I’m not using the same model of sensor

    Reply
  2. Very cool projects!

    If you use AC on the sensor it will last forever. Just desolder all of the active components on the sensor and wire both vcc and gnd to digital pins. Measure the voltage on the output just after the gnd pin is low and vcc is high and you should be fine I think. Also do an analog read when the applied power is opposite and ignore the reading, then make both pins vcc or gnd.

    Reply
  3. Lovely project! Which kind of NPN – transistor is that? Would it be possible to control the on/off – position of the sensor without one? I’m new at this, trying to introduce it to my 7th graders.

    Reply
  4. hi, Vincent Demay
    i tried to do this, but the output i’m getting for sensor in air is 1023,when i connect analog pin A0, when i connect to other pins such as a2,a3,a4,a5, its getting decreased values til 500.
    can u kindle tell me where i went wrong!?

    Reply

Leave a Comment.