Hi @ all,
my question goes probably a bit beyond the normal relay applications and definitely beyond my current knowledge, which is why I want to ask for your support, please.
I have an external valve that sends (depending in its two positions) either a +5V signal (Position A, HIGH) or -5V signal ((Position B, LOW), continuously. So, it is not just a pulse. I could set up everything in a way that the relay goes on, when the +5V signal comes in and that it goes off, when the -5V signal comes in.
This (attached Sketch 1) is the code I have been using for that. It includes a 10 sec delay for another purpose, but it works great.
HOWEVER, I want the relay to go on with the valve moving to position A (HIGH), to stay on for XY minutes, then to go off. Then the valve goes into position B, which means that the relay is still turned off until position A kicks in again and triggers the relay to do the same thing again. Now, I have been trying to work with an "if"-function instead of "while", because it does not work to simply paste a "turn off" command into the while loop section when the relay is supposed to be turned on. Then it is just simply going on and off in a cycle depending on the delays I used. With the if-function (Code 2) it works only once and as soon as I switch from A to B and B to A, the relay does not turn on anymore unless I upload the sketch again.
So, I really need some help with that, please!
Best regards and thanks a lot in advance for any advice,
Mario.
PS: Just to quickly summarize what I want to achieve with some random timing:
Valve in position A (HIGH) for 10 minutes --> Relay goes on for 5 min --> goes off, stays off
Valve in position B (LOW) --> Relay is turned off in general
Valve in position A (HIGH) for 10 minutes --> Relay goes on for 5 min --> goes off, stays off
Valve in position B (LOW) --> Relay is turned off in general .... and so on ...
Sketch_1.ino (600 Bytes)
Sketch_2.ino (745 Bytes)