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.
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.
Power supply (5v),
220Ω, 1KΩ resistors
LDR(Light Dependent Resistor)
100KΩ pot or preset,
Any motion sensor module (HC-SR501)
Atmel studio 6.1
Progisp or flash magic
Circuit Diagram and Working Explanation
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:
- Presence of darkness
- 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.
Recommended TI Whitepapers
// 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
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