Wakeup and Run

i have a program that i want to wake at a specific time turn on a relay then go back to sleep, and i have 3 inputs that will wake it to send a sms alarm but i am having issues with getting the relay to stay in for 2 minutes or to release, this is what i have so far i have moved the timing for the relay to different spots but no luck it wakes up goes to that program and stays there could someone take a look and see where I am missing on this

steve_wakeup_alarm0623.ino (6.11 KB)

Welcome to the Forum. Please read these two posts:

General Guidance and How to use the Forum
Read this before posting a programming question ...
You may also find useful information that would answer your question here:
Useful links - check here for reference posts / tutorials

It is important to provide as much of the information that is needed to solve your problem as you can, in your first posts. The forum link above has guidelines for posting in a standard way that makes it easiest for people to provide you with useful answers. Making an effort to do this will greatly increase the number and quality of helpful responses that you get.

In this case, the problem is that you have added your sketch as an attachment. Unless the sketch is too large, it's better if you post your code (using code tags!), rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.
Please edit your post and insert your code inside it, using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.

What’s this for?

if (button4 == HIGH);

The ; at the end means the IF does nothing.

It’s not a “button” if you…

pinMode(button4, OUTPUT);

…I only discovered it might perhaps be your relay, and might perhaps control a pump, from the comments in the code.

“relayPin”, or perhaps even better “pumpRelayPin”, would be a far better choice of variable name.

This code…

    if (currentMillis - startMillis > interval)
      startMillis = currentMillis;
       digitalWrite(button4, HIGH);

Looks like it is missing some { } from the indents. This is NOT python!
C/C++ requires code blocks, otherwise ONLY the first statement following the “if” gets executed.

As you have it coded…

startMillis = currentMillis;

Executes if the “if” is true.

digitalWrite(button4, HIGH);

Executes every time through loop when AlarmFlag == 0.

I’m guessing that’s every time as you did this two lines earlier…

(AlarmFlag = 0);

Although what the hell the ( ) around the statement are supposed to do (or what they actually do!) I have no idea. It’s no recognisable C/C++ syntax that I am aware of.

My personal recommendation (at least for beginners) is every control statement IF/ELSE/WHILE etc should be followed by a { } code block without exception. Even in my professional coding life this is a required coding standard. To easy to make a mistake with a code block otherwise.