Arduino(10): soil moisture detection YL-38 + YL-69

After the exam, my son brought a pot of cactus family back from the school and left it for a few days. He didn't know when to water it, and he was afraid that if he watered too much or too little, the plants would not grow well. I want to use the soil moisture sensor of Arduino to make a sensor. Originally, I only used the serial port window to read the values, but I usually turn on the computer, so I designed an LED light. When the humidity is too low, the light will turn on to indicate that it is time to water.

The sensor uses the LM393 chip, which is a simple humidity sensor that can be used to detect the moisture content of the soil. When the soil lacks water, the output value of the sensor becomes larger, and vice versa. If you need to adjust the sensitivity, you can adjust the blue potentiometer in the figure.

The soil moisture sensor module can be made into an automatic watering device. This module can detect whether the plants are thirsty or not when they are not at home for a long time or need automatic watering. Cooperate with Arduino controller to make plants more comfortable and garden smarter.

[Material]

  • Arduino Nano x 1
  • Soil moisture detection module
  • Breadboard x 1
  • Connecting wires x N

[Wiring diagram]

Connect the VCC and GND of the soil moisture detection module (the same two-piece soil moisture detection module diagram of Fritzing was not found, so I had to replace it with a single detector) to 5V and GND of the Arduino to sense The AO of the device is connected to Arduino A2. The two LEDs are grounded with Pin 3.


[Code]

const int sensorPin=2;
int LEDRed = 3;
void setup()
{
  pinMode(LEDRed, OUTPUT);    
  pinMode(sensorPin,INPUT);
  Serial.begin(9600);
}
 
void loop()
{
  int moist;
  moist = analogRead(sensorPin);
  Serial.println(moist);
  
  // Lights up when the dryness is greater than 800
  if (moist > 800) {
       digitalWrite(LEDRed, HIGH); }
  else {
      digitalWrite(LEDRed, LOW);  }
  delay(1000);
}

[Result]

Display the detected humidity value from the serial interface:

[Reference]

  • Sample program provided by the manufacturer

Post a Comment

Previous Post Next Post