const int SMS1P = 48;
const int SMS1N = 49;
const int SMS2P = 46;
const int SMS2N = 47;
const int RDSP = 50;
const int RDSN = 51;
const int SMS1O = A11;
const int SMS2O = A12;
const int RDSO = A13;
const int Rline = 24;
const int Yline = 26;
const int Bline = 28;
const int Solenoid = 30;
int RDS = 0;
int SMS1 = 0;
int SMS2 = 0;
void rain_drop_sensor_ON();
void Soil_Moisture_Sensor1_ON();
void Soil_Moisture_Sensor2_ON();
void rain_drop_sensor_OFF();
void Soil_Moisture_Sensor1_OFF();
void Soil_Moisture_Sensor2_OFF();
void Solenoid_ON();
void Solenoid_OFF();
void Three_Phase_Motor_ON();
void Three_Phase_Motor_OFF();
void read_Sensors_value();
void setup() {
pinMode(SMS1P, OUTPUT);
pinMode(SMS2P, OUTPUT);
pinMode(SMS1N, OUTPUT);
pinMode(SMS2N, OUTPUT);
pinMode(RDSP, OUTPUT);
pinMode(RDSN, OUTPUT);
pinMode(SMS1O, INPUT);
pinMode(SMS2O, INPUT);
pinMode(RDSO, INPUT);
pinMode(Rline, OUTPUT);
pinMode(Yline, OUTPUT);
pinMode(Bline, OUTPUT);
pinMode(Solenoid, OUTPUT);
Three_Phase_Motor_OFF();
Solenoid_OFF();
Serial.begin(9600);
}
void loop() {
rain_drop_sensor_ON();
Soil_Moisture_Sensor1_ON();
Soil_Moisture_Sensor2_ON();
read_Sensors_value();
RDS = analogRead(RDSO);
SMS1 = analogRead(SMS1O);
SMS2 = analogRead(SMS2O);
delay(10);
if (SMS1 < 100 && SMS2 < 100 && RDS > 200)
{
Three_Phase_Motor_ON();
Solenoid_ON();
}
else if (SMS1 < 100 && SMS2 < 100 && RDS < 200)
{
Three_Phase_Motor_OFF();
Solenoid_OFF();
}
else if (SMS1 < 100 && SMS2 > 100 && RDS > 200)
{
Three_Phase_Motor_ON();
Solenoid_OFF();
}
else if (SMS1 < 100 && SMS2 > 100 && RDS < 200)
{
Three_Phase_Motor_ON();
Solenoid_OFF();
}
else if (SMS1 > 100 && SMS2 < 100 && RDS > 200)
{
Three_Phase_Motor_OFF();
Solenoid_ON();
}
else if (SMS1 > 100 && SMS2 < 100 && RDS < 200)
{
Three_Phase_Motor_OFF();
Solenoid_OFF();
}
else if (SMS1 > 100 && SMS2 > 100 && RDS > 200)
{
Three_Phase_Motor_OFF();
Solenoid_OFF();
}
else if (SMS1 > 100 && SMS2 > 100 && RDS < 200)
{
Three_Phase_Motor_OFF();
Solenoid_OFF();
}
else
{
Three_Phase_Motor_OFF();
Solenoid_OFF();
}
}
void rain_drop_sensor_ON()
{
digitalWrite(RDSP, HIGH);
digitalWrite(RDSN, LOW);
}
void Soil_Moisture_Sensor1_ON()
{
digitalWrite(SMS1P, HIGH);
digitalWrite(SMS1N, LOW);
}
void Soil_Moisture_Sensor2_ON()
{
digitalWrite(SMS2P, HIGH);
digitalWrite(SMS2N, LOW);
}
void rain_drop_sensor_OFF()
{
digitalWrite(RDSP, LOW);
digitalWrite(RDSN, LOW);
}
void Soil_Moisture_Sensor1_OFF()
{
digitalWrite(SMS1P, LOW);
digitalWrite(SMS1N, LOW);
}
void Soil_Moisture_Sensor2_OFF()
{
digitalWrite(SMS2P, LOW);
digitalWrite(SMS2N, LOW);
}
void Solenoid_ON()
{
digitalWrite(Solenoid, LOW);
}
void Solenoid_OFF()
{
digitalWrite(Solenoid, HIGH);
}
void Three_Phase_Motor_ON()
{
digitalWrite(Rline, LOW);
digitalWrite(Yline, LOW);
digitalWrite(Bline, LOW);
}
void Three_Phase_Motor_OFF()
{
digitalWrite(Rline, HIGH);
digitalWrite(Yline, HIGH);
digitalWrite(Bline, HIGH);
}
void read_Sensors_value()
{
SMS1 = analogRead(SMS1O);
SMS2 = analogRead(SMS2O);
RDS = analogRead(RDSO);
Serial.println(SMS2);
Serial.println(SMS1);
Serial.println(RDS);
delay(2000);
}
Comments