Time loop

Hello guys, So i've got optic sensor which send 5V or 0V signal to my microsontroller for 15 seconds no matters if he sees something.

Now what i want to do:

I want to turn on lights when optic sensors sees someone or something and then lights should work for 60s. If in this 60 seconds something walk near sensor again it should restart the time and begin from 0. If nothing appears in 60seconds lights should turn off.

that's pretty complicated for me, i don't know what functions i should use bacause i'm not that good in this language.

Any help, code or some leads would be nice :)

What happens after 15 seconds if he sees nothing? What does the sensor return if it sees something walk near it?

Start with the Blink Without Delay example in the Arduino IDE to learn how to time events. Then learn how to extend those concepts to do several things at the same time.

@econjack after 15 seconds it doesn't give me any signal to microcontroller. The sensor returns 0V or LOW whatever.

Ok, so write the pseudo-code for the algorithm in English. Something like:

  1. While sensors return 0, keep reading sensors
  2. If sensor > 0, set timer to 60 seconds and record distance to sensor otherwise repeat #1
  3. Every second, decrease the timer by one second
  4. If distance now less than before, reset timer to 60 seconds and repeat step #2

I'm not convinced I have this right, but you should develop a proper algorithm for solving your problem before you start writing code. You should read Planning and Implementing an Arduino Program by Robin2 at the top of this Forum first, then read the last two posts by Nick Gammon before you post any code here.