Relay not activating every time

I don't really understand what you are trying to achieve with the logic in your arduino script.

When your loop executes with the PIR signal high, it is going to execute those two different
parts of the loop alternately on each cycle of the loop, which is going to be rather often.

I don't even know if you would see your LED turning on and off at that rate, it is going to
depend on how fast digitalWrite() works.

If you are trying to detect the edges where the PIR input goes high, and then goes low,
it doesn't look to me as if your script is actually going to do that.