Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write code to produce a program to the below specification: Code must alternate pumps on start up FIGURE 1 shows part of a control system

Write code to produce a program to the below specification:
Code must alternate pumps on start up
FIGURE 1 shows part of a control system used to maintain the water level in a
sump between the levels high and low. Two transducers (HIGH and LOW) are
used to monitor the level. The water is pumped out by two pumps, P1 and P2.
The water level in the sump is to be controlled as follows:
If the level reaches high one pump will start to pump out.
If the level does not reach low within about 30 seconds, the second pump
will come into action. If the level does reach low before 30 second
pumping should stop.
If the level does not reach low within about 30 seconds of the second
pump starting, an alarm is given. The alarm is sounded until the level
reaches low. If the level does reach low before 30 seconds the pumping
should stop.
The pumps will stop when low is detected.
To give even loading of the pumps they are to be used alternately, e.g. if
on one pump cycle P1 starts first and P2 is the back up then on the next
cycle P2 will start first and P1 is the back up
Please check your program functions as per the specification and i will leave you thumbs up
Please check this code to see where I am going wrong. Must simulate the code using tinkercad before answering question:
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

ISBN: 3319234609, 978-3319234601

Students also viewed these Databases questions