Grove - Moisture Sensor

From Wiki 来自痴汉的爱
Jump to: navigation, search
Moisture sensor .jpg

This Moisture Sensor can be used to detect the moisture of soil or judge if there is water around the sensor, let the plants in your garden reach out for human help. They can be very easy to use, just insert it into the soil and then read it. With the help of this sensor, it will be realizable to make the plant remind you : hey, i am thirsty now, please give me some water.

Note:This sensor isn't hardened against contamination or exposure of the control circuitry to water and may be prone to electrolytic corrosion across the probes, so it is not advisable to be left in place or used outdoors.

Get One Now Banner.png



  • Soil moisture sensor based on soil resistivity measurement
  • Easy to use
  • 2.0cmX6.0cm grove module



Item Parameter Min Typical Max Unit
Voltage - 3.3 ~ 5 V
Current - 0 ~ 35 mA
Output Value Sensor in dry soil 0 ~ 300 /
Sensor in humid soil 300 ~ 700 /
Sensor in water 700 ~ 950 /

Platforms Supported

  • Arduino
  • Raspberry Pi
  • TI LaunchPad

Application Ideas

Getting Started

Grove - Help

Following documents help in getting the user started with Grove.

With Arduino

This is a summary of the moisture sensor which can be used to detect the moisture of the soil. When the soil moisture reduces, the sensor output value will decrease. You will know whether a plant needs water or not by observing the results that the sensor outputs. The following sketch demonstrates a simple application of sensing the moisture of the soil.

  • Connect this module to one of analog port A0 of Grove - Base Shield with the 4 pin Grove cable, and then insert the Sensor into the soil or place it anywhere you want.
  • Plug Grove - Base Shield into the Arduino/Seeeduino and connnect Arduino to PC via a USB cable.

The hardware installation as shown below:


  • Copy and paste code below to a new Arduino sketch.
int sensorPin = A0;    // 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:
void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);    
  Serial.print("sensor = " );                       
  • Upload the code, please click here if you do not know how to upload.
  • The Result in different condition after open the serial monitor: (click to view larger image)
No load.jpg Dry soil.jpg Humility soil.jpg IN water.jpg
Sensor in air Sensor in dry soil Sensor in humid soil Sensor in water

With TI LaunchPad

Taking care of your plants (Moisture Sensor)

The following sketch demonstrates a simple application of sensing the moisture in soil. With this, you will know whether your plant needs water or not by observing the results from the output of the sensor.


 The following sketch demonstrates a simple application of sensing 
 the moisture of the soil. You can know whether a plant needs water 
 or not by observing the results that the sensor outputs.
 The circuit:
 * Moisture-Sensor attached to pin 24 (J6 plug on Grove Base BoosterPack)
 * one side pin (either one) to ground
 * the other side pin to +VCC
 * LED anode (long leg) attached to RED_LED
 * LED cathode (short leg) attached to ground
 * Note:  
 This example code is in the public domain.
#include "TM1637.h"
/* Macro Define */
#define CLK               39                  /* 4-digital display clock pin */
#define DIO               38                 /* 4-digiral display data pin */
#define BLINK_LED         RED_LED            /* blink led */
#define MOISTURE_PIN      24                /* pin of moisture sensor */
#define THRESHOLD_VALUE   300                /* threshold for watering the flowers */
#define ON                 HIGH                          /* led on */
#define OFF                LOW                           /* led off */
#define _handle_led(x)     digitalWrite(BLINK_LED, x)    /* handle led */
/* Global Varibles */
TM1637 tm1637(CLK, DIO);                  /* 4-digital display object */
int analog_value = 0;                     /* varible to store the value coming from rotary angle sensor */
int8_t bits[4] = {0};                     /* array to store the single bits of the value */
/* the setup() method runs once, when the sketch starts */
void setup() {
    /* Initialize 4-digital display */
    /* declare the red_led pin as an OUTPUT */
    pinMode(BLINK_LED, OUTPUT);
/* the loop() method runs over and over again */
void loop() {
    analog_value = analogRead(MOISTURE_PIN);      /* read the value from the sensor */
    /* if the value is smaller than threshold, turn on led */
    if(analog_value < THRESHOLD_VALUE) {
    } else {
    memset(bits, 0, 4);                             /* reset array when we use it */
    for(int i = 3; i >= 0; i--) {
        /* get single bits of the analog value */
        bits[i] = analog_value % 10;
        analog_value = analog_value / 10;  
        tm1637.display(i, bits[i]);                 /* display by 4-digital display */

With Raspberry Pi

1.You should have got a raspberry pi and a grovepi or grovepi+.
2.You should have completed configuring the development enviroment, otherwise follow here.

  • Plug the sensor to grovepi socket A0 by using a grove cable.

4.Navigate to the demos' directory:

    cd yourpath/GrovePi/Software/Python/

  • To see the code
    nano  # "Ctrl+x" to exit #

import time
import grovepi
# Connect the Grove Moisture Sensor to analog port A0
sensor = 0
while True:
        print grovepi.analogRead(sensor)
    except KeyboardInterrupt:
    except IOError:
        print "Error"

5.Run the demo.

  sudo python


Help us to make it better

Personal tools