Power suply - 220V 50HZ

Mcu works from 8MHz internal oscillator. But you should use external qrystal oscillator for more stability!

Source code written on C language in Atmel Studio 7 IDE.

For flashing MCU I used AVR ISP USBasp programmer and desktop app khazama 

You should set Fuse bits only for change oscillators source (internal 8MHz or external 8MHz) and disable CKDIV8 (it's devide frequency on 8 ) bit. Leave the remaining bits at default! 

Algorithm:

  • The priority is always on the key switch, regardless of the level of illumination and the location of the object in the field of the PIR sensor.
  • After about 5 hours, when the key is switch on, the light will automatically turn off. Sometimes household members, and I forget to turn off the lights.
  • If switch is turned off, and object is in the PIR sensor field and it's dark outside (the photo sensor comes to the rescue), the light turns on and remains on until the object leaves the PIR sensor field.
  • If switch is turned off, the object is in the PIR sensor field and it's dark outside, the light turns on, and if the object leaves the PIR sensor field, the lighting continues to work for a period of time specified by the adjustment potentiometer on the PIR sensor from 5 seconds to 300 seconds.
  • If switch is turned off, the object is in the PIR sensor field and it's light outside, bulb will not turn on until the light level falls to a predetermined threshold or the switch turns on.

Circuit diagramm of main board:

And photo driver: