/********* 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: "Rain Control" - Source Code compiled for: Arduino Uno - Source Code created on: 2024-03-20 19:14:28 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* When there is rain the motor should turn off and */ /* if there is no rain motor should work normally */ /* moreover, if ultrasonic detect water near 8cm */ /* valve should get opened. */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /***** DEFINITION OF Software Serial *****/ const uint8_t Yo_HC05_mySerial_PIN_SERIAL_TX_A0 = A0; const uint8_t Yo_HC05_mySerial_PIN_SERIAL_RX_A1 = A1; SoftwareSerial Yo_HC05_mySerial(Yo_HC05_mySerial_PIN_SERIAL_RX_A1, Yo_HC05_mySerial_PIN_SERIAL_TX_A0); /****** SYSTEM REQUIREMENTS *****/ const int rainSensorPin = 2; // Pin connected to the rain sensor const int ultrasonicPin = 3; // Pin connected to the ultrasonic sensor const int motorPin = 4; // Pin connected to the motor const int valvePin = 5; // Pin connected to the valve void setup(void) { // Initialize pin modes pinMode(rainSensorPin, INPUT); pinMode(ultrasonicPin, INPUT); pinMode(motorPin, OUTPUT); pinMode(valvePin, OUTPUT); // Initialize the SoftwareSerial communication Yo_HC05_mySerial.begin(9600); } void loop(void) { // Read the rain sensor int rainSensorValue = digitalRead(rainSensorPin); // Check if it is raining if (rainSensorValue == HIGH) { // Turn off the motor digitalWrite(motorPin, LOW); } else { // Turn on the motor digitalWrite(motorPin, HIGH); } // Read the ultrasonic sensor int ultrasonicValue = digitalRead(ultrasonicPin); // Check if water is detected near 8cm if (ultrasonicValue == HIGH) { // Open the valve digitalWrite(valvePin, HIGH); } else { // Close the valve digitalWrite(valvePin, LOW); } }