Capacitive Soil Moisture Sensor

Capacitive Moisture Sensor

Step 1: Connecting the Capacitive Soil Moisture Sensor

The Capacitive Soil Moisture Sensor will provide readings on the soil moisture level.

  1. Connect the VCC pin of the Soil Moisture Sensor to the 3.3V power pin on the Automation Hat.
  2. Connect the GND pin of the Soil Moisture Sensor to a ground (GND) pin on the Automation Hat.
  3. Connect the analog output pin (AOUT) of the Soil Moisture Sensor to an analog input pin on the Automation Hat. For example, A1.

Step 2: Reading humidity Sensor Values

First, we need to read the humidity from the sensor using the Automation HAT library. The read() function reads the ADC value from the sensor:

Converting the ADC value to percentage

The output of the sensor is an Analog-to-Digital Convertor (ADC) value. The humidity is generally represented as a percentage, so we need to convert the ADC value to a humidity percentage.

The following function does this conversion:

Note: Here, `min_value` and `max_value` represent the minimum and maximum ADC values corresponding to your specific sensor at 0% and 100% humidity respectively. These values might vary based on your sensor, so make sure to calibrate your sensor based on the actual readings.

Outputting the Humidity Reading on the Screen

For the final step, we will get the humidity percentage to be displayed on the Automation Hat's screen continuously.

Combining everything together

The following loop will endlessly read the humidity, convert it to a percentage, and draw the result on the screen:

Co funded by the EU

Funded by the European Union. Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or the European Education and Culture Executive Agency (EACEA). Neither the European Union nor EACEA can be held responsible for them.

Project Number: 2023-3-CY02-KA210-YOU-000173087