Kit 001

💻 Step 3 – Upload the Code

You’ve wired your system — now it’s time to make it smart.

We’ll upload a simple Arduino program that reads your soil moisture sensor and turns the water pump on when the soil gets too dry.

🧰 What You’ll Need

  • Arduino IDE installed

  • USB-C cable to connect your Arduino

  • The code below (or download from GitHub)

What This Code Does

  • Checks the sensor once per second

  • If the moisture level is too low (above 1000), it activates the pump

  • Otherwise, it keeps the pump off

const int moisturePin = A0;    // Moisture sensor connected to A0
const int relayPin = 7;        // Relay control pin
const int dryThreshold = 600; // Trigger threshold (adjust if needed)

void setup() {
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH); // Start with relay OFF
  Serial.begin(9600);          // For debugging
}

void loop() {
  int moisture = analogRead(moisturePin); // Read sensor value
  Serial.print("Moisture level: ");
  Serial.println(moisture);               // Print value to Serial Monitor

  if (moisture > dryThreshold) {
    Serial.print("Watering...");
    digitalWrite(relayPin, LOW); // Turn pump ON
    delay(5000);                  // Run pump for 5 seconds
    digitalWrite(relayPin, HIGH);  // Turn pump OFF
    Serial.print("Watering complete");
  }

  delay(2000); // Wait 2 seconds before next read
}

Select Your Board & Port

  • In Arduino IDE:

    • Go to Tools → Board → Arduino Uno R4 WiFi

    • Then Tools → Port and select your Arduino’s port (e.g., COM3 or /dev/tty.usbmodem...)

5. Click Upload

  • Hit the ✓ checkmark to verify

  • Click the → arrow to upload

  • Open Serial Monitor to see real-time moisture values

What’s a “Moisture Value”?

  • Dry soil = High value (usually 800–1023)

  • Wet soil = Low value (300–700)

  • You can tweak the if (moisture > 1000) value to make it more or less sensitive

Let's move on to the final step

© All rights reserved

© All rights reserved