You are on page 1of 66

Street light controller with vehicle sense and LDR

Submitted in partial fulfillment of the requirements for the award of degree of

BACHELOR OF TECHNOLOGY

IN

Electronics ENGINEERING

Submitted By:

Abhishek
2
2
4

ELECTRONICS ENGINEERING

UNITED COLLEGE OF ENGINEERING AND


TECHNOLOGY
SUBMITTED TO: …………………………

Street light controller with vehicle sense and LDR Page 1


Aditya bharadwaj

DECLARATION

I hereby declare that the project synopsis entitled “Street light


controller with vehicle sense and LDR” submitted is our original work
and the report has not formed the basis for the award of any degree,
associate ship, fellowship or any other similar title.

Signature:

Name:

Enrollment no:

Date:

Street light controller with vehicle sense and LDR Page 2


CERTIFICATE

This is to certify that the practical report entitled “Street light


controller with vehicle sense and LDR” is the bonafide work carried
out by students of Lucknow polytechnic, LUCKNOW during the year
2018 in partial fulfillment of the requirements for the award of the
Diploma. The report has not formed the basis for the award previously
of any degree, diploma, associate ship, fellowship or any other similar
title.

Signature of the guide:

Date:

Street light controller with vehicle sense and LDR Page 3


ACKNOWLEDGEMENT

It gives me great pleasure to express my gratitude and heart full


thanks to all those who are helping me in complete this project.

I want to thank to Mr. NAME , who has always encouraged and


help me in making this project. In addition to this, I am grateful to
other faculties too who made me in right direction and gave me their
precious time and expert guidance whenever necessary through
which I could achieve this extent.

At last but not the least I am feeling glad to say about my family
whose wishes are always with me, without which it was not possible
for me to reach this extent.

I hope my work is praised and my efforts render fruitful result.

THANK YOU

Signature:

Name:

Enrollment no:

Street light controller with vehicle sense and LDR Page 4


Contents
Enrollment no: .................................................................................... 4

Objective: ............................................................................................ 6

Block Diagram: .................................................................................... 6

Experiences: ........................................................................................ 7

Hardware Used: .................................... Error! Bookmark not defined.

Software used: .................................................................................... 8

AT89S52 Microcontroller .................................................................... 9

LDR: ................................................................................................... 12

IR Sensor: .......................................................................................... 14

PRINCIPLE OF WORKING ................................................................ 15

Distinguishing between black and white ........................................ 15

Circuit Diagram............................................................................... 16

Benefits: ............................................................................................ 16

References: ....................................................................................... 65

Figure 1 block diagram .............................................................................................................. 6


Figure 2 8051 PIN diagram........................................................................................................ 9
Figure 3 LDR ........................................................................................................................... 14
Figure 4 IR sensor .................................................................................................................... 14
Figure 5 circuit diagram ........................................................................................................... 17

Street light controller with vehicle sense and LDR Page 5


Objective:
Objective of this project is to make a system that will help us to
save electricity by automatically control the street lights. Street lights
will be automatically turn OFF in day time and in night time light will
glow with there10% intensity. When this system will automatically
detect the vehicle then lights will turn ON with 100% intensity.

Block Diagram:

Microcontroller At89S52 LDR Sensor

Street lights
IR Sensor

Figure 1 block diagram

Street light controller with vehicle sense and LDR Page 6


Description:

 Figure-1 is showing the block diagram of whole system.


 Microcontroller will first check whether it is day time or night by
using LDR sensor.
 In day time all lights will Turn OFF automatically.
 In night time all lights will glow with their 10% intensity.
 When this system will automatically detect the vehicle then only
that street lights which in near the vehicle will turn On with 100%
intensity and other lights will glow with only 10% intensity.

Experiences:
Technical Experiences:

 Microcontroller AT89S52

 LDR

 IR Sensor

Personal Experiences:

– Time management

– Communication

– Accountability

Street light controller with vehicle sense and LDR Page 7


Part List

 Microcontroller AT89S52 one 40RS


 LDR sensor one 10RS
 IR Pair fore 40RS
 12V/2Amp Power adaptor one 200RS
 Voltage regulator 7805 one 10RS
 Crystal oscillator 11.0592MHz one 5RS
 Ceramic capacitor 33pF two 2rs
 PCB 10X6 inches one 200RS
 White LED 24 48RS

Power supply requirement:

12V 2Amp transformer is used to give power to the system. GSM


module will work on 12V DC. 12V DC will be converted in to 5V DC
to operate microcontroller, sensor and RFID module.

Software used:
 Programming of microcontroller in C programming language.
 Keil C for programming microcontroller.
 Hyperterminal for troubleshooting.

Street light controller with vehicle sense and LDR Page 8


AT89S52 Microcontroller:

Figure 2 8051 PIN diagram

Street light controller with vehicle sense and LDR Page 9


Features:

• High Performance, Low Power Atmel8051® 8-bit Microcontroller


• Advanced RISC Architecture
– 131 Powerful Instructions - Most Single Clock Cycle Execution
– 32 × 8 General Purpose Working Registers
– Fully Static Operation
– Up to 1 MIPS throughput per MHz
– On-chip 2-cycle Multiplier
• Data and Non-Volatile Program Memory
– 16/32/64K Bytes Flash of In-System Programmable Program
Memory
– 512B/1K/2K Bytes of In-System Programmable EEPROM
– 1/2/4K Bytes Internal SRAM
– Write/Erase Cycles: 10,000 Flash/ 100,000 EEPROM
– Data Retention: 20 years at 85°C/ 100 years at 25°C(1)
– Optional Boot Code Section with Independent Lock Bits
In-System Programming by On-chip Boot Program
True Read-While-Write Operation
– Programming Lock for Flash Program and EEPROM Data Security
• On Chip Debug Interface (debugWIRE)
• CAN 2.0A/B with 6 Message Objects - ISO 16845 Certified
• LIN 2.1 and 1.3 Controller or 8-Bit UART
• One 12-bit High Speed PSC (Power Stage Controller)

Street light controller with vehicle sense and LDR Page 10


– Non Overlapping Inverted PWM Output Pins With Flexible Dead-
Time
– Variable PWM duty Cycle and Frequency
– Synchronous Update of all PWM Registers
– Auto Stop Function for Emergency Event
• Peripheral Features
– One 8-bit General purpose Timer/Counter with Separate Prescaler,
Compare Mode
and Capture Mode
– One 16-bit General purpose Timer/Counter with Separate Prescaler,
Compare
Mode and Capture Mode
– One Master/Slave SPI Serial Interface
Up To 11 Single Ended Channels and 3 Fully Differential ADC Channel
Pairs
Programmable Gain (5×, 10×, 20×, 40×) on Differential Channels
Internal Reference Voltage
Direct Power Supply Voltage Measurement
– 10-bit DAC for Variable Voltage Reference (Comparators, ADC)
– Four Analog Comparators with Variable Threshold Detection
– 100μA ±2% Current Source (LIN Node Identification)
– Interrupt and Wake-up on Pin Change
– Programmable Watchdog Timer with Separate On-Chip Oscillator
– On-chipTemperature Sensor

Street light controller with vehicle sense and LDR Page 11


• Special Microcontroller Features
– Low Power Idle, Noise Reduction, and Power Down Modes
– Power On Reset and Programmable Brown Out Detection
– In-System Programmable via SPI Port
• Operating Voltage: 2.7V - 5.5V
• Extended Operating Temperature:
– -40°C to +85°C
• Core Speed Grade:
– 0 - 8MHz @ 2.7 - 4.5V
– 0 - 16MHz @ 4.5 - 5.5V

LDR:

A photoresistor or light-dependent resistor (LDR) or photocell is a


light-controlled variable resistor. The resistance of a photoresistor
decreases with increasing incident light intensity; in other words, it
exhibits photoconductivity. A photoresistor can be applied in light-
sensitive detector circuits, and light- and dark-activated switching
circuits.

A photoresistor is made of a high resistance semiconductor. In the


dark, a photoresistor can have a resistance as high as several
megohms (MΩ), while in the light, a photoresistor can have a
resistance as low as a few hundred ohms. If incident light on a
photoresistor exceeds a certain frequency, photons absorbed by the

Street light controller with vehicle sense and LDR Page 12


semiconductor give bound electrons enough energy to jump into the
conduction band. The resulting free electrons (and their hole partners)
conduct electricity, thereby lowering resistance. The resistance range
and sensitivity of a photoresistor can substantially differ among
dissimilar devices. Moreover, unique photoresistors may react
substantially differently to photons within certain wavelength bands.

A photoelectric device can be either intrinsic or extrinsic. An intrinsic


semiconductor has its own charge carriers and is not an efficient
semiconductor, for example, silicon. In intrinsic devices the only
available electrons are in the valence band, and hence the photon
must have enough energy to excite the electron across the entire
bandgap. Extrinsic devices have impurities, also called dopants, added
whose ground state energy is closer to the conduction band; since the
electrons do not have as far to jump, lower energy photons (that is,
longer wavelengths and lower frequencies) are sufficient to trigger the
device. If a sample of silicon has some of its atoms replaced by
phosphorus atoms (impurities), there will be extra electrons available
for conduction. This is an example of an extrinsic semiconductor.[1]

Street light controller with vehicle sense and LDR Page 13


Figure 3 LDR

IR Sensor:

Figure 4 IR sensor

Street light controller with vehicle sense and LDR Page 14


PRINCIPLE OF WORKING
An Infrared (IR) sensor is used to detect obstacles in front of the
robot or to differentiate between colors depending on the
configuration of the sensor.

An IR sensor consists of an emitter, detector and associated circuitry.


The circuit required to make an IR sensor consists of two parts; the
emitter circuit and the receiver circuit.

The emitter is simply an IR LED (Light Emitting Diode) and the detector
is simply an IR photodiode which is sensitive to IR light of the same
wavelength as that emitted by the IR LED. When IR light falls on the
photodiode, its resistance and correspondingly, its output voltage,
change in proportion to the magnitude of the IR light received. This is
the underlying principle of working of the IR sensor.

Distinguishing between black and white

IR sensors are also used to distinguish between black and white


surfaces. White surfaces reflect all types of light while black surfaces
absorb them. Therefore, depending on the amount of light reflected
back to the IR receiver, the IR sensor can also be used to distinguish
between black and white surfaces.

Street light controller with vehicle sense and LDR Page 15


Let us now see how to build an IR sensor using this principle.

Circuit Diagram

IR Emitter Circuit IR Receiver Circuit

Benefits:
 This project is having application in public street lights area,
school, colleges and other places where traffic is not continuous
or not much in night time.
 This system can save 90% of electricity from every street light.

Street light controller with vehicle sense and LDR Page 16


Figure 5 circuit diagram

Software methodology

SDLC diagram:

Street light controller with vehicle sense and LDR Page 17


FEASIBILITY STUDY

Feasibility study is the measure of how beneficial or practical the


development of an information system will be to an organization.

FEASIBILITY study:

 Technical feasibility:
Technical feasibility of this application is concerned with
specifying equipment and software that will successfully satisfy
the user requirements.

Street light controller with vehicle sense and LDR Page 18


I. The facility to produce outputs in a given time.

II. Losing of data will be reduced.

In technical feasibility, the configuration of the system is a given time


more importance

Than the actual make of the hardware the configuration should give
the complete picture about the system requirements:

How these units are interconnected so that they can operate


and communicate smoothly?

1. What speeds of data transmission could be achived?


2. Specific software and hardware products can then be evaluated
keeping in view with logical needs.

 Operational feasibility:
Operational feasibility covers two aspects. One technical performance
aspects and the other is the acceptance within the organization. The
points to be considered are:

1. What changes will be brought with the system?


2. What organizational are considered?
3. What new skills are required?

Street light controller with vehicle sense and LDR Page 19


Operational feasibility determine how the proposed the system will
fit in with the current operation and what needs to implements the
system

 Economic feasibility:
For the economic feasibility, Economic analysis or
cost/benefit analysis is most frequently used technique the
effectiveness of a proposed system. It is a procedure to determine
the benefits and savings those are expected from the proposed
system and compare them with cost. If the benefits outweigh the
costs, a decision is taken to design and implement the system.
Otherwise, further justification or alternative in the proposed
system will have to be made if it is to have a chance of being
approved this is an ongoing effort that improves in accuracy at each
phase of system life cycle.

Plan of work:
 Module1: Circuit designing.
 Module2: Selection of components and PCB designing.
 Module3: Mounting of components on PCB.
 Module4: Hardware Testing and Final PCB designing.
 Module5: Firmware coding
 Module6: Testing of Complete System

Street light controller with vehicle sense and LDR Page 20


Microcontroller AT89S52
The Intel AT89S52 is a Harvard architecture, single chip micro controller which
was developed by Intel in 1980 for use in embedded systems. Intel's original
versions were popular in the 1980s and early 1990s, but has today[update] largely
been superseded by a vast range of faster and/or functionally enhanced AT89S52-
compatible devices manufactured by more than 20 independent manufacturers
including Atmel, Infineon Technologies. Maxim Integrated Products (via its
Dallas Semiconductor subsidiary), NXP (formerly Philips Semiconductor),
Nuvoton. ST Microelectronics, Silicon Laboratories (formerly Cygnal), Texas
Instruments and Cypress Semiconductor. Intel's official designation for the
AT89S52 family of µCs is MCS 51.

The AT89S52 is one of the most popular micro controllers in use today. Many
derivative micro controllers have since been developed that are based on--and
compatible with--the AT89S52. Thus, the ability to program an AT89S52 is an
important skill for anyone who plans to develop products that will take advantage
of micro controllers.

Important Features And Applications

 It provides many functions (CPU, RAM, ROM, I/O, interrupt logic, timer,
etc.) in a single package
 8-bit ALU, Accumulator and 8-bit Registers; hence it is an 8-bit microcontroller
 8-bit data bus - It can access 8 bits of data in one operation
 16-bit address bus - It can access 216 memory locations - 64KB (65536
locations) each of RAM and ROM
 On-chip RAM - 128 bytes (data memory)
 On-chip ROM - 4k Byte (program memory)
 Four byte bi-directional input/output port
 UART (serial port)
 Two 16-bit Counter/timers
 Two-level interrupt priority
 Power saving mode

Memory Architecture

Street light controller with vehicle sense and LDR Page 21


The AT89S52 has four distinct types of memory - internal RAM, special function
registers, program memory, and external data memory.

The AT89S52 has three very general types of memory. To effectively program
the AT89S52 it is necessary to have a basic understanding of these memory types.

The memory types are illustrated in the following graphic. They are: On-Chip
Memory, External Code Memory, and External RAM.

On-Chip Memory refers to any memory (Code, RAM, or other) that physically
exists on the microcontroller itself. On-chip memory can be of several types, but
we'll get into that shortly.

External Code Memory is code (or program) memory that resides off-chip. This
is often in the form of an external EPROM.

External RAM is RAM memory that resides off-chip. This is often in the form
of standard static RAM or flash RAM.

Code Memory

Code memory is the memory that holds the actual AT89S52 program that is to be
run. This memory is limited to 64K and comes in many shapes and sizes: Code
memory may be found on-chip, either burned into the microcontroller as ROM
or EPROM. Code may also be stored completely off-chip in an external ROM or,
more commonly, an external EPROM. Flash RAM is also another popular
method of storing a program. Various combinations of these memory types may
also be used--that is to say, it is possible to have 4K of code memory on-chip and
64k of code memory off-chip in an EPROM.

Street light controller with vehicle sense and LDR Page 22


When the program is stored on-chip the 64K maximum is often reduced to 4k,
8k, or 16k. This varies depending on the version of the chip that is being used.
Each version offers specific capabilities and one of the distinguishing factors
from chip to chip is how much ROM/EPROM space the chip has.

However, code memory is most commonly implemented as off-chip EPROM.


This is especially true in low-cost development systems and in systems developed
by students.

External RAM

As an obvious opposite of Internal RAM, the AT89S52 also supports what is


called External RAM.

As the name suggests, External RAM is any random access memory which is
found off-chip. Since the memory is off-chip it is not as flexible in terms of
accessing, and is also slower. For example, to increment an Internal RAM
location by 1 requires only 1 instruction and 1 instruction cycle. To increment a
1-byte value stored in External RAM requires 4 instructions and 7 instruction
cycles. In this case, external memory is 7 times slower!

What External RAM loses in speed and flexibility it gains in quantity. While
Internal RAM is limited to 128 bytes (256 bytes with an 8052), the AT89S52
supports External RAM up to 64K.

On-Chip Memory

As mentioned at the beginning of this chapter, the AT89S52 includes a certain


amount of on-chip memory. On-chip memory is really one of two types: Internal
RAM and Special Function Register (SFR) memory. The layout of the AT89S52's
internal memory is presented in the following memory map:

Street light controller with vehicle sense and LDR Page 23


As is illustrated in this map, the AT89S52 has a bank of 128 bytes of Internal
RAM. This Internal RAM is found on-chip on the AT89S52 so it is the fastest
RAM available, and it is also the most flexible in terms of reading, writing, and
modifying its contents. Internal RAM is volatile, so when the AT89S52 is reset
this memory is cleared.

The 128 bytes of internal ram is subdivided as shown on the memory map. The
first 8 bytes (00h - 07h) are "register bank 0". By manipulating certain SFRs, a
program may choose to use register banks 1, 2, or 3. These alternative register
banks are located in internal RAM in addresses 08h through 1Fh. We'll discuss
"register banks" more in a later chapter. For now it is sufficient to know that they
"live" and are part of internal RAM.

Bit Memory also lives and is part of internal RAM. We'll talk more about bit
memory very shortly, but for now just keep in mind that bit memory actually
resides in internal RAM, from addresses 20h through 2Fh.

The 80 bytes remaining of Internal RAM, from addresses 30h through 7Fh, may
be used by user variables that need to be accessed frequently or at high-speed.
This area is also utilized by the microcontroller as a storage area for the operating
stack. This fact severely limits the AT89S52s stack since, as illustrated in the
memory map, the area reserved for the stack is only 80 bytes--and usually it is
less since this 80 bytes has to be shared between the stack and user variables.

Bit Memory

Street light controller with vehicle sense and LDR Page 24


The AT89S52, being a communications-oriented microcontroller, gives the user
the ability to access a number of bit variables. These variables may be 1 or 0.

There are 128 bit variables available to the user, numbers 00h through 7Fh. The
user may make use of these variables with commands such as SETB and CLR.
For example, to set bit number 24 (hex) to 1 you would execute the instruction:

SETB 24h

It is important to note that Bit Memory is really a part of Internal RAM. In fact,
the 128 bit variables occupy the 16 bytes of Internal RAM from 20h through 2Fh.
Thus, if you write the value FFh to Internal RAM address 20h you've effectively
set bits 00h through 07h. That is to say that:
Special Function Register (SFR) Memory

Special Function Registers (SFRs) are areas of memory that control specific
functionality of the AT89S52 processor. For example, four SFRs permit access
to the AT89S52s 32 input/output lines. Another SFR allows a program to read or
write to the AT89S52s serial port. Other SFRs allow the user to set the serial baud
rate, control and access timers, and configure the AT89S52s interrupt system.

The AT89S52 is a flexible microcontroller with a relatively large number of


modes of operations. Your program may inspect and/or change the operating
mode of the AT89S52 by manipulating the values of the AT89S52's Special
Function Registers (SFRs).

SFRs are accessed as if they were normal Internal RAM. The only difference is
that Internal RAM is from address 00h through 7Fh whereas SFR registers exist
in the address range of 80h through FFh.

Each SFR has an address (80h through FFh) and a name. The following chart
provides a graphical presentation of the AT89S52's SFRs, their names, and their
address.

Street light controller with vehicle sense and LDR Page 25


As you can see, although the address range of 80h through FFh offer 128 possible
addresses, there are only 21 SFRs in a standard AT89S52. All other addresses in
the SFR range (80h through FFh) are considered invalid. Writing to or reading
from these registers may produce undefined values or behavior.

Basic Registers
The Accumulator

If you've worked with any other assembly languages you will be familiar with the
concept of an Accumulator register.

The Accumulator, as its name suggests, is used as a general register to accumulate


the results of a large number of instructions. It can hold an 8-bit (1-byte) value
and is the most versatile register the AT89S52 has due to the shear number of
instructions that make use of the accumulator. More than half of the AT89S52s
255 instructions manipulate or use the accumulator in some way.

For example, if you want to add the number 10 and 20, the resulting 30 will be
stored in the Accumulator. Once you have a value in the Accumulator you may

Street light controller with vehicle sense and LDR Page 26


continue processing the value or you may store it in another register or in
memory.

The "R" registers

The "R" registers are a set of eight registers that are named R0, R1, etc. up to and
including R7. These registers are used as auxiliary registers in many operations.
After executing this instruction the Accumulator will contain the value 30. You
may think of the "R" registers as very important auxiliary, or "helper", registers.
The Accumulator alone would not be very useful if it were not for these "R"
registers. The "R" registers are also used to temporarily store values.

The "B" Register

The "B" register is very similar to the Accumulator in the sense that it may hold
an 8-bit (1-byte) value. The "B" register is only used by two AT89S52
instructions: MUL AB and DIV AB. Thus, if you want to quickly and easily
multiply or divide A by another number, you may store the other number in "B"
and make use of these two instructions. A side from the MUL and DIV
instructions, the "B" register is often used as yet another temporary storage
register much like a ninth "R" register.

The Data Pointer (DPTR)

The Data Pointer (DPTR) is the AT89S52s only user-accessible 16-bit (2-byte)
register. The Accumulator, "R" registers, and "B" register are all 1-byte values.
DPTR, as the name suggests, is used to point to data. It is used by a number of
commands which allow the AT89S52 to access external memory. When the
AT89S52 accesses external memory it will access external memory at the address
indicated by DPTR.

While DPTR is most often used to point to data in external memory, many
programmers often take advantage of the fact that its the only true 16-bit register
available. It is often used to store 2-byte values which have nothing to do with
memory locations.

The Program Counter (PC)

Street light controller with vehicle sense and LDR Page 27


The Program Counter (PC) is a 2-byte address which tells the AT89S52 where
the next instruction to execute is found in memory. When the AT89S52 is
initialized PC always starts at 0000h and is incremented each time an instruction
is executed. It is important to note that PC isnt always incremented by one. Since
some instructions require 2 or 3 bytes the PC will be incremented by 2 or 3 in
these cases.

The Program Counter is special in that there is no way to directly modify its value.
That is to say, you cant do something like PC=2430h. On the other hand, if you
execute LJMP 2430h youve effectively accomplished the same thing.

The Stack Pointer (SP)

The Stack Pointer, like all registers except DPTR and PC, may hold an 8-bit (1-
byte) value. The Stack Pointer is used to indicate where the next value to be
removed from the stack should be taken from.

When you push a value onto the stack, the AT89S52 first increments the value of
SP and then stores the value at the resulting memory location.

When you pop a value off the stack, the AT89S52 returns the value from the
memory location indicated by SP, and then decrements the value of SP.

This order of operation is important. When the AT89S52 is initialized SP will be


initialized to 07h. If you immediately push a value onto the stack, the value will
be stored in Internal RAM address 08h. This makes sense taking into account
what was mentioned two paragraphs above: First the AT89S52 will increment the
value of SP (from 07h to 08h) and then will store the pushed value at that memory
address (08h).

SP is modified directly by the AT89S52 by six instructions: PUSH, POP,


ACALL, LCALL, RET, and RETI. It is also used intrinsically whenever an
interrupt is triggered (more on interrupts later. Don't worry about them for now!).

Addressing Mode

An "addressing mode" refers to how you are addressing a given memory location.
In summary, the addressing modes are as follows, with an example of each:
Immediate Addressing MOV A,#20h

Street light controller with vehicle sense and LDR Page 28


Direct Addressing MOV A,30h
Indirect Addressing MOV A,@R0
External Direct MOVX A,@DPTR
Code Indirect MOVC A,@A+DPTR

Each of these addressing modes provides important flexibility.

Immediate Addressing

Immediate addressing is so-named because the value to be stored in memory


immediately follows the operation code in memory. That is to say, the instruction
itself dictates what value will be stored in memory.

Direct Addressing

Direct addressing is so-named because the value to be stored in memory is


obtained by directly retrieving it from another memory location.

Indirect Addressing

Indirect addressing is a very powerful addressing mode which in many cases


provides an exceptional level of flexibility. Indirect addressing is also the only
way to access the extra 128 bytes of Internal RAM found on an 8052.

External Direct

External Memory is accessed using a suite of instructions which use what I call
"External Direct" addressing. I call it this because it appears to be direct
addressing, but it is used to access external memory rather than internal memory.

External Indirect

External memory can also be accessed using a form of indirect addressing which
I call External Indirect addressing. This form of addressing is usually only used
in relatively small projects that have a very small amount of external RAM.

Street light controller with vehicle sense and LDR Page 29


Program Flow

When an AT89S52 is first initialized, it resets the PC to 0000h. The AT89S52


then begins to execute instructions sequentially in memory unless a program
instruction causes the PC to be otherwise altered. There are various instructions
that can modify the value of the PC; specifically, conditional branching
instructions, direct jumps and calls, and "returns" from subroutines. Additionally,
interrupts, when enabled, can cause the program flow to deviate from its
otherwise sequential scheme.

Conditional Branching

The AT89S52 contains a suite of instructions which, as a group, are referred to


as "conditional branching" instructions. These instructions cause program
execution to follow a non-sequential path if a certain condition is true.
Conditional branching is really the fundamental building block of program logic
since all "decisions" are accomplished by using conditional branching.
Conditional branching can be thought of as the "IF...THEN" structure in
AT89S52 assembly language.

An important note worth mentioning about conditional branching is that the


program may only branch to instructions located within 128 bytes prior to or 127
bytes following the address which follows the conditional branch instruction.
This means that in the above example the label HELLO must be within +/- 128
bytes of the memory address which contains the conditional branching
instruction.

Direct Jumps

While conditional branching is extremely important, it is often necessary to make


a direct branch to a given memory location without basing it on a given logical
decision. This is equivalent to saying "Go to" in BASIC. In this case you want
the program flow to continue at a given memory address without considering any
conditions.

The obvious difference between the Direct Jump and Call instructions and the
conditional branching is that with Direct Jumps and Calls program flow always
changes. With conditional branching program flow only changes if a certain
condition is true.

Street light controller with vehicle sense and LDR Page 30


Direct Calls

Another operation that will be familiar to seasoned programmers is the LCALL


instruction. This is similar to a "Go sub" command in Basic.

When the AT89S52 executes an LCALL instruction it immediately pushes the


current Program Counter onto the stack and then continues executing code at the
address indicated by the LCALL instruction.

Interrupts

An interrupt is a special feature which allows the AT89S52 to provide the illusion
of "multi-tasking," although in reality the AT89S52 is only doing one thing at a
time. The word "interrupt" can often be substituted with the word "event."

An interrupt is triggered whenever a corresponding event occurs. When the event


occurs, the AT89S52 temporarily puts "on hold" the normal execution of the
program and executes a special section of code referred to as an interrupt handler.
The interrupt handler performs whatever special functions are required to handle
the event and then returns control to the AT89S52 at which point program
execution continues as if it had never been interrupted.

The topic of interrupts is somewhat tricky and very important. For that reason, an
entire chapter will be dedicated to the topic. For now, suffice it to say that
Interrupts can cause program flow to change.

Timers
The AT89S52 comes equipped with two timers, both of which may be controlled,
set, read, and configured individually. The AT89S52 timers have three general
functions: 1) Keeping time and/or calculating the amount of time between events,
2) Counting the events themselves, or 3) Generating baud rates for the serial port.

The three timer uses are distinct so we will talk about each of them separately.
The first two uses will be discussed in this chapter while the use of timers for
baud rate generation will be discussed in the chapter relating to serial ports.

Timer SFRs

Street light controller with vehicle sense and LDR Page 31


As mentioned before, the AT89S52 has two timers which each function
essentially the same way. One timer is TIMER0 and the other is TIMER1. The
two timers share two SFRs (TMOD and TCON) which control the timers, and
each timer also has two SFRs dedicated solely to itself (TH0/TL0 and TH1/TL1).

We've given SFRs names to make it easier to refer to them, but in reality an SFR
has a numeric address. It is often useful to know the numeric address that
corresponds to an

13-bit Time Mode (mode 0)

Timer mode "0" is a 13-bit timer. This is a relic that was kept around in the
AT89S52 to maintain compatibility with its predecessor, the 8048. Generally the
13-bit timer mode is not used in new development.

When the timer is in 13-bit mode, TLx will count from 0 to 31. When TLx is
incremented from 31, it will "reset" to 0 and increment THx. Thus, effectively,
only 13 bits of the two timer bytes are being used: bits 0-4 of TLx and bits 0-7 of
THx. This also means, in essence, the timer can only contain 8192 values. If you
set a 13-bit timer to 0, it will overflow back to zero 8192 machine cycles later.

Again, there is very little reason to use this mode and it is only mentioned so you
wont be surprised if you ever end up analyzing archaic code which has been
passed down through the generations (a generation in a programming shop is
often on the order of about 3 or 4 months).

16-bit Time Mode (mode 1)

Timer mode "1" is a 16-bit timer. This is a very commonly used mode. It functions
just like 13-bit mode except that all 16 bits are used.

TLx is incremented from 0 to 255. When TLx is incremented from 255, it resets
to 0 and causes THx to be incremented by 1. Since this is a full 16-bit timer, the
timer may contain up to 65536 distinct values. If you set a 16-bit timer to 0, it
will overflow back to 0 after 65,536 machine cycles.

8-bit Time Mode (mode 2)

Street light controller with vehicle sense and LDR Page 32


Timer mode "2" is an 8-bit auto-reload mode. What is that, you may ask? Simple.
When a timer is in mode 2, THx holds the "reload value" and TLx is the timer
itself. Thus, TLx starts counting up. When TLx reaches 255 and is subsequently
incremented, instead of resetting to 0 (as in the case of modes 0 and 1), it will be
reset to the value stored in THx.

Split Timer Mode (mode 3)

Timer mode "3" is a split-timer mode. When Timer 0 is placed in mode 3, it


essentially becomes two separate 8-bit timers. That is to say, Timer 0 is TL0 and
Timer 1 is TH0. Both timers count from 0 to 255 and overflow back to 0. All the
bits that are related to Timer 1 will now be tied to TH0.

While Timer 0 is in split mode, the real Timer 1 (i.e. TH1 and TL1) can be put
into modes 0, 1 or 2 normally--however, you may not start or stop the real timer
1 since the bits that do that are now linked to TH0. The real timer 1, in this case,
will be incremented every machine cycle no matter what.

The only real use I can see of using split timer mode is if you need to have two
separate timers and, additionally, a baud rate generator. In such case you can use
the real Timer 1 as a baud rate generator and use TH0/TL0 as two separate timers.

Reading the Timer

There are two common ways of reading the value of a 16-bit timer; which you
use depends on your specific application. You may either read the actual value of
the timer as a 16-bit number, or you may simply detect when the timer has
overflowed.

Reading the value of a Timer

If your timer is in an 8-bit mode--that is, either 8-bit Auto Reload mode or in split
timer mode--then reading the value of the timer is simple. You simply read the 1-
byte value of the timer and you're done.

However, if you're dealing with a 13-bit or 16-bit timer the chore is a little more
complicated. Consider what would happen if you read the low byte of the timer
as 255, then read the high byte of the timer as 15. In this case, what actually
happened was that the timer value was 14/255 (high byte 14, low byte 255) but

Street light controller with vehicle sense and LDR Page 33


you read 15/255. Why? Because you read the low byte as 255. But when you
executed the next instruction a small amount of time passed--but enough for the
timer to increment again at which time the value rolled over from 14/255 to 15/0.
But in the process you've read the timer as being 15/255. Obviously there's a
problem there.

Detecting Timer Overflow

Often it is necessary to just know that the timer has reset to 0. That is to say, you
are not particularly interest in the value of the timer but rather you are interested
in knowing when the timer has overflowed back to 0.

Timing the length of events

The AT89S52 provides another cool toy that can be used to time the length of
events.

