/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: Irrigation Controller
- Source Code NOT compiled for: Arduino Uno
- Source Code created on: 2025-11-23 12:09:35
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* the pump should on when the soil is dry */
/****** END SYSTEM REQUIREMENTS *****/
/* START CODE */
#include
#include
// Define relay and sensor pins
const int relayPin = 8; // Digital pin for relay control
const int sensorPin = A0; // Analog pin for soil moisture sensor
// Variable to hold sensor reading
int soilMoistureValue;
// Moisture threshold below which the pump should turn on
const int moistureThreshold = 20; // System Requirement 1
// Initialize relay object
RelayModule relay(relayPin);
// Setup function
void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(relayPin, OUTPUT); // Set relay pin as output
pinMode(sensorPin, INPUT); // Set sensor pin as input
relay.begin(); // Initialize relay
Serial.println("Reading From the Sensor ...");
delay(2000);
}
// Loop function
void loop() {
// Read soil moisture sensor
soilMoistureValue = analogRead(sensorPin);
// Map sensor value to percentage
soilMoistureValue = map(soilMoistureValue, 550, 10, 0, 100);
Serial.print("Moisture : ");
Serial.print(soilMoistureValue);
Serial.println("%");
// Check moisture level and control relay
if (soilMoistureValue < moistureThreshold) {
relay.off(); // Turn pump ON when soil is dry
} else {
relay.on(); // Turn pump OFF when soil is moist enough
}
delay(1000); // Wait for 1 second
}
/* END CODE */