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);
}
}
**