sensor pir and relay 5 v

hello I have a question why when I connect a PIR sensor with a relay whatever program I cried the relay will open and closes itself when connecting the controller? Thank you

Please put your code in its own window as seen in other posts. This can be done by placing     [code]  and [/code]  around the code or use the </> icon. This makes it easier for others to read.

How to use this forum

Also a circuit, hand drawn and photographed will do.

Weedpharma

int irmotionPin = 9;// detecteur int relayPin = 8; // relais

void setup(){

pinMode(relayPin, OUTPUT); digitalWrite(relayPin, LOW); } void loop(){

if(digitalRead(irmotionPin) == HIGH) {

digitalWrite(relayPin, HIGH);

delay(3000); }

digitalWrite(relayPin, LOW);

}

int irmotionPin = 9;// detecteur
int relayPin = 8;  // relais

void setup(){

pinMode(relayPin, OUTPUT);
 digitalWrite(relayPin, LOW); 
 }
void loop(){
    
 if(digitalRead(irmotionPin) == HIGH) { 
  
       digitalWrite(relayPin, HIGH); 
      
       delay(3000);
}
 
       digitalWrite(relayPin, LOW); 
       
}

Do not cross-post. Other thread removed.