Advertisement
pleasedontcode

"Rain Control" rev_01

Mar 20th, 2024
69
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: "Rain Control"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-20 19:14:28
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* When there is rain the motor should turn off and */
  21.     /* if there is no rain motor should work normally */
  22.     /* moreover, if ultrasonic detect water near 8cm */
  23.     /* valve should get opened. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <SoftwareSerial.h>
  28.  
  29. /****** FUNCTION PROTOTYPES *****/
  30. void setup(void);
  31. void loop(void);
  32.  
  33. /***** DEFINITION OF Software Serial *****/
  34. const uint8_t Yo_HC05_mySerial_PIN_SERIAL_TX_A0 = A0;
  35. const uint8_t Yo_HC05_mySerial_PIN_SERIAL_RX_A1 = A1;
  36. SoftwareSerial Yo_HC05_mySerial(Yo_HC05_mySerial_PIN_SERIAL_RX_A1, Yo_HC05_mySerial_PIN_SERIAL_TX_A0);
  37.  
  38. /****** SYSTEM REQUIREMENTS *****/
  39. const int rainSensorPin = 2;     // Pin connected to the rain sensor
  40. const int ultrasonicPin = 3;    // Pin connected to the ultrasonic sensor
  41. const int motorPin = 4;         // Pin connected to the motor
  42. const int valvePin = 5;         // Pin connected to the valve
  43.  
  44. void setup(void)
  45. {
  46.   // Initialize pin modes
  47.   pinMode(rainSensorPin, INPUT);
  48.   pinMode(ultrasonicPin, INPUT);
  49.   pinMode(motorPin, OUTPUT);
  50.   pinMode(valvePin, OUTPUT);
  51.  
  52.   // Initialize the SoftwareSerial communication
  53.   Yo_HC05_mySerial.begin(9600);
  54. }
  55.  
  56. void loop(void)
  57. {
  58.   // Read the rain sensor
  59.   int rainSensorValue = digitalRead(rainSensorPin);
  60.  
  61.   // Check if it is raining
  62.   if (rainSensorValue == HIGH)
  63.   {
  64.     // Turn off the motor
  65.     digitalWrite(motorPin, LOW);
  66.   }
  67.   else
  68.   {
  69.     // Turn on the motor
  70.     digitalWrite(motorPin, HIGH);
  71.   }
  72.  
  73.   // Read the ultrasonic sensor
  74.   int ultrasonicValue = digitalRead(ultrasonicPin);
  75.  
  76.   // Check if water is detected near 8cm
  77.   if (ultrasonicValue == HIGH)
  78.   {
  79.     // Open the valve
  80.     digitalWrite(valvePin, HIGH);
  81.   }
  82.   else
  83.   {
  84.     // Close the valve
  85.     digitalWrite(valvePin, LOW);
  86.   }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement