Arduino "Trigger" NO Pushbutton

Hello, I am currently trying to write a code utilizing a N.O. pushbutton as a "trigger" to write a digital pin to high. I have a selector switch one going to pin 8,7 on my arduino. I am wanting the arduino to read which pin is "HIGH" (5V) and digitalWrite pin 4 "HIGH" for 15 seconds if pin 7 is high, and 30 is pin 8 is high. I am not a programmer by trade and am needing some help with this code.

int SecPin30 = 8; //Digital 8
int SecPin15 = 7; //Digital 7
int OutputPin = 4; //Digital 4
int val30 = 0;
int val15 = 0;

void setup()
{
//Declares pin mode type
pinMode(SecPin30, INPUT);
pinMode(SecPin15, INPUT);
pinMode(OutputPin, OUTPUT);
val30 = digitalRead(SecPin30);
val15 = digitalRead(SecPin15);

}

// the loop function runs over and over again forever
void loop()
{
{ if (val15==HIGH);
pinMode(OutputPin,HIGH);
delay(15000);
}
{ if (val30=HIGH);
pinMode(OutputPin,HIGH);
delay(30000);
}

}

What is Your problem? What help do You need? What's Your question?
Tip:
Use inputs declared as "INPUT_PULLUP" to Your buttons and the other end of the buttons connected to GND.

I am wondering if this code will perform as described, I am not able to run the code in person until tomorrow. Im am trying to work out any bugs/coding errors now.

Run Your code. That is the ultimate confirmation whether it's functioning or not. It takes a lot more time for us to "verify" that code the theoretical way.

I was able to run the code on another arduino, when the pushbutton is closed, I have no output on the desired pin no. 4 .

You must check the buttons inside loop(). Setup is only executed once, at start up, pwr up, etc.
pinMode(OutputPin,HIGH);
is a declaration that doesn't set any output. Use digital.write to set outputs.

Changed it to "digitalWrite" and works perfectly, thank you for your help!

You see. Some work by You, a few Words from us.

I am having issues with the code again, I am getting constant output on pin 4. Do you see any issues with the code?

int SecPin30 = 13; //Digital 13
int SecPin15 = 10; //Digital 10
int OutputPin =4; //Digital 4

void setup()
{
//Declares pin mode type
pinMode(SecPin30, INPUT);
pinMode(SecPin15, INPUT);
pinMode(OutputPin, OUTPUT);

}

// the loop function runs over and over again forever
void loop()
{

{if (digitalRead(SecPin30)==HIGH);
digitalWrite(OutputPin,HIGH); //Write output pin HIGH
delay(30000); //30 Seconds
digitalWrite(OutputPin,LOW); //Write output pin LOW
}
{if (digitalRead(SecPin15)==HIGH);
digitalWrite(OutputPin,HIGH); //Write output pin HIGH
delay(15000); //15 Seconds
digitalWrite(OutputPin,LOW); //Write output pin LOW
}
}

You switch the pin HIGH, wait 30 seconds, switch it off and immediately loop round again. If pin 30 is still HIGH it will immediately switch on again. Same for the other pin. And if you don't have pull-down resistors on those pins then they may randomly read as HIGH at any time.

So posting a schematic showing how things are wired may give you the answer.

Steve

Attached is a schematic, the arduino does seem to be "triggering" randomly.

Yep, no pulldown resistors. The pins are just floating either when the pin is not selected or when it is selected but the PB is open.

Steve

Where would the pulldown resistors go? I cant quite seem to figure it out.

This example show several connection options.

MLanphier:
Where would the pulldown resistors go? I cant quite seem to figure it out.

Don't use pull-down resistors. Use pull-up resistors, between the pin and 5 V, with the button between the pin and ground.

If you set PinMode as INPUT_PULLUP, you enable a 47k (approximately) pull-up resistor internal to the Arduino.