Hello,
I am using Arduino UNO for my project. In this project I use a single-pole-double-throw relay. I need to use both states of a relay (i.e. I control a pump when there is no connection established and control a solenoid valve when there is). My code is as follows:
void regular_fill (){
unsigned long time, old_time;
int check_period = 1000;//check period = 1 sec --> pause between pressure switch checks
ll_reading = check_ll(); //initial check --> double check for an error in "loop" function
ul_reading = check_ul(); //initial check
old_time = millis (); //reference time, needed for periodical check of pressure switch
while (ll_reading == 1 && ul_reading !=1){
//code block for pressure switch check
time = millis();
if ((time-old_time)>=1000){
ps_reading = check_ps();
old_time = time;
}
if (ps_reading == 1)
return;
digitalWrite (lower_relay, LOW);
delay (100);
ul_reading = check_ul(); //continuos check to meet WHILE loop condition
}
//want to return lower_relay to HIGH here
/* how do I return lower_relay to HIGH so that it stays there forever or
until I change its state?
digitalWrite (lower_relay, HIGH);//turn OFF 24V airgap pump and airgap solenoid valve --> quite sure will not work
*/
return;
}
In the code above, for this subroutine, I need the state of upper_relay to be LOW until I hit certain water level and after I need to drop the relay to another state. But to do this, I need to set lower_relay to HIGH and it needs to stay at HIGH for other parts of code to be functional.
Please suggest how to set a digital pin to HIGH so that it will be in that state globally until I call it up again (i.e. want to have HIGH as default).
I know I could change relay connections, but it will interfere with voltage-sensitive components.... thus I really cannot change my circuit..