brock

Friday, August 17, 2012

Motion Detection Circuit for Security Lamp

Here is a system based on PIR motion detector module BS1600 (or BS1700) that can be used for security or corridor lighting in power-saving mode. The 12V DC power supply required for the motion detector and the relay driver is derived from 230V, 50Hz mains using a transformerless circuit as shown below.


The working of the circuit is simple. When you power-on the circuit after assembling all the components including the CFL, the CFL will glow for 10 seconds, turn off for 30 seconds, glow for 10 seconds and then turn off. Now the circuit is ready to work.

When any movement is detected, around 3.3V appears on the base of relay-driver transistor T1 and it conducts to energise relay RL1. As a result, Triac1 (BT136) fires to provide full 230V and light up the CFL. Another normally-opened contact of the relay (N/O2) is used here to hold the output until reset. If the switch is not in 'hold' position, the light will remain 'on' for about ten seconds (as programmed in the motion sensor). In short, when there is a movement near the sensor, the CFL glows for about ten seconds. It will remain 'on' if switch S1 is in 'hold' position.

Assemble the circuit on a general-purpose PCB and enclose in a suitable cabinet. Use a three-pin connector for connecting the PIR sensor in the circuit with correct polarity. 

Thursday, August 9, 2012

IR Sensor based Visitor Counter


Visitor counting is simply a measurement of the visitor traffic entering and exiting offices, malls, sports venues, etc. Counting the visitors helps to maximise the efficiency and effectiveness of employees, floor area and sales potential of an organisation.
Visitor counting is not limited to the entry/exit point of a company but has a wide range of applications that provide information to management on the volume and flow of people throughout a location. A primary method for counting the visitors involves hiring human auditors to stand and manually tally the number of visitors who pass by a certain location. But human-based data collection comes at great expense. Here is a low-cost microcontroller based visitor counter that can be used to know the number of persons at a place. All the components required are readily available in the market and the circuit is easy to build.
Two IR transmitter-receiver pairs are used at the passage: one pair comprising IR transmitter IR TX1 and receiver phototransistor T1 is installed at the entry point of the passage, while the other pair comprising IR transmitter IR TX2 and phototransistor T2 is installed at the exit of the passage. The IR signals from the IR LEDs should continuously fall on the respective phototransistors, so proper orientation of the transmitters and phototransistors is necessary.
Circuit description

Two similar sections detect interruption of the IR beam and generate clock pulse for the microcontroller. The microcontroller controls counting and displays the number of persons present inside the hall. above figure shows the circuit of the microcontroller-based visitor counter, wherein the transmitter and the receiver form the IR detection circuit. Control logic is built around transistors, operational amplifier LM324 (IC1) and flip-flop (IC2). When nobody is passing through the entry/exit point, the IR beam continuously falls on phototransistorT1. Phototransistor T1 conducts and the high voltage at its emitter drives transistor T3 into saturation, which makes pin 3 of comparator N1 low and finally output pin 1 of comparator N1 is high. Now if someone enters the place, first the IR beam from IR TX1 is interrupted and then the IR beam from IR TX2. When the beam from IR TX1 is interrupted, phototransistor T1 and transistor T3 cut-off and pin 3 of comparator N1 goes high. The low output (pin 1) of comparator N1 provides negative trigger pulse to pin 1 of J-K flip-flop IC2(A). At this moment, high input at ‘J’ and ‘K’ pins of flip-flop IC2(A) toggles its output to low. On the other hand, the low input at ‘J’ and ‘K’ pins of IC2(B) due to clock pin 1 of IC2(A) and ‘J’ input (pin 9) and ‘K’ input (pin 12) of IC2(B) are connected to pin 1 of comparator N1. The negative-going pulse is applied to clock pin 6 of IC2(B) when the person interrupts the IR beam from IR TX2. There is no change in the output of IC2(B) flip-flop. This triggers the external interrupt INT0 (pin 12) of microcontroller AT89C52. The AT89C52 is an 8-bit microcontroller with 8 kB of flash-based program memory, 256 bytes of RAM, 32 input/output lines, three 16-bit timers/counters, on-chip oscillator and clock circuitry. A 12MHz crystal is used for providing clock. Ports 0, 1 and 2 are configured for 7-segment displays. Port-0 pin is externally pulled up with 10-kilo-ohm resistor network RNW1 because port-0 is an 8-bit, open-drain, bidirectional l, input/output (I/O) port. Port-1 andport-2 are 8-bit bidirectional I/O ports with internal pull-ups (no need of external pull-ups). Port pins 3.0 and 3.1 are configured to provide the set pulse to J-K flip-flops IC2(A) and IC2(B), respectively. External interrupts INT0 and INT1 receive the interrupt pulse when the person interrupts the IR beams. Resistor R9 and capacitor C5 provide power-on-reset pulse to the microcontroller. Switch S1 is used for manual reset. When the microcontroller is re- s e t , t h e flip-flops are b r o u g h t i n ‘ s e t ’ s t a t e through the microcontroller at software run time by making their ‘set’ pin high for a moment. The value of the counter increments by ‘1’ when the interrupt service routine for INT0 is executed .The output of the corresponding J-K flip-flop is set to ‘high’ again by making its ‘set’ input pin low through the microcontroller. The micro-controller is configured as a negative-edge triggered interrupt sensor. Similarly, if somebody exits the place, first the IR beam from IR TX2 is interrupted and then the IR beam from IR TX1. When the beam from IR TX2 is interrupted, output pin 7 of comparator N2 goes low. This provides clock pulse to pin 6 of J-K flip-flop IC2(B).
   
