Hi, I'm working on an assignment that needs to meet the below requirements. This is my first time using C++ and
wanted to know if the code I've written is going about this in the right way.
Scenario
a control system is 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’
I have no experience with code and i am struggling to work out where i am going wrong.
Any help is much appreciated
Thanks
int Pump1 = 8;
int Pump2 = 9;
int Alarm = 4;
int sensorPin = 1;
int LowWaterLevel = 1023*0.1;
int HighWaterLevel = 1023*0.9;
void setup()
{
pinMode (Pump1,OUTPUT);
pinMode (Pump2,OUTPUT);
pinMode (Alarm,OUTPUT);
}
void loop()
{
if(analogRead(sensorPin)<=HighWaterLevel)
digitalWrite(Pump1, LOW);
}
if(analogRead(sensorPin)>=HighWaterLevel)
{digitalWrite(Pump1,HIGH);
delay(30000);
}
if(analogRead(sensorPin)<=LowWaterLevel)
{digitalWrite(Pump1,LOW);
}
else{digitalWrite(Pump2,HIGH);
delay(30000);
}
if(analogRead(sensorPin)<=LowWaterLevel)
{digtalWrite(Pump1 && Pump2,LOW);
}
else{digitalWrite(Pump1&&Pump2, LOW);
digitalWrite(Alarm,HIGH);
}
if(analogRead(sensorPin)<=LowWaterLevel)
{DigitalWrite(Alarm, LOW);
}
File 1.pdf (60.3 KB)