wokwi / wokwi-elements

Web Components for Electronics and IoT Parts
https://elements.wokwi.com/
MIT License
181 stars 48 forks source link

FC-28 Soil Moisture Sensor #98

Open arcostasi opened 3 years ago

arcostasi commented 3 years ago

FC-28 Soil Moisture Sensor is a simple breakout for measuring the moisture in soil and similar materials. The soil moisture sensor is pretty straight forward to use. The two large exposed pads function as probes for the sensor, together acting as a variable resistor. The more water that is in the soil means the better the conductivity between the pads will be and will result in a lower resistance, and a higher AOUT.

fc-28-moisture-sensor

The FC-28 module has both digital and analog outputs. The analog output AO of the FC-28 gives a direct analog value of sensor readings, because it is the value of voltage drop across the probe. So analog output value returns a voltage value proportional to the resistance of the soil. That is, value will be high when the soil is dry and the value decreases as it gets wet.

The FC-28 module has a threshold adjust potentiometer for the digital output to preset the required threshold value. The sensor value will be compared with this threshold value by the LM393 comparator. When the sensor value is above the set threshold value the digital output DO will switch to a HIGH state (+5V). That is if the soil is less moisture then the voltage across the probe becomes high and that switches digital output to high state. The output LED is just inverse to the digital output if DO is High then the LED turns OFF. An ON DO LED indicates that the resistance is low than the threshold that is the the soil moisture is higher than threshold.


Technical Specifications

Pinouts

Documents

Code

To connect the sensor in the analog mode, we will need to use the analog output of the sensor. When taking the analog output from the soil moisture sensor FC-28, the sensor gives us the value from 0-1023. The moisture is measured in percentage, so we will map these values from 0 -100 and then we will show these values on the serial monitor.

const int sensorPin = A0;

void setup() {
  Serial.begin(9600);
  pinMode(sensorPin, INPUT);
}

void loop() {
  int analogValue = analogRead(sensorPin);
  int moisture = map(analogValue, 0, 1023, 0, 100);

  Serial.print("Moisture in soil: ");
  Serial.println(moisture);
  delay(1000);
}
leftCoast commented 2 years ago

That's a terrible moisture sensor. How about using the el'-cheapo capacitive one you can find on Amazon? Those, if you calibrate them, (Well, and seal them up from getting water in their entrails) typically work great for years.

arcostasi commented 2 years ago

I understand, this sensor is widely used here in Brazil due to its low cost and many students buy this sensor to do some project at home or at school. But it's always good to know something more precise and of better quality. I appreciate the suggestion.