How to add a ON timer

void loop() {

  switch (state1) {
    case 1:
      digitalWrite(OUTPUT1_PIN, LOW);
      if (digitalRead(SENSOR1_PIN) == HIGH ) transition1 = 12;

      break;

    case 2:
      
      if (millis() > time_to_switch_off_1 ) transition1 = 21;
      digitalWrite(OUTPUT1_PIN, HIGH);
      break;
  }

  switch (transition1) {  
    case 12: 
      Serial.println("Sensors 1 AND 2 active: output 1 is ON");
      time_to_switch_off_1 = millis() + TIMER1 * 1000UL;
      transition1 = 0;
      state1 = 2; 

      break;

    case 21:
      Serial.println("TIMER 1 has ended");
      if (digitalRead(SENSOR1_PIN) == HIGH ) {
        time_to_switch_off_1 = millis() + TIMER1 * 1000UL;
        state1 = 2;
        Serial.println("Sensor 1 AND 2 still active, output 1 stays ON");
      }
      else {
        state1 = 1;
        Serial.println("Sensor 1 OR 2 NOT active, output 1 OFF");
      }
      transition1 = 0;

  }

Thanks

What is an "ON timer" supposed to time?

Steve

#define OUTPUT1_PIN  8
#define OUTPUT2_PIN  9
#define OUTPUT3_PIN  10
#define OUTPUT4_PIN  11
#define OUTPUT5_PIN  12
#define OUTPUT6_PIN  13
#define OUTPUT7_PIN  A0
#define OUTPUT8_PIN  A1
#define OUTPUT9_PIN  A2
#define SENSOR1_PIN  2 // controls output1
#define SENSOR2_PIN  3
#define SENSOR3_PIN  4 // controls output1
#define SENSOR4_PIN  5

#define TIMER1        30 // [s]
#define TIMER2        33 // [s]
#define TIMER3        36 // [s]
#define TIMER4        39 // [s]
#define TIMER5        42 // [s]
#define TIMER6        45 // [s]
#define TIMER7        48 // [s]
#define TIMER8        51 // [s]
#define TIMER9        54 // [s]

#define TIMER_ONN_1   2  // [S]
#define TIMER_ONN_1   3
#define TIMER_ONN_1   4
#define TIMER_ONN_1   5
#define TIMER_ONN_1   6
#define TIMER_ONN_1   7
#define TIMER_ONN_1   8
#define TIMER_ONN_1   9
#define TIMER_ONN_1   10

byte state1 = 1, transition1;
byte state2 = 1, transition2;
byte state3 = 1, transition3;
byte state4 = 1, transition4;
byte state5 = 1, transition5;
byte state6 = 1, transition6;
byte state7 = 1, transition7;
byte state8 = 1, transition8;
byte state9 = 1, transition9;


unsigned long time_to_switch_off_1;
unsigned long time_to_switch_off_2;
unsigned long time_to_switch_off_3;
unsigned long time_to_switch_off_4;
unsigned long time_to_switch_off_5;
unsigned long time_to_switch_off_6;
unsigned long time_to_switch_off_7;
unsigned long time_to_switch_off_8;
unsigned long time_to_switch_off_9;

void setup() {
  pinMode(SENSOR1_PIN, INPUT);
  pinMode(SENSOR2_PIN, INPUT);
  pinMode(SENSOR3_PIN, INPUT);
  pinMode(SENSOR4_PIN, INPUT);
  pinMode(OUTPUT1_PIN, OUTPUT);
  pinMode(OUTPUT2_PIN, OUTPUT);
  pinMode(OUTPUT3_PIN, OUTPUT);
  pinMode(OUTPUT4_PIN, OUTPUT);
  pinMode(OUTPUT5_PIN, OUTPUT);
  pinMode(OUTPUT6_PIN, OUTPUT);
  pinMode(OUTPUT7_PIN, OUTPUT);
  pinMode(OUTPUT8_PIN, OUTPUT);
  pinMode(OUTPUT9_PIN, OUTPUT);
  Serial.begin(9600);
  Serial.println("Ready, waiting for sensors");
}

void loop() {
  // OUT1, SENSOR1

  switch (state1) {
    case 1:
      digitalWrite(OUTPUT1_PIN, LOW);
      if ((digitalRead(SENSOR1_PIN)) && (digitalRead(SENSOR2_PIN)) || (digitalRead(SENSOR3_PIN)) && (digitalRead(SENSOR4_PIN))) transition1 = 12;

      break;

    case 2:

      if (millis() > time_to_switch_off_1 ) transition1 = 21;
      digitalWrite(OUTPUT1_PIN, HIGH);
      break;
  }

  switch (transition1) {
    case 12:
      Serial.println("Sensors 1 AND 2 active: output 1 is ON");
      time_to_switch_off_1 = millis() + TIMER1 * 1000UL;
      transition1 = 0;
      state1 = 2;

      break;

    case 21:
      Serial.println("TIMER 1 has ended");
      if ((digitalRead(SENSOR1_PIN)) && (digitalRead(SENSOR2_PIN)) || (digitalRead(SENSOR3_PIN)) && (digitalRead(SENSOR4_PIN))) {
        time_to_switch_off_1 = millis() + TIMER1 * 1000UL;
        state1 = 2;
        Serial.println("Sensor 1 AND 2 still active, output 1 stays ON");
      }
      else {
        state1 = 1;
        Serial.println("Sensor 1 OR 2 NOT active, output 1 OFF");
      }
      transition1 = 0;

  }
  // OUT 2, SENSOR1

  switch (state2) {
    case 1:
      digitalWrite(OUTPUT2_PIN, LOW);
      if ((digitalRead(SENSOR1_PIN)) && (digitalRead(SENSOR2_PIN)) || (digitalRead(SENSOR3_PIN)) && (digitalRead(SENSOR4_PIN))) transition2 = 12;

      break;

    case 2:
      digitalWrite(OUTPUT2_PIN, HIGH);
      if (millis() > time_to_switch_off_2) transition2 = 21;
      break;
  }

  switch (transition2) {
    case 12:
      Serial.println("Sensors 1 AND 2 active: output 2 is ON");
      time_to_switch_off_2 = millis() + TIMER2 * 1000UL;
      transition2 = 0;
      state2 = 2;
      break;

    case 21:
      Serial.println("TIMER 2 has ended");
      if ((digitalRead(SENSOR1_PIN)) && (digitalRead(SENSOR2_PIN)) || (digitalRead(SENSOR3_PIN)) && (digitalRead(SENSOR4_PIN))) {
        time_to_switch_off_2 = millis() + TIMER2 * 1000UL;
        state2 = 2;
        Serial.println("Sensor 1 AND 2 still active, output 2 stays ON");
      }
      else {
        state2 = 1;
        Serial.println("Sensor 1 OR 2 NOT active, output 2 OFF");
      }
      transition2 = 0;

  }
  // OUT3 SENSOR1
  switch (state3) {
    case 1:
      digitalWrite(OUTPUT3_PIN, LOW);
      if ((digitalRead(SENSOR1_PIN)) && (digitalRead(SENSOR2_PIN)) || (digitalRead(SENSOR3_PIN)) && (digitalRead(SENSOR4_PIN))) transition3 = 12;

      break;

    case 2:
      digitalWrite(OUTPUT3_PIN, HIGH);
      if (millis() > time_to_switch_off_3) transition3 = 21;
      break;
  }

  switch (transition3) {
    case 12:
      Serial.println("Sensors 1 AND 2 active: output 3 is ON");
      time_to_switch_off_3 = millis() + TIMER3 * 1000UL;
      transition3 = 0;
      state3 = 2;
      break;

    case 21:
      Serial.println("TIMER 3 has ended");
      if ((digitalRead(SENSOR1_PIN)) && (digitalRead(SENSOR2_PIN)) || (digitalRead(SENSOR3_PIN)) && (digitalRead(SENSOR4_PIN))) {
        time_to_switch_off_3 = millis() + TIMER3 * 1000UL;
        state3 = 2;
        Serial.println("Sensor 1 AND 2 still active, output 3 stays ON");
      }
      else {
        state3 = 1;
        Serial.println("Sensor 1 OR 2 NOT active, output 3 OFF");
      }
      transition3 = 0;

  }



  }



}

