// for use with Capacitive Moisture Sensor (CMS)
// Replace POT with the CMS
// as each CMS is slightly difference will need to adjust dry and wet values
//Constants
const int dry = 561; // value for dry sensor
const int wet = 318; // value for very wet
int moistureVal =0;
void setup()
{
Serial.begin(9600);
pinMode(11, OUTPUT); // Green LED
pinMode(12, OUTPUT); // Yellow LED
pinMode(13, OUTPUT); // Red LED
}
void loop()
{
int sensorVal = analogRead(A0);
// sensor has a range of 318 to 559
// need to translate this to a scale like 0% to 100%
// reference https://www.arduino.cc/reference/en/language/functions/math/map
int percentageHumidity = map(sensorVal, wet, dry, 100, 0);
Serial.print(percentageHumidity);
Serial.print("%");
// Serial.print(" - ");
// Serial.print("Analog = ");
// Serial.print(analogRead(A0));
if(sensorVal >= 500) {
Serial.println(" - Dry");
int moistureVal = 1;
// Serial.print(" - LED ");
// Serial.println(moistureVal);
// Setting LED Indicators
digitalWrite(11, LOW); // Turn off Green LED
digitalWrite(12, LOW); // Turn off Yellow LED
digitalWrite(13, HIGH); // Turn on Red LED
} else if (sensorVal >= 350) {
Serial.println(" - Good");
int moistureVal = 2;
// Serial.print(" - LED ");
// Serial.println(moistureVal);
// Setting LED Indicators
digitalWrite(11, HIGH); // Turn on Green LED
digitalWrite(12, LOW); // Turn off Yellow LED
digitalWrite(13, LOW); // Turn off Red LED
} else {
Serial.println(" - Wet");
moistureVal = 0;
// Serial.print(" - LED ");
// Serial.println(moistureVal);
// Setting LED Indicators
digitalWrite(11, LOW); // Turn off Green LED
digitalWrite(12, HIGH); // Turn on Yellow LED
digitalWrite(13, LOW); // Turn off Red LED
}
delay(500); // in milliseconds
}