For example, let's say we're trying to save electricity in the office and we're
interested in how long a light is turned on each day. When the light is turned on,
we want to measure time. When the light is turned off we don't. One option would
be to connect the light switch to one of the pins, constantly read the pin, and turn
the timer on or off based on the state of that pin. While this would work fine, the
AT89S52 provides us with an easier method of accomplishing this.

Looking again at the TMOD SFR, there is a bit called GATE0. So far we've
always cleared this bit because we wanted the timer to run regardless of the state
of the external pins. However, now it would be nice if an external pin could
control whether the timer was running or not. It can. All we need to do is connect
the light switch to pin INT0 (P3.2) on the AT89S52 and set the bit GATE0. When
GATE0 is set Timer 0 will only run if P3.2 is high. When P3.2 is low (i.e., the
light switch is off) the timer will automatically be stopped.

Thus, with no control code whatsoever, the external pin P3.2 can control whether
or not our timer is running or not.

Serial port Operation


One of the AT89S52s many powerful features is its integrated UART, otherwise
known as a serial port. The fact that the AT89S52 has an integrated serial port

Street light controller with vehicle sense and LDR Page 34


means that you may very easily read and write values to the serial port. If it were
not for the integrated serial port, writing a byte to a serial line would be a rather
tedious process requiring turning on and off one of the I/O lines in rapid
succession to properly "clock out" each individual bit, including start bits, stop
bits, and parity bits.

However, we do not have to do this. Instead, we simply need to configure the


serial ports operation mode and baud rate. Once configured, all we have to do is
write to an SFR to write a value to the serial port or read the same SFR to read a
value from the serial port. The AT89S52 will automatically let us know when it
has finished sending the character we wrote and will also let us know whenever
it has received a byte so that we can process it. We do not have to worry about
transmission at the bit level--which saves us quite a bit of coding and processing
time.

Setting the Serial Port Mode

The first thing we must do when using the AT89S52s integrated serial port is,
obviously, configure it. This lets us tell the AT89S52 how many data bits we
want, the baud rate we will be using, and how the baud rate will be determined.

First, lets present the "Serial Control" (SCON) SFR and define what each bit of
the SFR represents:

Nam Bit
Bit Explanation of Function
e Address
7 SM0 9Fh Serial port mode bit 0
6 SM1 9Eh Serial port mode bit 1.
5 SM2 9Dh Multiprocessor Communications Enable (explained later)
Receiver Enable. This bit must be set in order to receive
4 REN 9Ch
characters.
3 TB8 9Bh Transmit bit 8. The 9th bit to transmit in mode 2 and 3.
2 RB8 9Ah Receive bit 8. The 9th bit received in mode 2 and 3.
Transmit Flag. Set when a byte has been completely
1 TI 99h
transmitted.
Receive Flag. Set when a byte has been completely
0 RI 98h
received.

Street light controller with vehicle sense and LDR Page 35


Additionally, it is necessary to define the function of SM0 and SM1 by an
additional table:

Serial
SM0 SM1 Explanation Baud Rate
Mode
0 0 0 8-bit Shift Register Oscillator / 12
0 1 1 8-bit UART Set by Timer 1 (*)
1 0 2 9-bit UART Oscillator / 64 (*)
1 1 3 9-bit UART Set by Timer 1 (*)

Setting the Serial Port Baud Rate

Once the Serial Port Mode has been configured, as explained above, the program
must configure the serial ports baud rate. This only applies to Serial Port modes
1 and 3. The Baud Rate is determined based on the oscillators frequency when in
mode 0 and 2. In mode 0, the baud rate is always the oscillator frequency divided
by 12. This means if you're crystal is 11.059Mhz, mode 0 baud rate will always
be 921,583 baud. In mode 2 the baud rate is always the oscillator frequency
divided by 64, so a 11.059Mhz crystal speed will yield a baud rate of 172,797.

In modes 1 and 3, the baud rate is determined by how frequently timer 1


overflows. The more frequently timer 1 overflows, the higher the baud rate. There
are many ways one can cause timer 1 to overflow at a rate that determines a baud
rate, but the most common method is to put timer 1 in 8-bit auto-reload mode
(timer mode 2) and set a reload value (TH1) that causes Timer 1 to overflow at a
frequency appropriate to generate a baud rate.

Writing to the Serial Port

Once the Serial Port has been property configured as explained above, the serial
port is ready to be used to send data and receive data. If you thought that
configuring the serial port was simple, using the serial port will be a breeze.

To write a byte to the serial port simply write the value to the SBUF (99h) SFR.
Reading the Serial Port

Street light controller with vehicle sense and LDR Page 36


Reading data received by the serial port is equally easy. To read a byte from the
serial port one just needs to read the value stored in the SBUF (99h) SFR after
the AT89S52 has automatically set the RI flag in SCON.

BC-547 Transistor

BC547 is an NPN bi-polar junction transistor. A transistor, stands for


transfer of resistance, is commonly used to amplify current. A small
current at its base controls a larger current at collector & emitter
terminals.
BC547 is mainly used for amplification and switching purposes. It has
a maximum current gain of 800. Its equivalent transistors are BC548
and BC549.
The transistor terminals require a fixed DC voltage to operate in the
desired region of its characteristic curves. This is known as the biasing.
For amplification applications, the transistor is biased such that it is
partly on for all input conditions. The input signal at base is amplified
and taken at the emitter. BC547 is used in common emitter
configuration for amplifiers. The voltage divider is the commonly used

Street light controller with vehicle sense and LDR Page 37


biasing mode. For switching applications, transistor is biased so that it
remains fully on if there is a signal at its base. In the absence of base
signal, it gets completely off.

Street light controller with vehicle sense and LDR Page 38


IR Sensor

An infrared sensor is an electronic device, that emits in order to sense


some aspects of the surroundings. An IR sensor can measure the heat
of an object as well as detects the motion. These types of sensors
measures only infrared radiation, rather than emitting it that is called
as a passive IR sensor. Usually in the infrared spectrum, all the objects
radiate some form of thermal radiations. These types of radiations
are invisible to our eyes, that can be detected by an infrared sensor.
The emitter is simply an IR LED (Light Emitting Diode) and the detector
is simply an IR photodiode which is sensitive to IR light of the same
wavelength as that emitted by the IR LED. When IR light falls on the
photodiode, The resistances and these output voltages, change in
proportion to the magnitude of the IR light received.

IR Sensor Circuit Diagram and Working Principle

An infrared sensor circuit is one of the basic and popular sensor


module in an electronic device. This sensor is analogous to human’s
visionary senses, which can be used to detect obstacles and it is one
of the common applications in real time.This circuit comprises of the
following components

 LM358 IC 2 IR transmitter and receiver pair


 Resistors of the range of kilo ohms.
 Variable resistors.
 LED (Light Emitting Diode).

Street light controller with vehicle sense and LDR Page 39


In this project, the transmitter section includes an IR sensor, which
transmits continuous IR rays to be received by an IR receiver module.
An IR output terminal of the receiver varies depending upon its
receiving of IR rays. Since this variation cannot be analyzed as such,
therefore this output can be fed to a comparator circuit. Here an
operational amplifier (op-amp) of LM 339 is used as comparator
circuit.

When the IR receiver does not receive a signal, the potential at the
inverting input goes higher than that non-inverting input of the
comparator IC (LM339). Thus the output of the comparator goes low,
but the LED does not glow. When the IR receiver module receives
signal to the potential at the inverting input goes low. Thus the output
of the comparator (LM 339) goes high and the LED starts glowing.
Resistor R1 (100 ), R2 (10k ) and R3 (330) are used to ensure that
minimum 10 mA current passes through the IR LED Devices like
Photodiode and normal LEDs respectively. Resistor VR2 (preset=5k ) is
used to adjust the output terminals. Resistor VR1 (preset=10k ) is used
to set the sensitivity of the circuit Diagram. Read more about IR
sensors.

Principles of Operation

We have already discussed how a light sensor works. IR Sensors work


by using a specific light sensor to detect a select light wavelength in

Street light controller with vehicle sense and LDR Page 40


the Infra-Red (IR) spectrum. By using an LED which produces light at
the same wavelength as what the sensor is looking for, you can look
at the intensity of the received light. When an object is close to the
sensor, the light from the LED bounces off the object and into the light
sensor. This results in a large jump in the intensity, which we already
know can be detected using a threshold.

Detecting Brightness