At  this  moment,  the  high  input at ‘J’ and ‘K’ pins of  flip-flop IC2(B) toggles its output to low. On the other hand, the low input at ‘J’ and ‘K’ pins of IC2(A) due to clock pin 6 of IC2(B) and ‘J’ input (pin 4) and ‘K’ input (pin16) of IC2(A) are connected to pin 7 of comparator N2.
The  negative-going  pulse  is  ap- plied to clock pin 1 of IC2(A) when the person interrupts the IR beam from IR TX1. There is no change in the output of  IC2(A)  flip-flop. This  triggers  the external  interrupt  INT1  (pin  13)  of microcontroller  AT89C52.  The  value of the counter decrements by ‘1’ when interrupt service routine for INT1 is ex- ecuted. The output of the correspond ing J-K flip-flop is set to ‘high’ again by making its ‘set’ input pin low through the microcontroller.

The  circuit  is  powered  by  regulated 5V. Above figure shows the  circuit of the power supply. The  AC mains is stepped down by  transformer X1 to deliver  secondary  output  of  7.5V,
250mA, which is rectified by  bridge rectifier BR1, filtered by capacitor C6 and regulated by  IC 7805 (IC4). Ca- pacitor C7 bypasses any ripple in the regulated output.

 code:


Wednesday, August 8, 2012

Basic idea On PWM


Pulse-width modulation (PWM), or pulse-duration modulation (PDM), is a commonly used technique for controlling power to inertial electrical devices, made practical by modern electronic power switches.
The average value of voltage (and current) fed to the load is controlled by turning the switch between supply and load on and off at a fast pace. The longer the switch is on compared to the off periods, the higher the power supplied to the load is.
The PWM switching frequency has to be much faster than what would affect the load, which is to say the device that uses the power. Typically switchings have to be done several times a minute in an electric stove, 120 Hz in a lamp dimmer, from few kilohertz (kHz) to tens of kHz for a motor drive and well into the tens or hundreds of kHz in audio amplifiers and computer power supplies.
The term duty cycle describes the proportion of 'on' time to the regular interval or 'period' of time; a low duty cycle corresponds to low power, because the power is off for most of the time. Duty cycle is expressed in percent, 100% being fully on.
The main advantage of PWM is that power loss in the switching devices is very low. When a switch is off there is practically no current, and when it is on, there is almost no voltage drop across the switch. Power loss, being the product of voltage and current, is thus in both cases close to zero. PWM also works well with digital controls, which, because of their on/off nature, can easily set the needed duty cycle.
PWM has also been used in certain communication systems where its duty cycle has been used to convey information over a communications channel.

In telecommunications, the widths of the pulses correspond to specific data values encoded at one end and decoded at the other.
Pulses of various lengths (the information itself) will be sent at regular intervals (the carrier frequency of the modulation).
          _      _      _      _      _      _      _      _     
         | |    | |    | |    | |    | |    | |    | |    | |    
Clock    | |    | |    | |    | |    | |    | |    | |    | |    
       __| |____| |____| |____| |____| |____| |____| |____| |____
                 _      __     ____          ____   _
PWM Signal      | |    |  |   |    |        |    | | |
                | |    |  |   |    |        |    | | |
       _________| |____|  |___|    |________|    |_| |___________
Data       0     1       2      4      0      4     1      0
The inclusion of a clock signal is not necessary, as the leading edge of the data signal can be used as the clock if a small offset is added to the data value in order to avoid a data value with a zero length pulse.
                _      __     ___    _____   _      _____   __     _   
               | |    |  |   |   |  |     | | |    |     | |  |   | | 
PWM Signal     | |    |  |   |   |  |     | | |    |     | |  |   | |  
             __| |____|  |___|   |__|     |_| |____|     |_|  |___| |_____

Data            0       1      2       4     0        4      1     0

[edit]Sample C Code to Generate PWM

Code:
void delay_ms(unsigned int i)
{
unsigned int j;
while(i-->0)
{
for(j=0;j<500 font="font" j="j">
{
;
}
}
}
void delay_micro(unsigned int i)
{
unsigned int s;
for(s=0;s
{
;
}
}

void main()
{
unsigned int i;
while(1)
{
for(i=0;i<200 font="font" i="i">
{
led=0;
delay_micro(i);
led=1;
delay_ms(20);
}
}
}