pleasedontcode

Irrigation Controller rev_01

Nov 23rd, 2025
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Irrigation Controller
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-11-23 12:09:35
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* the pump should on when the soil is dry */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23.  
  24. /* START CODE */
  25.  
  26. #include <Relay.h>
  27. #include <RelayModule.h>
  28.  
  29. // Define relay and sensor pins
  30. const int relayPin = 8; // Digital pin for relay control
  31. const int sensorPin = A0; // Analog pin for soil moisture sensor
  32.  
  33. // Variable to hold sensor reading
  34. int soilMoistureValue;
  35.  
  36. // Moisture threshold below which the pump should turn on
  37. const int moistureThreshold = 20; // System Requirement 1
  38.  
  39. // Initialize relay object
  40. RelayModule relay(relayPin);
  41.  
  42. // Setup function
  43. void setup() {
  44.   Serial.begin(9600); // Initialize serial communication
  45.   pinMode(relayPin, OUTPUT); // Set relay pin as output
  46.   pinMode(sensorPin, INPUT); // Set sensor pin as input
  47.   relay.begin(); // Initialize relay
  48.   Serial.println("Reading From the Sensor ...");
  49.   delay(2000);
  50. }
  51.  
  52. // Loop function
  53. void loop() {
  54.   // Read soil moisture sensor
  55.   soilMoistureValue = analogRead(sensorPin);
  56.   // Map sensor value to percentage
  57.   soilMoistureValue = map(soilMoistureValue, 550, 10, 0, 100);
  58.   Serial.print("Moisture : ");
  59.   Serial.print(soilMoistureValue);
  60.   Serial.println("%");
  61.  
  62.   // Check moisture level and control relay
  63.   if (soilMoistureValue < moistureThreshold) {
  64.     relay.off(); // Turn pump ON when soil is dry
  65.   } else {
  66.     relay.on(); // Turn pump OFF when soil is moist enough
  67.   }
  68.   delay(1000); // Wait for 1 second
  69. }
  70.  
  71. /* END CODE */
  72.  
Advertisement
Add Comment
Please, Sign In to add comment