SOIL MOISTURE

16. Soil moisture

How many times did you forget to water your flower pot? With a soil moisture sensor you will give the flower pot the instrument to alert you when it will be thirsty (see Photo 1). This example of analog input uses a soil moisture sensor to detect and report via the Internet two events: dry soil (Dry) and wet soil (Wet).

Photo 1 - flower pot connected to the Internet

Figure 1 - Soil moisture sensor circuit

1. Circuit

Connect the Soil moisture sensor as shown in Figure 1:

  • Vcc PIN to 3.3V,
  • A0 PIN to A0.

Note: probe PINs can also be inverted.

Tip: you can make the probe with two rigid copper wires.

2. Sketch

Write a sketch K to define:

  • the input connection: Soil :: A0
  • threshold variables: d (dry) and w (wet)
  • the events to send: Dry, Wet (see Figure 2)
  • the rules to turn on the status LED when the soil is dry and turn it off when it is wet.
Soil :: A0
d = 100
w = 700
Dry = Soil<d
Wet = Soil>w
Dry -> led=1
Wet -> led=0

or simply load the sketch in the workspace with the command

] load e16_soil_moisture


Figure 2 - Dry and Wet Thresholds

3. Try and learn

1. Take a glass of water and insert the sensor into the glass:

  • < Wet

the Wet event happens and is sent over the Internet; the status LED turns off.

Pull the sensor out of the glass:

  • < Dry

the Dry event happens and is sent over the Internet; the status LED turns on.

2. Insert the sensor into a dry plant and read the Soil value with the command:

  • ] Soil #1

determine the threshold value and set the variable d.

After watering the plant and changing the threshold w, insert:

  • ] stop

to stop reading Soil

  • ] save

to store the new sketch.

4. Summarizing

In these lesson you learned or repeated:

  • how to use a Soil moisture sensor
  • how to define events to be sent over the Internet

Video 1 - soil moisture