PIR sensor detects motion only when a very near motion to the IR sensor and when the cover opened
You have provided Arduino code, but if your problem is with the sensor (as you seem to be asking in the question) then that code is just a distraction.
So apply one of the standard troubleshooting techniques: Split the system into parts, and investigate the signal(s) between those sections.
In your case, you can easily investigate just the sensor's behaviour using a DMM or scope etc. (or even a small, high-efficiency red LED with a series 220 ohm resistor to 0V, in my experience) to visualise and understand its output signal with different stimuli (no Arduino connected for this testing).

Is the sensor's output correct, when not connected to the Arduino?

No - then investigate the sensor and how you are using it. Ignore the Arduino code for now.
Yes - then stop worrying about the sensor, as you described in the question. It's time to debug your Arduino code.