Advertisement

Saturday, December 6, 2025

my smart irrigation code

 // Automatic Irrigation System - Project Submission Version

// Om's Project


const int sensorPin = A0;   // Moisture sensor analog output

const int relayPin = 8;     // Relay IN pin (active LOW)


// Threshold value: adjust based on dry and slightly wet soil readings

const int threshold = 600;  


void setup() {

  pinMode(sensorPin, INPUT_PULLUP);  // Fix floating pin issue

  pinMode(relayPin, OUTPUT);

  digitalWrite(relayPin, HIGH);      // Relay OFF at start

  Serial.begin(9600);                // Optional: view sensor readings

}


void loop() {

  int moistureValue = analogRead(sensorPin);  // Read sensor

  Serial.print("Moisture Value: ");

  Serial.println(moistureValue);


  // Check soil condition

  if (moistureValue < threshold) {   // Soil is dry

    digitalWrite(relayPin, LOW);     // Turn motor ON

  } else {                            // Soil is wet

    digitalWrite(relayPin, HIGH);    // Turn motor OFF

  }


  delay(500);  // Small delay for stability

}


my smart irrigation code

 // Automatic Irrigation System - Project Submission Version // Om's Project const int sensorPin = A0;   // Moisture sensor analog outpu...