Sensor

๐ŸŒฑ Soil Humidity Sensor

๐Ÿ“Œ Description

The soil humidity sensor detects whether the soil is dry or moist. It works by measuring conductivity: wet soil conducts electricity better than dry soil. The sensor sends a digital signal (HIGH or LOW) to the microcontroller.

๐ŸŽฏ Use

In our projects, the soil humidity sensor is used to:

  • Monitor plant watering needs.
  • Trigger irrigation systems automatically.
  • Help robots interact with natural environments.

๐Ÿ‘‰ Think of the soil humidity sensor as the robotโ€™s gardener tool โ€” it tells the robot if plants need water.

Module parameters

Pin name Description
G GND (Power Input Negative)
V VCC (Power Input Cathode)
S Digital signal pins
A Analog signal pins
  • Supply voltage: 3.3V/5V
  • Connection: 2.54mm pin header
  • Installation method: double screw fixing

๐Ÿ–ฅ๏ธ Code Explanation

import machine

pin26 = machine.Pin(26, machine.Pin.IN)    # Sensor input
pin17 = machine.Pin(17, machine.Pin.OUT)   # LED output

while True:
    if pin26.value() == 1:                 # If soil is dry
        pin17.value(0)                     # LED OFF
        print('dry soil')
    else:                                  # If soil is moist
        pin17.value(1)                     # LED ON
        print('Moist soil')

Step by Step

  1. pin26 = machine.Pin(26, machine.Pin.IN) โ†’ Reads the soil sensorโ€™s digital signal.
  2. pin17 = machine.Pin(17, machine.Pin.OUT) โ†’ Controls the LED (output).
  3. while True: โ†’ Loop that repeats forever.
  4. if pin26.value() == 1: โ†’ Checks if soil is dry.
  5. pin17.value(0) โ†’ LED stays off when soil is dry.
  6. print('dry soil') โ†’ Displays message โ€œdry soilโ€.
  7. else: โ†’ If soil is moistโ€ฆ
  8. pin17.value(1) โ†’ LED turns on.
  9. print('Moist soil') โ†’ Displays message โ€œMoist soilโ€.

๐Ÿ‘‰ Together, this program makes the LED indicate soil condition and prints the status.


โœ… Conclusion of the Test

  • If the LED stays off and the console prints โ€œdry soilโ€ when the soil is dry, and turns on with โ€œMoist soilโ€ when the soil is wet, the program is working correctly.
  • This test shows how the robot can sense soil moisture and react with an output (LED + message).
  • Later, the sensor could be connected to a pump or irrigation system to automatically water plants when the soil is dry.
On this page