AdSense

Wednesday, July 5, 2017

4 - Arduino: Hygrometer for sensing soil moisture


ARDUINO: HYGROMETER FOR SENSING SOIL MOISTURE

- Layout for this exercise:




- The goal of this exercise is to build an Arduino circuit able to detect moisture levels, for instance it could be used for a pot of plants.

- The circuit will trigger a couple of alarms (buzzer sound and red LED) whenever the moisture level is under a moisture threshold specified at the Arduino sketch.

- There are several moisture sensor available in the market, for instance the HL-69, YL-69, FC-28, ..., all of them compatible with the Arduino board.

- A moisture sensor consists of two parts: a prong sensor and a controller.

- On one side the controller is directly connected to the sensor, on the other side it is connected to the Arduino board:

  • AO (Analog Output) -> A0
  • DO (Digital Output) -> not used
  • GND (Ground) -> GND
  • VCC -> +5 V


- Code:




- Let's analyze the code.

- First of all, the readings are taken from the analog A0 pin connected to the controller:






- Because the range of digital conversion at the analog input A0 is from 0 to 1023, let's calibrate the reading so that 0 corresponds to 100% and 1023 to 0% of moisture:




- When moisture is below 20% the two alarms are triggered: a buzzer produces a sound of 2000 Hz and a red LED blinks:




- Also, the serial ouput prints the moisture level on the screen every 2 seconds, whenever a new reading is made. In this picture the % of moisture varies abruptly when the sensor detects water:




- Testing the circuit, when the sensor is touching dry soil the buzzer beeps and the red LED blinks. However, if water is added to the soil both the beep and red light stop. Also, a message is printed through the serial monitor displaying the increase in humidity level: