Needed Hardware

Arduino Uno
Price: less than $30 (Amazon)

A moisture sensor
Price: less than $7 (Amazon)
Simple Way to connect to the Arduino

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.

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.

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.