// Capacitive Moisture Sensor // XIAO RP2040 const int sensorPin = A0; // Pin zero for the moisture sensor const int redLED = D1; // DRY const int blueLED = D2; // WET int moistureValue = 0; void setup() { pinMode(redLED, OUTPUT); pinMode(blueLED, OUTPUT); Serial.begin(115200); // baud rate for serial viewer allows text to be readable } void loop() { // Average 20 readings for stability long total = 0; for (int i = 0; i < 20; i++) { total += analogRead(sensorPin); delay(5); } moistureValue = total / 20; // WET if (moistureValue < 500) { digitalWrite(blueLED, HIGH); digitalWrite(redLED, LOW); Serial.print("Moisture Value: "); Serial.print(moistureValue); Serial.println(" --> WET"); } // DRY else { digitalWrite(blueLED, LOW); digitalWrite(redLED, HIGH); Serial.print("Moisture Value: "); Serial.print(moistureValue); Serial.println(" --> DRY"); } delay(700); }