Question: const int HIGH _ TRANS _ PIN = 6 ; / / Replace with the actual pin number for the HIGH transducer const int LOW

const int HIGH_TRANS_PIN =6; // Replace with the actual pin number for the HIGH transducer
const int LOW_TRANS_PIN =7; // Replace with the actual pin number for the LOW transducer
const int PUMP1_LED_PIN =12; // Replace with the actual pin number for the first pump LED
const int PUMP2_LED_PIN =11; // Replace with the actual pin number for the second pump LED
const int ALARM_LED_PIN =10; // Replace with the actual pin number for the alarm LED
unsigned long previousMillis =0;
const long interval =30000; //30 seconds interval
void setup(){
pinMode(HIGH_TRANS_PIN, INPUT);
pinMode(LOW_TRANS_PIN, INPUT);
pinMode(PUMP1_LED_PIN, OUTPUT);
pinMode(PUMP2_LED_PIN, OUTPUT);
pinMode(ALARM_LED_PIN, OUTPUT);
}
void loop(){
unsigned long currentMillis = millis();
bool pump1Active = true; // Start with pump 1
//...(inside the loop)
if (digitalRead(HIGH_TRANS_PIN)== HIGH){
//...
if (pump1Active){
digitalWrite(PUMP1_LED_PIN, HIGH);
//...(pump 1 actions)
} else {
digitalWrite(PUMP2_LED_PIN, HIGH);
//...(pump 2 actions)
}
pump1Active =!pump1Active; // Toggle active pump
}
// Check water level and take appropriate action
if (digitalRead(HIGH_TRANS_PIN)== HIGH){
// High level reached, start pumping
digitalWrite(PUMP1_LED_PIN, HIGH);
delay(1000); // Pumping time (adjust as needed)
digitalWrite(PUMP1_LED_PIN, LOW);
// Check if low level is reached within 30 seconds
if (digitalRead(LOW_TRANS_PIN)== LOW){
// Low level reached, stop pumping
digitalWrite(PUMP2_LED_PIN, LOW);
digitalWrite(ALARM_LED_PIN, LOW);
} else {
// Low level not reached within 30 seconds, activate second pump
digitalWrite(PUMP2_LED_PIN, HIGH);
delay(10); // Pumping time (adjust as needed)
digitalWrite(PUMP2_LED_PIN, LOW);
// Check if low level is reached within 30 seconds
if (digitalRead(LOW_TRANS_PIN)== LOW){
// Low level reached, stop pumping
digitalWrite(ALARM_LED_PIN, LOW);
} else {
// Low level not reached within additional 30 seconds, sound alarm
digitalWrite(ALARM_LED_PIN, HIGH);
}
}
// Reset the timer
previousMillis = currentMillis;
}
// Check if 30 seconds have passed since the last check
if (currentMillis - previousMillis >= interval){
//30 seconds passed, stop all pumps and alarm
digitalWrite(PUMP1_LED_PIN, LOW);
digitalWrite(PUMP2_LED_PIN, LOW);
digitalWrite(ALARM_LED_PIN, LOW);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!