Programme gets stuck

I have a CO2 Calcium reactor for my aquarium which is controlled by an Arduino. The basic function is the following

1/ A float switch within the reactor determines how much CO2 is in the reactor. As the CO2 is lost or absorbed the float switch switches on and off a solenoid switch.

2/ A stepper pump puts water into the reactor which in turn overflows into the tank as saturated calcium water. The interval at which the stepper pump goes on is pre-set within the programme. The duration of an "On" period is determined by a potentiometer.

3/ There are 2 circulation pumps on the reactor to turn the water around within.

4/ In order for the reactor to function at its optimum it needs to be degassed daily and depending on stock levels this is a variable which needs to be changed. The de-gassing can vary from once a day to 6 times a day. The way this is achieved is by using a multi switch connected to the Arduino. So if switch 1 is high we are working to degas programme 1 ect ect..

Everything works fine except for the part where the reactor switches off to degas it does not switch on again. it gets stuck on the degas off.

Could somebody kindly have a look through my code to see where I might have gone wrong. You will notice from the code I thought that maybe after the degas has taken place I could just tell the programme to re- setup. I ma not sure though if this will work.

AquaArt_CO2.ino (8.93 KB)

All those while loops and trying to tell the whole day's story in one pass of loop is a poor design. This should be a state machine. There shouldn't be a single while loop anywhere in it. You should just check to see if it is time to turn the degas on or off and if so do it. Let the loop function do the looping.

Ok. I will try that.

Meanwhile take a look at AlarmCheck().

At a glance you appear to be overusing the variable you meant to be a constant, AlarmSt.

I can't tell just how the alarm is meant to function but I can see it won't.

It looks like you could temporarily remove/disable the alarm function, fix/write the main stuff, then turn your attention to the design of the alram. DVQ.

a7

Ok I have now created a state machine which works fine. I have also revised the alarm situation by writing it into the float switch function but it still does not work. The float switch itself works fine the only thing is no alarm comes on after 5 minutes. Any suggestions?

AquaArt_CO2.ino (13.7 KB)

Any suggestions?

What do your Serial.print() statements tell you is happening?

Why not?

I found a library that sorts the alarm function out. However I would be grateful if someone could have a look at my sketch (void FloatSW() ) and just let me know why it did not work so that I can learn.
Thanks