Problem using PIR sensor and relay with arduino

Hello!

I want to create motion detecting light with PIR sensor and Relay using arduino
and was using this guide to do so: https://howtomechatronics.com/tutorials/arduino/how-pir-sensor-works-and-how-to-use-it-with-arduino/

But the relay turns on and off randomly and sometimes it stays on...
I tried replacing both the Relay and PIR sensor but did not help

I also tried replacing the Relay with led and it worked!

But still did not have any success with relay...

I guess there might be an power issue because I have connected both relay and PIR power pins to Arduino's 5v.

Any help regarding this would be appreciated.
Thanks.

Using this code? :

    /*     Arduini PIR Motion Sensor Tutorial
     *      
     *  by Dejan Nedelkovski, www.HowToMechatronics.com
     *  
     */
    int pirSensor = 8;
    int relayInput = 7;
    void setup() {
      pinMode(pirSensor, INPUT);
      pinMode(relayInput, OUTPUT);  
    }
    void loop() {
      int sensorValue = digitalRead(pirSensor);
      if (sensorValue == 1) {
        digitalWrite(relayInput, LOW); // The Relay Input works Inversly
      }
    }

maybe try replacing the loop() with this :

void loop() {
      int sensorValue = digitalRead(pirSensor);
      if (sensorValue == 1) {
        digitalWrite(relayInput, LOW); // The Relay Input works Inversly
      }
      else {
         digitalWrite(relayInput, HIGH); 
      }
}

Or a bit shorter

void loop() {
   digitalWrite(relayInput, ! digitalRead(pirSensor) ) ;  // The Relay Input works Inversly
}