Basic algorithm is following: we have motion counter - it is set to some large number if motion has been detected and decreases otherwise. In main loop we increase or decrease LED brightness based on our counter. This approach gives us smooth fading and control over fade-out delay.

The logic is performed on Arduino Pro Mini (Atmega328p). Only two pins are used:

- D9 to control LED brightness

- D12 for input from PIR

For smooth brightness stepping we use 10-bit PWM feature based on Arduino timer (implemented in TimerOne lib on GitHub).

LED brightness is regulated by logic-level mosfet. We add two resistors to avoid parasitic capacitance.

Also we use external voltage regulator instead of built-in one in Arduino, to keep the micro-controller cold.

When the project had been tested I replaced Arduino Pro Mini with simpler one - DigiSpark (Atmega85).