Soil Moisture & Rain Sensors
Next on the new sensors to play with list is a soil moisture sensor and the similar rain sensor, both use the same LM393 opamp comparator board.
The pinout is:
AO - A7
DO - D2
VCC - 3.3v
GND - GND
The digital output basically gives a 0/1 based on if the moisture/rainfall has reached a certain level (adjusted with the trimpot).
My code is:
const int aPin = A7;
const int dPin = 2;
int moisture = 0;
bool isRaining = false;
void setup()
{
Serial.begin(9600);
pinMode(aPin, INPUT);
pinMode(dPin, INPUT);
}
void loop()
{
isRaining = !digitalRead(dPin);
if (isRaining)
{
Serial.println("It is raining");
moisture = 1023-analogRead(aPin);
Serial.print("Moisture level: ");
Serial.println(moisture);
}
else
{
Serial.println("It is not raining");
}
delay(500);
}
I found that the reading levels for the moisture sensor were approximately:
0 = air
400 = damp
700 = submerged
And for the rain sensor:
500 = raining
800 = pissing it down