Relay not switching off

I have a simple circuit where an arduino is connected to 8 relays and one button ( Active high) . when the button is pressed the 8 relays are activated for 2 mins and then it get's deactivated. The problem that I am facing is that , the relays just get's triggered but they don't deactivate.

The below is the code

const int com1 =  13;// tp1 input




const int Motor1 = A0; 
const int Motor2 = A1; 
const int Motor3= A2; 
const int Motor4 = A3; 

const int Motor5 = A4; 
const int Motor6 = A5; 
const int Motor7= 3; 
 const int Motor8 = 2;
 int trigger1;
int  state =0;
void setup() {


  pinMode(Motor1,OUTPUT);
  pinMode(Motor2,OUTPUT);
  pinMode(Motor3,OUTPUT); 
  
  pinMode(Motor4, OUTPUT);

 pinMode(com1, INPUT_PULLUP);
  pinMode(com2, OUTPUT);
  
   pinMode(Motor5,OUTPUT);
  pinMode(Motor6,OUTPUT);
  pinMode(Motor7,OUTPUT); 
  
  pinMode(Motor8, OUTPUT);
 
 
   

}
  


void loop()
{   
  



trigger1 = digitalRead(com1);

if (trigger1 == 0 && state == 0)
{

digitalWrite(Motor1, HIGH);

digitalWrite(Motor2, HIGH);

digitalWrite(Motor3, HIGH);

digitalWrite(Motor4, HIGH);
 
digitalWrite(Motor5, HIGH);

digitalWrite(Motor6, HIGH);

digitalWrite(Motor7, HIGH);

digitalWrite(Motor8, HIGH);


delay(1000);

state =1;
}

if ( state ==1 ){
digitalWrite(Motor1, LOW);

digitalWrite(Motor2, LOW);

digitalWrite(Motor3, LOW);

digitalWrite(Motor4, LOW);

digitalWrite(Motor5, LOW);

digitalWrite(Motor6, LOW);

digitalWrite(Motor7, LOW);

digitalWrite(Motor8, LOW);
delay(1000);

state =0;


}}

Thanks in advance

Nidmar1107:
are activated for 2 mins

Which part of the code does this 2 minute activation?

Add some code that allows you to visually check to see whether the values such as 'trigger1' are behaving correctly.... eg. some println messages in the serial monitor window that allows you to see whether or not your button presses (and button releases) are doing the right thing.

Also make sure you use button debounce routines.

I think the button is bouncing and your code is getting confused with the trigger and state and not acting like you think it should

To rectify...implement a simple debounce by putting this statement:

trigger1 = digitalRead(com1);

in a loop that reads the com1 several times with a delay(250). Once the trigger1 is a constant H or L then continue on.

I think this will resolve your prob.

Let us know.

Firstly you have no code to detect 2 minutes timeout, and secondly your relay outputs are probably
active low if they are standard opto isolated relay module...

one button ( Active high)
pinMode(com1, INPUT_PULLUP);

These two statements are incompatible with a normally open button, how is your button wired?