PIR Sensor light project / stuck

Instead of having two local variables named sensor, in setup() and loop(), there should be one global variable. It's type should be byte, unless you plan to attach the sensor to pin 256 or higher, and should be const.

You need to separate the decision making process (should the LED be turned on or off) from the implementation process. The decision to turn the LED is based on the status of the PIR sensor (there is motion). The decision to turn the LED off is based on the PIR sensor (there is no motion) AND the length of time the LED has been on.

So, first you decide whether the LED should be on or off.

Then, you decide, if it should be off, if it's time to turn it off.

Then, you do it.

Look at the blink without delay example.

Of course, you could simply add a call to delay() to keep the LED on for some defined period of time, but that makes the whole system unresponsive.