the system based arduino is stuck when an external event is occured

Hello,

I have an arduino nano connected to a module of two relays to operate a switch for supplying two lamps. I used a 5 volt module with nano 5v power supply. I mounted the system on the wall to test it. The system works well except sometimes the relay or the arduino stucks when I order some window roller shutters in my house with a pusher.

The system returns to its normal operation only when a reset is made.

Have you an idea about this problem!!??

I have an idea that this is not an installation issue.
I have another idea that you should post your code, and a schematic.

The schematic is attached as an image.

This is the code:

#include <CapacitiveSensor.h>
CapacitiveSensor Sensor = CapacitiveSensor(2,4);
CapacitiveSensor Sensor2 = CapacitiveSensor(7,6);

long val, val2;
const int relayPin =10;
int relayState = 0;
int touch_on =0;


const int relayPin2 =11;
int relayState2 = 0;
int touch_on2 =0;

void setup()
{
pinMode(relayPin, OUTPUT);
pinMode(relayPin2, OUTPUT);

pinMode(LED_BUILTIN, OUTPUT);

}

void loop()
{

val = Sensor.capacitiveSensor(30);
val2 = Sensor2.capacitiveSensor(30);

if(val > 800 && digitalRead(relayPin) == HIGH)
{
 digitalWrite(relayPin, LOW); // open
 delay(1000);
}

if ( val < 800 &&  digitalRead(relayPin) == LOW)
{
 touch_on=1;
}


if(val > 800 && touch_on == 1 && digitalRead(relayPin) == LOW)
{
 digitalWrite(relayPin, HIGH); // close
 touch_on = 0;
 delay(1000);
}

 //////////////////////////// relay2


if(val2 > 800 &&  digitalRead(relayPin2) == HIGH)
 {
 digitalWrite(relayPin2, LOW); 
 digitalWrite(LED_BUILTIN, HIGH);
 delay(1000);
 
 }

if ( val2 < 800 && digitalRead(relayPin2) == LOW)
{
   touch_on2=1;
}

if(val2 > 800 && touch_on2 == 1 && digitalRead(relayPin2) == LOW)
{
 digitalWrite(relayPin2, HIGH); 
 digitalWrite(LED_BUILTIN, LOW);
 touch_on2 = 0;
 delay(1000);
 
}

}

Please edit your post to add codes tags, as described in How to use this forum.

the arduino stucks when I order some window roller shutters in my house with a pusher

This is most likely due to electrical noise in the power supply, which causes a reset.

what shall I do in this case to eliminate this electrical noise.

Post a complete wiring diagram, and other details showing us the exact nature of the "5V power supply". Pencil and paper drawings are fine -- just post a snapshot.

(deleted)