Automatic Staircase Light


ByDilip Raja 24

Automatic Staircase Lighting using PIR Sensor and AVR Microcontroller

We all know that one of the places where power wastage occurs most in homes and offices is at staircases. We usually turn on light at stairs and leave it in a hurry. In this project we are going to design a stair case lamp which works on battery and only turn on the lights only when someone is present at there. This circuit can be used to save power and it can be used as an emergency backup light.

The circuit works on two conditions - one is presence of light in its location and second is presence of human being, only when these two conditions are met, the controller turns the backup light ON.

These two conditions are tested by two sensors one is LDR and other is PIR Motion sensor module. The LDR senses the presence of light and Motion sensor detects the presence of a human being in its range.

LDR and PIR Sensor

The image on the left side shows the sensor LDR (Light Dependent Resistor) and the picture on the right side show the PIR Sensor or Motion Sensor Module. PIR Sensor is basically an IR (Infrared Receiver). It consists of sensitive IR receives which detects the IR (Infra Red) rays in its region.We know that every living organism emits IR rays and so the human body. Whenever a there is a human in the sensor module region it detects the presence of IR rays.


Whenever a human present in the sensing region of module, the sensor picks up IR changes as human body emits IR rays, so now these changes of IR picked up by module are filtered by electronics in the module and as of signaling the changes in IR, A pulse is generated by the module. This pulse is of duration 5sec by default.

So whenever a human crosses the sensing region of module, it generates a pulse of 5 sec.  So presence of human is detected by IR rays by this module.


The motion sensor module will have two pots or presets one of them is to adjust the sensing region of the module and the second is for varying the time of high pulse output on detection of motion. The duration of pulse can be adjusted from few second to few minutes. You can understand more about it by this PIR sensor circuit.


The LDR in this circuit works as a variable resistor. The resistor of the LDR changes  based on the light intensity. When the light falling on the LDR is low the resistance of the LDR will be high. When the light falling on LDR is high the resistance across terminals of LDR will be very low compared to low light resistance.


Components Required



Power supply (5v),


100uF capacitor


220Ω, 1KΩ resistors

LDR(Light Dependent Resistor)

100KΩ pot or preset,

Any motion sensor module (HC-SR501)


TIP122 transistor.



Atmel studio 6.1

Progisp or flash magic


Circuit Diagram and Working Explanation

Automatic Staircase Lighting Circuit Diagram

As shown in the above automatic staircase lighting circuit, there is no need to connect an external crystal here. Because the ATMEGA works on internal 1MHz, Resistor-Capacitor oscillator on default. Only when the accuracy of clock is needed, as application of high precision counting, external crystal is attaches. When the controller is first bought, it is fused to work on internal crystal by default.  


The controller will here will be always checking two things:

  1. Presence of darkness
  2. Detection on motion

As we discussed when the light is low the resistance of LDR will be high, now on observation we can tell there is a voltage divider formed by LDR and 100K pot, the middle joint of voltage divider is taken as reference and is connected to PB1 of controller. You can learn more about the working principle of LDR in this LDR circuit.

Now if there is low light the resistance of LDR will be high and so the voltage share in the voltage divider branch changes, Because of high resistance, the voltage across LDR will be higher than that of 100K pot, and because of this the voltage at midpoint drops drastically and this drop is easily sensed by controller. So whenever darkness comes the controller picks up a signal. This signal satisfies the first condition. Understand more about LDRs in this dark detector circuit.

With the presence of motion, there will be pulse at PB0 of controller which is generated by motion sensor module as we discussed earlier.

Once these two conditions are met, the controller is instructed to signal the NPN transistor to drive the power LED. 



// C program for Automatic Staircase Light

#include <avr/io.h> //header to enable data flow control over pins
#define F_CPU 1000000 //telling controller crystal frequency 
#include <util/delay.h> //header to enable delay function in program

