Arduino – Soil Moisture Sensor LED Alert with Arduino Uno

Use Soil Moisture sensors and LED’s to alert you to when your plants need to be watered.

Functional Parts in the Project:

#define soilSensor1 A0
#define soilSensor2 A1

#define greenLED1 6
#define redLED1 7
#define greenLED2 8
#define redLED2 9

int goodMoisture = 300;

void setup() {
  pinMode(greenLED1, OUTPUT);
  pinMode(redLED1, OUTPUT);
  pinMode(greenLED2, OUTPUT);
  pinMode(redLED2, OUTPUT);

  Serial.begin(9600);
}

void loop() {
  int sensorValue1 = analogRead(soilSensor1);
  int sensorValue2 = analogRead(soilSensor2);
  Serial.print("Sensor 1 =  ");
  Serial.print(sensorValue1);
  Serial.print("  Sensor 2 =  ");
  Serial.println(sensorValue2);

  if (sensorValue1 < goodMoisture){
    digitalWrite(greenLED1, HIGH);
    digitalWrite(redLED1, LOW);
  } else {
    digitalWrite(greenLED1, LOW);
    digitalWrite(redLED1, HIGH);
  }

   if (sensorValue2 < goodMoisture){
    digitalWrite(greenLED2, HIGH);
    digitalWrite(redLED2, LOW);
  } else {
    digitalWrite(greenLED2, LOW);
    digitalWrite(redLED2, HIGH);
  }
  
  delay(1000);
}

Be the first to comment

Leave a Reply