how to add ON TIMER in each output same like OFF TIMER

how to add ON TIMER in each output same like OFF TIMER

The OFF TIMERs appear to cause the outputs to go HIGH after a period of time has passed since they went LOW as a result of readings from some sensors. Please explain what the ON TIMERs should do ?

at present, buttons active , all outputs active same time and off with timer,

i need to modify, when buttons active each outputs active one by one

bijitha:
at present, buttons active , all outputs active same time and off with timer,

i need to modify, when buttons active each outputs active one by one

I am sorry but I still don't understand what you want to do. Perhaps somebody else will, or maybe you could explain in more detail.

I think that there may be a language problem. What is your native language ?

delayed action in each output

bijitha:
delayed action in each output

I think that you mean you would like the outputs to go LOW based on the readings from the sensors but only after a period of time has elapsed. Is that correct ?
If so, then what should happen if the input from the sensor changes during the wait period ?

void loop() {
  // OUT1, SENSOR1

  switch (state1) {
    case 1:
      digitalWrite(OUTPUT1_PIN, LOW);
      if ((digitalRead(SENSOR1_PIN)) && (digitalRead(SENSOR2_PIN)) || (digitalRead(SENSOR3_PIN)) && (digitalRead(SENSOR4_PIN))) transition1 = 12;
      break;
    case 2:
      if (millis() > time_to_switch_off_1 ) transition1 = 21;


delay(1000);  // HER I NEED millis() FUNCTION

     
     digitalWrite(OUTPUT1_PIN, HIGH);
      break;
  }
  switch (transition1) {
    case 12:
      Serial.println("Sensors 1 AND 2 active: output 1 is ON");
      time_to_switch_off_1 = millis() + TIMER1 * 1000UL;
      transition1 = 0;
      state1 = 2;
      break;
    case 21:
      Serial.println("TIMER 1 has ended");
      if ((digitalRead(SENSOR1_PIN)) && (digitalRead(SENSOR2_PIN)) || (digitalRead(SENSOR3_PIN)) && (digitalRead(SENSOR4_PIN))) {
        time_to_switch_off_1 = millis() + TIMER1 * 1000UL;
        state1 = 2;
        Serial.println("Sensor 1 AND 2 still active, output 1 stays ON");
      }
      else {
        state1 = 1;
        Serial.println("Sensor 1 OR 2 NOT active, output 1 OFF");
      }
      transition1 = 0;

  }

Another all are ok