Working of code for irrigation system.

I am creating an irrigation system and would like to know if this code will work.
I've used 8 water pumps, 3-6v, Water level sensors, bluetooth module (HC-05),LED. Code's incomplete, but I would like to know if the last part will work before continuing.

**
String b;
#include <LiquidCrystal.h>
#include <RTClib.h>
#include <Wire.h>
#include <Servo.h>
Servo MyServo;
RTC_DS1307 rtc;
LiquidCrystal lcd (12,11,5,4,3,2);
#define Buzzer 10
#define LED_R 9
int AlluvialPump = 28 ;
int SandyPump = 27 ;
int BlackPump = 26 ;
int RYPump = 25 ;
int LateritePump = 24 ;
int MountainPump = 23 ;
int RWTPump = 22 ;
int SupplyTPump = 30;
const int read = A0; //Sensor AO pin to Arduino pin A0
int MT;
const int read1 = A1; //Sensor AO pin to Arduino pin A0
int RWT;
const int sensorMin = 0;
const int sensorMax = 1024;
int RainDrop = A2;
void setup() {
// put your setup code here, to run once:
pinMode(AlluvialPump, OUTPUT);
pinMode(RainDrop, INPUT);
pinMode(SandyPump, OUTPUT);
pinMode(BlackPump, OUTPUT);
pinMode(RYPump, OUTPUT);
pinMode(LateritePump, OUTPUT);
pinMode(MountainPump, OUTPUT);
pinMode(RWTPump, OUTPUT);
pinMode(Buzzer, OUTPUT);
pinMode(LED_R, OUTPUT);
MyServo.attach(8);
MyServo.write(0);
Serial.begin(9600);
rtc.begin(); // Initialize the rtc object
lcd.begin(20, 4); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display }
Wire.begin();
lcd.clear();
}

void loop() {
// put your main code here, to run repeatedly:
DateTime now = rtc.now(); // Clock call
now = rtc.now();
if(Serial.available()>0){
b=Serial.readString();

Serial.println(b);

MT = analogRead(read);
if (MT<=480){
Serial.println("Water level: 0mm - Empty!");
}
RWT = analogRead(read1);

int sensorReading = analogRead(A2);
int range = map(sensorReading, sensorMin, sensorMax, 0, 2);
switch (range)
{
case 0:
Serial.println("RAINING");
MyServo.write(180);
digitalWrite(LED_R,HIGH);
break;

case 1:
Serial.println("Not Raining");
MyServo.write(0);
digitalWrite(LED_R,LOW);
if (RWT >= 710){
digitalWrite(RWTPump, HIGH);
delay(15000);
digitalWrite(RWTPump,LOW);
}
break;

}
delay(1000);
}
}
**

MasterChaos:
I am creating an irrigation system and would like to know if this code will work.
I've used 8 water pumps, 3-6v, Water level sensors, bluetooth module (HC-05),LED. Code's incomplete, but I would like to know if the last part will work before continuing.

What does "work" mean?

Please remember to use code tags when posting code.

Please do the following:

  1. Post your code properly
  2. Post a wiring diagram
  3. Define what "work" means, i.e. the requirements for your system

A few observations from what you posted:

  • sensorMax should be 1023 not 1024
  • you did not configure A0 and A1 inputs
  • you should use more descriptive names. Example, read and read1 are not descriptive.
  • if you define constants for inputs and outputs then use them.
  • the way you have loop() coded NOTHING will happen unless you have serial input. Is this your intent?
  • you have sensorReading mapped to 0-2 but you don't process case 2 in your switch statement

ToddL1962:
-- you did not configure A0 and A1 inputs

If they're used only for analogRead, it isn't necessary - don't worry you're not the first noob to incorrectly point this out.

  • you have sensorReading mapped to 0-2 but you don't process case 2 in your switch statement

If the OP "fixes" sensorMax as you suggest, case 2 will never occur only occur if the analogRead returns 1023.
Best to leave it as it is.

TheMemberFormerlyKnownAsAWOL:
What does "work" mean?

Please remember to use code tags when posting code.

What I meant is that, will the delay at the end function properly for the pump?

What does "will the delay at the end function properly for the pump?" mean?

Sometimes, I've encountered such a problem that such a delay does not work for me, so I wanted to see if anybody had encountered this problem and had a solution

Long delays will make the rest of your code unresponsive - you should avoid using them.

TheMemberFormerlyKnownAsAWOL:
If they're used only for analogRead, it isn't necessary - don't worry you're not the first noob to incorrectly point this out.

I didn't imply the OP HAD too. He configured A2 for input. I prefer to be consistent and complete. BTW, I don't consider myself a "noob". I don't know everything about all Arduinos but I've been programming and managing embedded system development for over 30 years.

If the OP "fixes" sensorMax as you suggest, case 2 will never occur only occur if the analogRead returns 1023.
Best to leave it as it is.

Depends on OP's intent. If it is left at 1024 then it will never be 2. If he doesn't want it to ever be 2 I think it would have been more clear to define a threshold value. and dispense with the map. I wanted to be sure OP understand that the input cannot be 1024.