Here I will put a code with the YL-69 sensor so that it detects the humidity of a plant and be able to implement an auto-irrigation system so that when it detects that it is dry, it waters.
int rainPin = A0; int greenLED = 6; int redLED = 7; int thresholdValue = 800; // void setup(){ //definim pinMode(rainPin, INPUT); pinMode(greenLED, OUTPUT); pinMode(redLED, OUTPUT); digitalWrite(greenLED, LOW); digitalWrite(redLED, LOW); Serial.begin(9600); } void loop() { // read the input on analog pin 0: int sensorValue = analogRead(rainPin); Serial.println(sensorValue); if(sensorValue < thresholdValue){ Serial.println(" - Doesn't need watering"); digitalWrite(redLED, LOW); digitalWrite(greenLED, HIGH); } else { Serial.println(" - Time to water your plant"); digitalWrite(redLED, HIGH); digitalWrite(greenLED, LOW); } delay(500); }