Since the sensor works by looking for reflected light, it is possible to


have a sensor that can return the value of the reflected light. This type
of sensor can then be used to measure how "bright" the object is. This
is useful for tasks like line tracking.

Street light controller with vehicle sense and LDR Page 41


If you are into electronics, PCBs are the most common things you will
see. These boards make our lives easier by eliminating all those
connecting wires and breadboards. If properly designed, it even
makes our project look smaller and sexy.

What is a circuit board? A printed circuit board (PCB) mechanically


supports and electrically connects electronic components using
conductive tracks, pads and other features etched from copper sheets
laminated onto a non-conductive substrate. A printed circuit board
has pre-designed copper tracks on a conducting sheet. The pre-
defined tracks reduce the wiring thereby reducing the faults arising
due to lose connections. One needs to simply place the components
on the PCB and solder them.

In this cool tutorial, I will show you how you can make circuit boards
at home easily. Doing so will save you a lot of time from debugging
and double checking the connections on a breadboard. You could even

Street light controller with vehicle sense and LDR Page 42


make your own arduino after going through this tutorial: DIY Arduino
and the current one. So, sit back and see how its done really easily :)

What are the different ways to make a Circuit Board?

There are in all three basic methods to make PCB:

1. Iron on Glossy paper method.


2. Circuit by hand on PCB.
3. Laser cutting edge etching.

Since laser method is industrial method to make PCB we will get in


detail of first two methods to make PCB at home.

PCB Design:

PCB design is usually done by converting your circuit’s schematic


diagram into a PCB layout using PCB layout software. There are many
cool open source software packages for PCB layout creation and
design.

Some are listed here to give you a head-start:

