Automatic Staircase Light

Published  June 10, 2015   24
Dilip Raja
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 


Have any question realated to this Article?

Ask Our Community Members


Submitted by aesha on Thu, 08/13/2015 - 15:20


can i make this project on copper board?

Submitted by fin on Tue, 06/14/2016 - 21:47


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?

Submitted by Kapil on Tue, 07/12/2016 - 13:23


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.


Submitted by tonye okari on Wed, 07/27/2016 - 05:29


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

Submitted by S.M. Bakhtiar on Wed, 09/21/2016 - 11:15


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

Submitted by Miral Dalal on Wed, 10/19/2016 - 00:00


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.

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