Multi input, multi time, single output

Yes I have searched the forum and the wed for basic guidance on this project.
What I want to achieve is have multiple momentary button each with there own set time 5sec, 10sec, 60sec etc. controlling a single mosfet. The set up will run off a dual rail power supply. Arduino with 12 volts and leds with 5ish volts. I have found a code set that I thought I could tweak to work but after multiple errors and one smoked mosfet later I am asking for help. If I missed an obvious prior post please forgive me. I will cry NOOB.

int pinButton = 8;
int Relay = 2;
int stateRelay = LOW;
int stateButton;
int previous = LOW;
long time = 0;
long debounce = 500;
int stayON = 5000; //stay on for 5000 ms
 
void setup() {
  pinMode(pinButton, INPUT);
  pinMode(Relay, OUTPUT);
}
 
void loop() {
  stateButton = digitalRead(pinButton);  
  if(stateButton == HIGH && previous == LOW && millis() - time > debounce) {
    if(stateRelay == HIGH){
      digitalWrite(Relay, LOW);
    } else {
       digitalWrite(Relay, HIGH);
       delay(stayON);
       digitalWrite(Relay, LOW);
    }
    time = millis();
  }
  previous == stateButton;
}

arduino led.pdf (95.5 KB)

If you are using an N channel mosfet the LEDs should be between 5V and the mosfet drain, mosfet source to ground.
Mosfet should be logic level type, which one are you using? How much LED current?

How are the switches wired ?

Why does the program never change the value of stateRelay ?

A better approach would be to detect when the button becomes pressed rather than when it is pressed as in the StateChangeDetection example in the IDE.

previous == stateButton; ?????

Okay so what I would like to be able to do in a very simple state. Is have 3 input buttons that when pushed will trigger the one set of leds to come on for a set amount of time. If the buttons take the pin high or low doesn't matter. I just want the output to go high to switch a mosfet. I don't need help with the circuit side just programming.

poorbullfrog:
Okay so what I would like to be able to do in a very simple state. Is have 3 input buttons that when pushed will trigger the one set of leds to come on for a set amount of time. If the buttons take the pin high or low doesn't matter. I just want the output to go high to switch a mosfet. I don't need help with the circuit side just programming.

OP: Why don't you re-read that, and see if it makes any sense.

You say you want three input buttons, when you clearly mean switches, to be read. If all three are pressed, whether than means the state is HIGH or LOW depends on how (unstated) the switches are wired, you want the one set of LEDs to come on, for some unspecified amount of time. But, somehow, magically, the "set of LEDs" is supposed to switch a MOSFET on.

It may be that you can wire the switches, LEDs, mosfets, etc., but if you expect us to help with the code, you MUST post a schematic, so we know which pins to read and which pins to write to, AND so we know whether LOW means pressed or released, AND so we can tell whether it is LEDs or MOSFETs we are controlling.

You also must tell us how long the LED(s)/MOSFET(s) are to be on, AND what should happen if the three switches are pressed again before that time is up.

This program will do what you say you want.

There are much better ways to do it. You have not described what should happen under all circumstances, but if the solution is "good enough" then use it.

const byte buttonPins[] = {A1, A2, A3};
const unsigned long delays[] = {1000, 5000, 10000};
const byte ledPin = 10;

void setup()
{
  for (int button = 0; button < 3; button++)
  {
    pinMode(buttonPins[button], INPUT_PULLUP);
  }
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
}

void loop()
{
  for (int button = 0; button < 3; button++)
  {
    if (digitalRead(buttonPins[button]) == LOW)
    {
      digitalWrite(ledPin, LOW);
      delay(delays[button]);
      digitalWrite(ledPin, HIGH);
    }
  }
}

NOTE : you will need to change the code to use your pins and logic levels and, of course, the delays.

Looks way better then mine. It should work better then mine too, considering mine doesn't work. Only one button works.
Ill try it out. Thank you.

//Timer program 
int pinButtonA = 8;
int pinButtonB = 7;
int pinButtonC = 4;
int Relay = 11;
int stateRelay = LOW;
int stateButtonA;
int stateButtonB;
int stateButtonC;
int previous = LOW;
long time = 0;
long debounce = 500;
int stayONA = 5000; //stay on for 5000 ms
int stayONB = 30000; //stay on for 30000 ms
int stayONC = 90000; //stay on for 120000 ms

void setup() {
  pinMode(pinButtonA, INPUT);
  pinMode(pinButtonB, INPUT);
  pinMode(pinButtonC, INPUT);
  pinMode(Relay, OUTPUT);
}

void loop() {
  stateButtonA = digitalRead(pinButtonA);
  if (stateButtonA == HIGH && previous == LOW && millis() - time > debounce) {
    if (stateRelay == HIGH) {
      digitalWrite(Relay, LOW);
    } else {
      digitalWrite(Relay, HIGH);
      delay(stayONA);
      digitalWrite(Relay, LOW);
    }
    time = millis();
    stateButtonB = digitalRead(pinButtonB);
    if (stateButtonB == HIGH && previous == LOW && millis() - time > debounce) {
      if (stateRelay == HIGH) {
        digitalWrite(Relay, LOW);
      } else {
        digitalWrite(Relay, HIGH);
        delay(stayONB);
        digitalWrite(Relay, LOW);
      }
      time = millis();
      stateButtonC = digitalRead(pinButtonC);
      if (stateButtonC == HIGH && previous == LOW && millis() - time > debounce) {
        if (stateRelay == HIGH) {
          digitalWrite(Relay, LOW);
        } else {
          digitalWrite(Relay, HIGH);
          delay(stayONC);
          digitalWrite(Relay, LOW);
        }
        time = millis();

        previous == stateButtonA;
      }

    }
  }
}