1. Cadsoft Eagle (http://www.cadsoftusa.com/download-


eagle/?language=en)
2. PCBWizard (http://pcb-wizard.software.informer.com/4.0/)

Street light controller with vehicle sense and LDR Page 43


Design your circuit schematic in Cadsoft Eagle:
In Eagle: File> Export>ImageBe sure to set DPIG to 1200 for better
quality

What are the stuff required to make a Circuit Board?

Street light controller with vehicle sense and LDR Page 44


You also need: FeCl3 powder/solution (same as etching solution),
photo/glossy paper, permanent black marker, blade cutter,
sandpaper, kitchen paper, cotton wool.

For this tutorial, lets consider making a PCB for a simple project- a
Touch Switch using IC555.

STEP 1: Take printout of circuit board layout

Take a print out of your PCB layout using the laser printer and the A4
photo paper/glossy paper. Keep in mind the following points:

 You should take the mirror print out.


 Select the output in black both from the PCB design software and
printer driver settings.
 Make sure that the printout is made on the glossy side of the
paper.

PCB print on glossy paper

Street light controller with vehicle sense and LDR Page 45


STEP 2: Cutting the copper plate for the circuit board

Cut the copper board according to the size of layout using a hacksaw
or a cutter.

Copper clad plate

Cutting the plate

Next, rub the copper side of PCB using steel wool or abrasive spongy
scrubs. This removes the top oxide layer of copper as well as the photo

Street light controller with vehicle sense and LDR Page 46


resists layer. Sanded surfaces also allows the image from the paper to
stick better.

Rubbing away the top oxide layer

STEP 3: Transferring the PCB print onto the copper plate

Method 1 Iron on glossy paper method (for complex


circuits): Transfer the printed image (taken from a laser printer) from
the photo paper to the board. Make sure to flip top layer horizontally.
Put the copper surface of the board on the printed layout. Ensure that
the board is aligned correctly along the borders of the printed
layout. And use tape to hold the board and the printed paper in the
correct position.

Street light controller with vehicle sense and LDR Page 47


Place the printed side of the paper on the plate

Method 2 Circuit by hand on PCB (for simple and small circuits):


Taking the circuit as reference, draw a basic sketch on copper plate
with pencil and then by using a permanent black marker.

Using the permanent marker for sketching the PCB

STEP 4: Ironing the circuit from the paper onto the PCB plate

 After printing on glossy paper, we iron it image side down to


copper side. Heat up the electric iron to the maximum
temperature.

Street light controller with vehicle sense and LDR Page 48


 Put the board and photo paper arrangement on a clean wooden
table (covered with a table cloth) with the back of the photo
paper facing you.
 Using pliers or a spatula, hold one end and keep it steady. Then
put the hot iron on the other end for about 10 seconds. Now,
iron the photo paper all along using the tip and applying little
pressure for about 5 to 15 mins.
 Pay attention towards the edges of the board – you need to
apply pressure, do the ironing slowly.
 Doing a long hard press seems to work better than moving the
iron around.
 Here, the heat from the iron transfers the ink printed on the
glossy paper to the copper plate.

Iron the paper onto the plate

CAUTION: Do not directly touch copper plate because it is very hot


due to ironing.

Street light controller with vehicle sense and LDR Page 49


After ironing, place printed plate in luke warm water for around 10
minutes. Paper will dissolve, then remove paper gently. Remove the
paper off by peeling it from a low angle.

Peeling the paper

In some cases while removing the paper, some of the tracks get
fainted. In the figure below, you can see that the track is light in colour
hence we can use a black marker to darken it as shown.

Light trace

Street light controller with vehicle sense and LDR Page 50


Darkening the trace

STEP 5: Etching the plate

You need to be really careful while performing this step.

 First put rubber or plastic gloves.


 Place some newspaper on the bottom so that the etching
solution does not spoil your floor.
 Take a plastic box and fill it up with some water.
 Dissolve 2-3 tea spoon of ferric chloride power in the water.
 Dip the PCB into the etching solution (Ferric chloride solution,
FeCl3) for approximately 30 mins.
 The FeCl3 reacts with the unmasked copper and removes the
unwanted copper from the PCB.
 This process is called as Etching. Use pliers to take out the PCB
and check if the entire unmasked area has been etched or not.
In case it is not etched leave it for some more time in the
solution.

Street light controller with vehicle sense and LDR Page 51


Etching the plate

Gently move the plastic box to and fro so that etching solution reacts
with the exposed copper. The reaction is given as:
Cu + FeCl3 = CuCl3 + Fe
After every two minutes check if all the copper has been removed. If
it hasn’t then place it back in the solution and wait.

CAUTION: Always use gloves while touching the plate having the
solution.

Street light controller with vehicle sense and LDR Page 52


Etched copper plate

STEP 6: Cleaning, disposing and final touches for the circuit board

Be careful while disposing the etching solution, since its toxic to fish
and other water organisms. And don’t think about pouring it in the
sink when you are done, it is illegal to do so and might damage your
pipes (hehe, who knew you could get arrested while making a PCB!).
So dilute the etching solution and then throw it away somewhere safe.

A few drops of thinner (nail polish remover works well) on a pinch of


cotton wool will remove completely the toner/ink on the plate,
exposing the copper surface. Rinse carefully and dry with a clean cloth
or kitchen paper. Trim to final size and smoothen edges with
sandpaper.

Street light controller with vehicle sense and LDR Page 53


Removing the ink

Now, drill holes using a PCB driller like this: PCB driller and solder all
your cool components. If you want that traditional green PCB look,
apply solder resist paint on top: PCB lacquer. And finally! your super
cool circuit board would be ready!

Linear Power Supplies


In the last installment of the Power Supply Tutorial, we found that the most basic
power supply was of a simple unregulated design. We also found that for all but
the least demanding applications, the unregulated design is not able to maintain
the output voltage close enough to the prescribed set point as the line voltage
and load current changes. Thus, regulation methods have been developed to
maintain the output voltage or current at a constant set point. The first type of
regulated design was the linear regulator power supply.

Street light controller with vehicle sense and LDR Page 54


The term “linear power supply” is typically thought of as a type of AC/DC system,
providing a regulated output. The linear regulator is actually the part of the
linear regulator power supply that performs the regulation.

Linear Regulator Theory

Linear regulators employ a pass element serving as a variable resistor which


forms a voltage divider with the load.

The pass element functioning as a variable resistor can be semiconductor


devices such as a bipolar junction transistor (BJT), power metal oxide
semiconductor field effect transistor (MOSFET), insulated gate bipolar transistor
(IGBT), or an electron tube such as a triode, tetrode, or pentode. Electron tubes
would be used in highly specialized applications where there are no
semiconductor devices suitable.

Power Output Capability

A linear regulator can be designed to regulate power outputs as small as a watt


or less. Linear regulators used alone in this fashion are performing DC/DC
conversion. Linear power supplies can be designed to provide AC/DC conversion
up to tens of kilowatts or even more. In this case the linear regulator is coupled
with additional circuitry providing rectification and filtering.

Noise and Ripple

Perhaps the most significant merit of linear power supplies is the cleanliness of
the output voltage and the relative lack of electromagnetic emissions. The
typical peak to peak output voltage ripple for a linear supply might be 1000x or
60dB less than the output DC level. So for a 5V output supply the typical peak to
peak ripple voltage might be 5mV. A switching supply typically sees about a 100x

Street light controller with vehicle sense and LDR Page 55


or 40dB reduction. It is possible with careful design to achieve a 10,000x or 80dB
reduction in a linear regulated power supply.

Transient Response

The response of linear power supplies to line and load transients is better their
switching counterparts because the linear supply does not have a switching
frequency to limit the bandwidth. In linear supplies, the regulation bandwidth is
typically limited by parasitic device elements.

Weight and Size

The weight and size of the linear power supply is the major disadvantage. AC/DC
conversion is done at low frequencies and therefore the transformer must be
large to keep the core from saturating. This factor, along with efficiency to be
discussed next, is the main reason why linear power supplies have limited use
today. For example, a 500W linear power supply might weigh about 50 pounds
and occupy a desktop. Whereas a 500W switching supply might weight less than
10 pounds and sit on a small part of the desktop.

Efficiency

Linear regulators are typically thought of a being extremely inefficient – but that
is not always the case and they can sometimes be more efficient that a switching
power supply!

On a first order basis, the efficiency of a linear regulator is very simple to


determine. The efficiency is simply the output voltage divided by the input
voltage. If determined effort is made to keep the difference between the pass
element input voltage and the output voltage as small as possible, the efficiency
can be very good. This type of linear regulator is called a “low-dropout
regulator”. For other cases where the operating point is not conducive to
maintaining a low dropout, the linear regulator efficiency can suffer greatly.

Street light controller with vehicle sense and LDR Page 56


As an example, if the input voltage in the figure above is 13.6 volts, and the
regulator maintains an output voltage of 12 volts, for a voltage drop of 1.6 volts,
the efficiency of the linear regulator is 12V/13.6V = 88.2%. The efficiency in this
case is very good by most standards.

As another example, if the input voltage is 5 volts and the output voltage is 3.3
volts, for a voltage drop of 1.7 volts, the efficiency is 3.3V/5V = 66%. The
efficiency in this case is not very good by most standards.

As a last example, if the input voltage is 5 volts and the output voltage is 1.8
volts, for a pass element voltage drop of 3.2 volts, the efficiency is 1.8V/5V =
36%. This efficiency in this case is very poor.

Summary

In this article we found that linear power supplies excel in producing outputs
with very low noise and ripple, low electromagnetic emissions, and have
excellent transient response. However, they are by nature large and heavy when
compared to switching power supplies. Linear power supplies would be the type
of choice when outputs with low ripple and noise content are of paramount
concern, and where larger size and substantially greater weight can be
tolerated.

Switched-mode power supply

A switched-mode power supply (switching-mode power supply, SMPS, or


switcher) is an electronic power supply that incorporates a switching regulator

Street light controller with vehicle sense and LDR Page 57


to convert electrical power efficiently. Like other power supplies, an SMPS
transfers power from a source, like mains power, to a load, such as a personal
computer, while converting voltage and current characteristics. Unlike a linear
power supply, the pass transistor of a switching-mode supply continually
switches between low-dissipation, full-on and full-off states, and spends very
little time in the high dissipation transitions, which minimizes wasted energy.
Ideally, a switched-mode power supply dissipates no power. Voltage regulation
is achieved by varying the ratio of on-to-off time. In contrast, a linear power
supply regulates the output voltage by continually dissipating power in the pass
transistor. This higher power conversion efficiency is an important advantage of
a switched-mode power supply. Switched-mode power supplies may also be
substantially smaller and lighter than a linear supply due to the smaller
transformer size and weight.

Switching regulators are used as replacements for linear regulators when higher
efficiency, smaller size or lighter weight are required. They are, however, more
complicated; their switching currents can cause electrical noise problems if not
carefully suppressed, and simple designs may have a poor power factor.

Explanation

A linear regulator provides the desired output voltage by dissipating excess


power in ohmic losses (e.g., in a resistor or in the collector–emitter region of a
pass transistor in its active mode). A linear regulator regulates either output
voltage or current by dissipating the excess electric power in the form of heat,
and hence its maximum power efficiency is voltage-out/voltage-in since the volt
difference is wasted.

In contrast, a switched-mode power supply regulates either output voltage or


current by switching ideal storage elements, like inductors and capacitors, into
and out of different electrical configurations. Ideal switching elements (e.g.,
transistors operated outside of their active mode) have no resistance when
"closed" and carry no current when "open", and so the converters can
theoretically operate with 100% efficiency (i.e., all input power is delivered to
the load; no power is wasted as dissipated heat).

Street light controller with vehicle sense and LDR Page 58


For example, if a DC source, an inductor, a switch, and the corresponding
electrical ground are placed in series and the switch is driven by a square wave,
the peak-to-peak voltage of the waveform measured across the switch can
exceed the input voltage from the DC source. This is because the inductor
responds to changes in current by inducing its own voltage to counter the
change in current, and this voltage adds to the source voltage while the switch
is open. If a diode-and-capacitor combination is placed in parallel to the switch,
the peak voltage can be stored in the capacitor, and the capacitor can be used
as a DC source with an output voltage greater than the DC voltage driving the
circuit. This boost converter acts like a step-up transformer for DC signals. A
buck–boost converter works in a similar manner, but yields an output voltage
which is opposite in polarity to the input voltage. Other buck circuits exist to
boost the average output current with a reduction of voltage.

In an SMPS, the output current flow depends on the input power signal, the
storage elements and circuit topologies used, and also on the pattern used (e.g.,
pulse-width modulation with an adjustable duty cycle) to drive the switching
elements. The spectral density of these switching waveforms has energy
concentrated at relatively high frequencies. As such, switching transients and
ripple introduced onto the output waveforms can be filtered with small LC
filters.

Advantages and disadvantages

The main advantage of the switching power supply is greater efficiency because
the switching transistor dissipates little power when acting as a switch. Other
advantages include smaller size and lighter weight from the elimination of heavy
line-frequency transformers, and lower heat generation due to higher efficiency.
Disadvantages include greater complexity, the generation of high-amplitude,
high-frequency energy that the low-pass filter must block to avoid

Street light controller with vehicle sense and LDR Page 59


electromagnetic interference (EMI), a ripple voltage at the switching frequency
and the harmonic frequencies thereof.

Very low cost SMPSs may couple electrical switching noise back onto the mains
power line, causing interference with A/V equipment connected to the same
phase. Non-power-factor-corrected SMPSs also cause harmonic distortion.

SMPS and linear power supply comparison

There are two main types of regulated power supplies available: SMPS and
linear. The following table compares linear regulated and unregulated AC-to-DC
supplies with switching regulators in general:

Theory of operation

Block diagram of a mains operated AC/DC SMPS with output voltage


regulation

Input rectifier stage

Street light controller with vehicle sense and LDR Page 60


AC, half-wave and full-wave rectified signals.

If the SMPS has an (AC input), then the first stage is to convert the input to DC.
This is called rectification. A SMPS with a DC input does not require this stage. In
some power supplies (mostly computer ATX power supplies), the rectifier circuit
can be configured as a voltage doubler by the addition of a switch operated
either manually or automatically. This feature permits operation from power
sources that are normally at 115 V or at 230 V. The rectifier produces an
unregulated DC voltage which is then sent to a large filter capacitor. The current
drawn from the mains supply by this rectifier circuit occurs in short pulses
around the AC voltage peaks. These pulses have significant high frequency
energy which reduces the power factor. To correct for this, many newer SMPS
will use a special PFC circuit to make the input current follow the sinusoidal
shape of the AC input voltage, correcting the power factor. Power supplies that
use Active PFC usually are auto-ranging, supporting input voltages from ~100
VAC – 250 VAC, with no input voltage selector switch.

A SMPS designed for AC input can usually be run from a DC supply, because the
DC would pass through the rectifier unchanged.[16] If the power supply is
designed for 115 VAC and has no voltage selector switch, the required DC
voltage would be 163 VDC (115 × √2). This type of use may be harmful to the
rectifier stage, however, as it will only use half of diodes in the rectifier for the
full load. This could possibly result in overheating of these components, causing
them to fail prematurely. On the other hand, if the power supply has a voltage
selector switch for 115/230V (computer ATX power supplies typically are in this
category), the selector switch would have to be put in the 230 V position, and
the required voltage would be 325 VDC (230 × √2). The diodes in this type of
power supply will handle the DC current just fine because they are rated to
handle double the nominal input current when operated in the 115 V mode, due
to the operation of the voltage doubler. This is because the doubler, when in
operation, uses only half of the bridge rectifier and runs twice as much current
through it.[17] It is uncertain how an Auto-ranging/Active-PFC type power supply
would react to being powered by DC.

Street light controller with vehicle sense and LDR Page 61


Inverter stage
This section refers to the block marked chopper in the diagram.

The inverter stage converts DC, whether directly from the input or from the
rectifier stage described above, to AC by running it through a power oscillator,
whose output transformer is very small with few windings at a frequency of tens
or hundreds of kilohertz. The frequency is usually chosen to be above 20 kHz, to
make it inaudible to humans. The switching is implemented as a multistage (to
achieve high gain) MOSFET amplifier. MOSFETs are a type of transistor with a
low on-resistance and a high current-handling capacity.

Voltage converter and output rectifier

If the output is required to be isolated from the input, as is usually the case in
mains power supplies, the inverted AC is used to drive the primary winding of a
high-frequency transformer. This converts the voltage up or down to the
required output level on its secondary winding. The output transformer in the
block diagram serves this purpose.

If a DC output is required, the AC output from the transformer is rectified. For


output voltages above ten volts or so, ordinary silicon diodes are commonly
used. For lower voltages, Schottky diodes are commonly used as the rectifier
elements; they have the advantages of faster recovery times than silicon diodes
(allowing low-loss operation at higher frequencies) and a lower voltage drop
when conducting. For even lower output voltages, MOSFETs may be used as
synchronous rectifiers; compared to Schottky diodes, these have even lower
conducting state voltage drops.

The rectified output is then smoothed by a filter consisting of inductors and


capacitors. For higher switching frequencies, components with lower
capacitance and inductance are needed.

Simpler, non-isolated power supplies contain an inductor instead of a


transformer. This type includes boost converters, buck converters, and the buck-
boost converters. These belong to the simplest class of single input, single output
converters which use one inductor and one active switch. The buck converter
reduces the input voltage in direct proportion to the ratio of conductive time to

Street light controller with vehicle sense and LDR Page 62


the total switching period, called the duty cycle. For example an ideal buck
converter with a 10 V input operating at a 50% duty cycle will produce an
average output voltage of 5 V. A feedback control loop is employed to regulate
the output voltage by varying the duty cycle to compensate for variations in
input voltage. The output voltage of a boost converter is always greater than the
input voltage and the buck-boost output voltage is inverted but can be greater
than, equal to, or less than the magnitude of its input voltage. There are many
variations and extensions to this class of converters but these three form the
basis of almost all isolated and non-isolated DC to DC converters. By adding a
second inductor the Ćuk and SEPIC converters can be implemented, or, by
adding additional active switches, various bridge converters can be realized.

Other types of SMPSs use a capacitor-diode voltage multiplier instead of


inductors and transformers. These are mostly used for generating high voltages
at low currents (Cockcroft-Walton generator). The low voltage variant is called
charge pump.

Regulation

This charger for a small device such as a mobile phone is a simple off-line switching power
supply in a European plug.

A feedback circuit monitors the output voltage and compares it with a reference
voltage, which shown in the block diagram serves this purpose. Depending on
design/safety requirements, the controller may contain an isolation mechanism
(such as opto-couplers) to isolate it from the DC output. Switching supplies in
computers, TVs and VCRs have these opto-couplers to tightly control the output
voltage.

Street light controller with vehicle sense and LDR Page 63


Open-loop regulators do not have a feedback circuit. Instead, they rely on
feeding a constant voltage to the input of the transformer or inductor, and
assume that the output will be correct. Regulated designs compensate for the
impedance of the transformer or coil. Monopolar designs also compensate for
the magnetic hysteresis of the core.

The feedback circuit needs power to run before it can generate power, so an
additional non-switching power-supply for stand-by is added.

Transformer design

Any switched-mode power supply that gets its power from an AC power line
(called an "off-line" converters[18]) requires a transformer for galvanic isolation.
Some DC-to-DC converters may also include a transformer, although isolation
may not be critical in these cases. SMPS transformers run at high frequency.
Most of the cost savings (and space savings) in off-line power supplies result
from the smaller size of high frequency transformer compared to the 50/60 Hz
transformers formerly used. There are additional design tradeoffs.

The terminal voltage of a transformer is proportional to the product of the core


area, magnetic flux, and frequency. By using a much higher frequency, the core
area (and so the mass of the core) can be greatly reduced. However, core losses
increase at higher frequencies. Cores generally use ferrite material which has a
low loss at the high frequencies and high flux densities used. The laminated iron
cores of lower-frequency (<400 Hz) transformers would be unacceptably lossy
at switching frequencies of a few kilohertz. Also, more energy is lost during
transitions of the switching semiconductor at higher frequencies. Furthermore,
more attention to the physical layout of the circuit board is required as parasitics
become more significant, and the amount of electromagnetic interference will
be more pronounced.

Copper loss

At low frequencies (such as the line frequency of 50 or 60 Hz), designers can


usually ignore the skin effect. For these frequencies, the skin effect is only
significant when the conductors are large, more than 0.3 inches (7.6 mm) in
diameter.

Street light controller with vehicle sense and LDR Page 64


Switching power supplies must pay more attention to the skin effect because it
is a source of power loss. At 500 kHz, the skin depth in copper is about 0.003
inches (0.076 mm) – a dimension smaller than the typical wires used in a power
supply. The effective resistance of conductors increases, because current
concentrates near the surface of the conductor and the inner portion carries less
current than at low frequencies.

The skin effect is exacerbated by the harmonics present in the high speed PWM
switching waveforms. The appropriate skin depth is not just the depth at the
fundamental, but also the skin depths at the harmonics.[19]

In addition to the skin effect, there is also a proximity effect, which is another
source of power loss.

References:
1. Augarten, Stan (1983). The Most Widely Used Computer on a
Chip: The TMS 1000. State of the Art: A Photographic History of
the Integrated Circuit (New Haven and New York: Ticknor &
Fields). ISBN 0-89919-195-9. Retrieved 2009-12-23.
2. "Oral History Panel on the Development and Promotion of the
Intel 8048 Microcontroller" (PDF). Computer History Museum
Oral History, 2008. p. 4. Retrieved 2011-06-28.
3. "Atmel’s Self-Programming Flash Microcontrollers" (PDF).
2012-01-24. Retrieved 2008-10-25. by Odd Jostein Svendsli 2003
4. Jim Turley. "The Two Percent Solution" 2002.
5. Tom Cantrell "Microchip on the March". Circuit Cellar. 1998.
6. http://www.semico.com
7. Momentum Carries MCUs Into 2011
http://semico.com/content/momentum-carries-mcus-2011

Street light controller with vehicle sense and LDR Page 65


8. "MCU Market on Migration Path to 32-bit and ARM-based
Devices". April 25, 2013. It typically takes a global economic
recession to upset the diverse MCU marketplace, and that’s
exactly what occurred in 2009, when the microcontroller
business suffered its worst-ever annual sales decline of 22% to
$11.1 billion.
9. Bill Giovino. "Zilog Buys Microcontroller Product Lines from
Samsung". 2013.
10. http://www.mouser.com/ProductDetail/Silicon-
Labs/EFM8BB10F2G-A-QFN20.

Street light controller with vehicle sense and LDR Page 66

You might also like