int main(void)
    DDRB = 0b11111100; //PB0,PB1 are used as inputs and reset are used as outputs
    int x=0; // taking a integer 
               if (bit_is_clear(PINB,1)) // In presence of darkness (When there is darkness pin goes low)
                     if (bit_is_set(PINB,0)) //When there is motion (motion sensor gives high output on presence of human being)
                          x=1; //set x when both conditions are satified
             if (x==1) //when x is set
                 PORTB |=(1<<PINB2); //trigger transistor to drive power led
                _delay_ms(220); //wait 220ms (can be changed for higher duartion)
                PORTB &=~(1<<PINB2); //turn on transistor trigger
                x=0; // reset x 


Get Our Weekly Newsletter!

Subscribe below to receive most popular news, articles and DIY projects from Circuit Digest


  • aesha's picture
    Aug 13, 2015

    can i make this project on copper board?

  • Jayant's picture
    Oct 06, 2015

    Yes, you can make it on PCB board. Design a PCB layout of this circuit and make it on PCB board. Do also share with us.

  • deep sharma's picture
    deep sharma
    Nov 04, 2015

    can you give the source code for this project in assembly?

  • Sayali's picture
    Jan 23, 2016

    Can you please provide proteus simulation for this project?

  • Sonam's picture
    May 10, 2016

    Can we do this project using pic 16f877a?

  • fin's picture
    Jun 14, 2016

    i'm having mini project. then i thought about this project. i'm not an ace student so may i ask is this microC can use for PLC? or do you have any this exact project but build based on plc?

  • Kapil's picture
    Jul 12, 2016

    I m not an electronics student but i feel it intresting. Will u pls send me a step by step guid to make a PCB and how to assemble the all the items to make a fully working stair lightning.


  • tonye okari's picture
    tonye okari
    Jul 27, 2016

    please am working on something like this. but this is actually what i want can you help me

    automatic street light controller using pic16f877a to control the led intensity

    i need help on my project topic. it is a controller that uses the sensor passive infrared sensor(PIR) and light dependent resistor (LDR). light dependent resistor senses the light intensity(that's day and night) and gives command for the light to come on, but the light intensity should be only 50% bright. then when the PIR detects movement then the light intensity of the LED should be 100% bright. i really need the source code and how to interface each of the component with pic16f877a.
    thanks in anticipation

  • S.M. Bakhtiar's picture
    S.M. Bakhtiar
    Sep 21, 2016

    Dear Concern,
    Should i control this without MC if possible then how i do this.
    Thanks in advanced.

  • Miral Dalal's picture
    Miral Dalal
    Oct 19, 2016

    I have uploaded my program in atmega 32A but after making the same circuit my at mega 32 switches on the led every time, its doesn't take any input from ldr or pit what to do?? Please help urgent.

  • Glee's picture
    Feb 16, 2017

    where am I going to connect the capacitor?

  • Bhatt sneha's picture
    Bhatt sneha
    Jul 20, 2017

    can you give me the Proteus simulation of this project

  • Laarnie Jane Viernes's picture
    Laarnie Jane Viernes
    Oct 05, 2017

    Can someone help me on this... PLEASE??

  • sharma 's picture
    Nov 10, 2017

    can i get code in assembly language of 80C51

  • Yousuf Ajaz's picture
    Yousuf Ajaz
    Nov 13, 2017

    Can any ne provide assembly code and proteus simulation for this project????

  • AISHA's picture
    Nov 14, 2017

    This project cannot be completely simulated due to the usage of sensors

  • Omkar Goriwale's picture
    Omkar Goriwale
    Jan 15, 2018

    Please upload IEEE papers of Automatic Staircase Lighting using PIR sensor.

  • Ram's picture
    Feb 19, 2018

    I need the Arduino Uno program for the automatic staircase light using PIR motion sensor

  • adwait's picture
    Apr 16, 2018

    Sir I have encountered errors in code can u please tell me what header files are needed to be added in above c program.

  • Hamza's picture
    May 03, 2019

    Burned the code in ATmega32A.. So the port 9, 6, 7, 8 is not in use By programming port
    Have no idea what that is..
    Should there be any changes in the circuit diagram if i burn the code into atmega32A
    The LED is kept ON as soon i connect the battery

Log in or register to post Comment