You are on page 1of 52

Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 1



A Mini Project Report Entitled
On
AUTOMATIC ROOM LIGHT CONTROLLER WITH
SENSORS
A report Submitted in partial fulfillment of the
Academic requirements for the award of the degree of
BACHELOR OF TECHNOLOGY
in
ELECTRONICS AND COMMUNICATION ENGINEERING
by

P.BHASKAR (11QM1A0469)
T.SURESH (11QM1A0479)
S.PRAVEEN KUMAR (11QM1A0475)

Under the esteemed guidance of
P.ANUSHA,M.Tech.
Asst. Professor

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING



Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 2

KG REDDY COLLEGE OF ENGINEERING &
TECHNOLOGY
CHILKUR (V), MOINABAD (M), RANGA REDDY DISTRICT (A.P)
DEPARTMENT OF ELECTRONICS AND COMMUNICATION
ENGINEERING


CERTIFICATE
This is to certify that the Dissertation entitled AUTOMATIC ROOM
LIGHT CONTROLLER WITH SENSORS is a bonafide work done by
P.BHASKAR(11QM1A0469), T.SURESH(11QM1A0479), S.PRAVEEN
KUMAR (11QM1A0475). in partial fulfillment of the academic
requirements for the award of the degree of Bachelor of Technology in
ELECTRONICS AND COMMUNICATION ENGINEERING, submitted to the
Department of ECE, KG REDDY College of Engineering & Technology,
Hyderabad.



INTERNAL GUIDE HOD OF ECE
P.ANUSHA,M.Tech. Mr.M.N.NARSAIAH, M.Tech(Ph.D)
Asst. Professor Associate Professor




EXTERNAL EXAMINER
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 3

ACKNOWLEDGMENT

With great pleasure we want to take this opportunity to express my heart felt
gratitude to all the people who helped in making this project work a grand success.
We are very much thankful to Mr. Krishna Reddy. Honourable chairman for his help in
providing good facilities in our college
We are highly indebted to Dr.Madhusudan Nair, Principal KGRCET for giving
permission to carry out this project in KGRCET.
We would like to thank M.N.Narsaiah, Assoc. Professor Head of the Department of
Electronics & Communication Engineering, for his moral support throughout the
period of our study in KGRCET.
We are grateful to P.ANUSHA for her valuable suggestions and guidance during the
execution of this project work.
We are very much thankful to KGRCET for giving us this opportunity to do this project
in embedded systems. We express our deep sense of gratitude to P.ANUSHA for her
constant guidance throughout the course of project work.
Finally we would like to thank the Teaching & Non- teaching staff of Department of
Electronics & Communication Engineering, for their co-operation.






P.BHASKAR (11QM1A0469)

T.SURESH (11QM1A0479)

S.PRAVEEN KUMAR (11QM1A0475)









Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 4

CONTENTS
Abstract i

List of figures ii

List of tables iii

List of screens iv


CHAPTER NO. CHAPTER NAME PAGE NO.
1. INTRODUCTION
1.1 Abbreviation of Embedded systems 1
1.2 Examples and Embedded systems 2
1.3 Embedded C 2
1.4 Firmware 4
1.5 Operating systems 5


2. BLOCK DIAGRAM
2.1 Block diagram Explanation 6

3. HARDWARE REQUIREMENTS
3.1 Description of Microcontroller 9
3.2 Liquid Crystal Display 13
3.3 Relay switch 18
3.4 I R sensors 23


4. SOFTWARE DESCRIPTION
4.1 Keil Compiler 30
4.2 Pro Load 30
4.3 Procedural steps for Compilation
Simulation and Dumping 31
4.3.1 Compilation and simulation steps 31
4.3.2 Dumping steps 36
4.4 Program Code 37

5. RESULT
Result Analysis 40

Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 5

CONCLUSION 41

FUTURE SCOPE 42

REFERENCES 43







































Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 6

ABSTRACT
In the undertaken project we have designed a circuit that switches on and switches
off automatically whenever a person enters and leave the room respectively. The benefit
of this circuit is that after entering the room person will not have to search for the light
switch the light will automatically be turned on and need not to switch it off as the person
leave the room, the room light will be turned off automatically.
When an object moves into a room it will be detected by the IR sensor 1 this
makes the microcontroller to switch on the light using relay switch by understanding that
something has moved in to the room. if the last object moves out of the room it has
passes through IR sensor 2 and microcontroller will switch OFF the light using relay.
Low cost, Easy to use. can be implemented in single door, Can be used to automatic
room light control.
Main advantage of this project is that it helps in energy conservation. Because
when there is nobody inside the room then lights are turned off.
It is used only when one person cuts the rays of the sensor hence cannot be used when
two or more persons cross the door simultaneously.
When anybody is inside the room and we need to switch OFF the power then we
have to do it manually. So, in this case we fail to automatically control the light.


















Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 7

LIST OF FIGURES

FIGURE NO. FIGURE NAME PAGE NO.

1.1 Embedded system 1
2.1 Block diagram of project 6
2.2 Circuit diagram of power supply 7
3.1 Pin diagram of 8051 9
3.2 Block diagram of 8051 10
3.3 Lcd display 15
3.4 Lcd interfacing 18
3.5 Relay switch 19
3.6 Internal structure of relay 20
3.7 4 Pin relay 21
3.8 Energized relay 21
3.9 De-Energized relay 22
3.10 Circuit diagram of relay 22
3.11 Circuit diagram of transmitter 25
3.12 Receiver 26
3.13 TSOP 1738 27
3.14 Block diagram of TSOP 28











Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 8

LIST OF TABLES

TABLE NO. TABLE NAME PAGE NO.

3.1 Description of Port 3 10

3.2 Pin Description of Lcd 14

3.3 Lcd Command codes 15

























Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 9

LIST OF SCREENS

SCREEN NO. SCREEN NAME PAGE NO.

4.3 Open keil and start a new project 31

4.4 Opening a new project 32

4.4 ATMEL (source code) 32

4.5 Creating a new project 33

4.6 Save it with .c 33

4.6 Adding files to group 34

4.7 Rebuilding all targets 35

4.8 Debugging the program 36


















Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 10

CHAPTER 1
INTRODUCTION
1.1 EMBEDDED SYSTEM:
An embedded system is a special-purpose system in which the computer is
completely encapsulated by or dedicated to the device or system it controls. Unlike a
general-purpose computer, such as a personal computer, an embedded system performs
one or a few predefined tasks, usually with very specific requirements. Since the system
is dedicated to specific tasks, design engineers can optimize it, reducing the size and cost
of the product. Embedded systems are often mass-produced, benefiting from economies
of scale.
Personal digital assistants (PDAs) or handheld computers are generally considered
embedded devices because of the nature of their hardware design, even though they are
more expandable in software terms. This line of definition continues to blur as devices
expand. With the introduction of the OQO Model 2 with the Windows XP operating
system and ports such as a USB port both features usually belong to "general purpose
computers", the line of nomenclature blurs even more.
Physically, embedded systems ranges from portable devices such as digital
watches and MP3 players, to large stationary installations like traffic lights, factory
controllers, or the systems controlling nuclear power plants.
In terms of complexity embedded systems can range from very simple with a
single microcontroller chip, to very complex with multiple units, peripherals and
networks mounted inside a large chassis or enclosure.

Fig 1.1. Embedded system
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 11

1.2 Examples of Embedded Systems:
Avionics, such as inertial guidance systems, flight control hardware/software
and other integrated systems in aircraft and missiles
Cellular telephones and telephone switches
Engine controllers and antilock brake controllers for automobiles
Home automation products, such as thermostats,air conditioners, sprinklers, and
security monitoring systems.
Handheld calculators
Handheld computers
Household appliances, including microwave ovens, washing machines, television
sets, DVD players and recorders
Medical equipment
Personal digital assistant
Videogame consoles
Computer peripherals such as routers and printers.
Industrial controllers for remote machine operation.

1.3 What is an Embedded System?
An embedded system is an application that contains at least one programmable
computer and which is used by individuals who are, in the main, unaware that the system
is computer based.
Which Programming Language should you use?
Having decided to use an 8051 processor as the basis of your embedded system, the
next key decision that needs to be made is the choice of programming language. In order
to identify a suitable language for embedded systems, we might begin by making the
following observations.
Computers (such as microcontroller, microprocessor or DSP chips) only accept
instructions in machine code (object codes). Machine code is, by definition, in
the language of the computer, rather than that of the programmer. Interpretation of
the code by the programmer is difficult and error prone.
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 12

All software, whether in assembly, C, C++, Java or Ada must ultimately be
translated into machine code in order to be executed by the computer.
Embedded processors like the 8051 have limited processor power and very
limited memory available: the language used must be efficient.
The language chosen should be in common use.
Summary of C language Features:
It is mid-level, with high- level features (such as support for functions and
modules), and low- level features (such as good access to hardware via pointers).
It is very efficient.
It is popular and well understood.
Even desktop developers who have used only Java or C++ can soon understand C
syntax.
Good, well-proven compilers are available for every embedded processor (8-bit to
32-bit or more).
Basic C program structure:
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//Basic blank C program that does nothing
// Includes
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#include <reg51.h> // SFR declarations
Void main (void)
{
While (1);
{
Body of the loop // Infinite loop
}
} // match the braces


Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 13

1.4 FIRMWARE:
Firmware is a software program permanently etched into a hardware device such as a
keyboards, hard drive, BIOS, or video cards. It is programmed to give permanent
instructions to communicate with other devices and perform functions like basic
input/output tasks. Firmware is typically stored in the flash ROM (read only memory) of
a hardware device. It can be erased and rewritten.
Firmware was originally designed for high level software and could be changed
without having to exchange the hardware for a newer device. Firmware also retains the
basic instructions for hardware devices that make them operative. Without firmware, a
hardware device would be non- functional.
Originally, firmware had read-only memory (ROM) and programmable read-only
memory (PROM). It was designed to be permanent. Eventually PROM chips could be
updated and were called erasable programmable read-only memory (EPROM). But
EPROM was expensive, time consuming to update and challenging to use. Firmware
eventually evolved from ROM to flash memory firmware; thus, it became easier to
update and user friendly.
levels of firmware:
1. Low Level Firmware: This is found in ROM, OTP/PROM and PLA structures.
Low level firmware is often read-only memory and cannot be changed or updated.
It is sometimes referred to as hardware.
2. High Level Firmware: This is used in flash memory for updates that is often
considered as software.
3. Subsystems: These have their own fixed microcode embedded in flash chips,
CPUs and LCD units. A subsystem is usually considered part of the hardware
device as well as high level firmware.
BIOS, modems and video cards are usually easy to update. But firmware in storage
devices usually gets overlooked; there are no standardized systems for updating
firmware. Fortunately, storage devices do not need to be updated often.
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 14

1.5 OPERATING SYSTEM:
What is an operating system? An operating system (sometimes abbreviated as "OS")
is the program that, after being initially loaded into the computer by a boot program,
manages all the other programs in a computer. The other programs are called applications
or application programs. The application programs make use of the operating system by
making requests for services through a defined application program interface (API). In
addition, users can interact directly with the operating system through a user interface
such as a command language or a graphical user interface (GUI).
An operating system performs these services for applications:
In a multitasking operating system where multiple programs can be running at the same
time, the operating system determines which applications should run in what order and
how much time should be allowed for each application before giving another application
a turn.
It manages the sharing of internal memory among multiple applications.
It handles input and output to and from attached hardware devices, such as hard disks,
printers, and dial-up ports.
It sends messages to each application or interactive user (or to a system operator)
about the status of operation and any errors that may have occurred.
It can offload the management of what are called batch jobs (for example,
printing) so that the initiating application is freed from this work.
On computers that can provide parallel processing, an operating system can
manage how to divide the program so that it runs on more than one processor at a time.
All major computer platforms (hardware and software) require and sometimes
include an operating system. Linux, Windows, VMS, OS/400, AIX, and z/OS are all
examples of operating systems.


Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 15

CHAPTER 2
BLOCK DIAGRAM

In this Automatic room light controller with sensors project we have mainly
used hardware components like Relay switch, I R sensors, Lcd display and Tsop 1738.
And the automatic room light controller with sensors are explained with neat block
diagram as shown below.



Fig2.1. block diagram

2.1 Block Diagram Explanation:

In this section we will be discussing about the complete block diagram and
functional description of our project. And also brief description of each block in the block
diagram.
Micro controller:
In this project work the microcontroller is plays major role. Microcontroller were
originally used as components in complicated process-control systems. However, because
of their small size and low price, microcontrollers are now also being used in regulators
IR sensor
2
Receiver
2

Power Supply
IR sensor
1
Receiver
1







Micro
Controller

LCD Display

Relay
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 16

for individual control loops. In several areas microcontroller are now outperforming their
analog counterparts and are cheaper as well.
Power Supply
This section is meant for supplying Power to all the sections mentioned above. It
basically consists of a Transformer to step down the 230V ac to 12V ac followed by
diodes. Here diodes are used to rectify the ac to dc. After rectification the obtained
rippled dc is filtered using a capacitor Filter. A positive voltage regulator is used to
regulate the obtained dc voltage(5V).

Fig.2.2. circuit diagram of power supply
But here in this project two power supplies are used one is meant to supply
operating voltage for Microcontroller and the other is to supply control voltage for
Relays.
LCD Display Section:
This section is basically meant to show up the status of the project. This project
makes use of Liquid Crystal Display to display / prompt for necessary information.
Relay Switch:
Relay is a electrical to magnetic converting switch when input is high magnetic field is
produced switch is on otherwise switch is off.

Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 17

CHAPTER 3
HARDWARE REQUIREMENTS
3.1 AT89C51 MICROCONTROLLER
3.1.1 Features
AT89C51 based architecture
8-Kbytes of on-chip Reprogrammable Flash Memory
128 x 8 RAM
Two 16-bit Timer/Counters
Full duplex serial channel
Boolean processor
Four 8-bit I/O ports, 32 I/O lines
Memory addressing capability
64K ROM and 64K RAM
Power save modes:
Idle and power-down
Six interrupt sources
Most instructions execute in 0.3 us
CMOS and TTL compatible
Maximum speed: 40 MHz @ Vcc = 5V
Industrial temperature available
Packages available:
40-pin DIP
44-pin PLCC
44-pin PQFP
3.1.2 The Microcontroller:
A microcontroller is a general purpose device, but that is meant to read data,
perform limited calculations on that data and control its environment based on those
calculations. The prime use of a microcontroller is to control the operation of a machine
using a fixed program that is stored in ROM and that does not change over the lifetime of
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 18

the system. The microcontroller design uses a much more limited set of single and double
byte instructions that are used to move data and code from internal memory to the ALU.
The microcontroller is concerned with getting data from and to its own pins; the
architecture and instruction set are optimized to handle data in bit and byte size.
The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller
with 8Kbytes of Flash Programmable and erasable read only memory (EROM). The
device is manufactured using Atmels high-density nonvolatile memory technology and
is functionally compatible with the industry-standard 80C51 microcontroller instruction
set and pin out. By combining versatile 8-bit CPU with Flash on a monolithic chip, the
Atmels AT89c51 is a powerful microcomputer, which provides a high flexible and cost-
effective solution to many embedded control applications.
AT89C51 Block Diagram


Fig3.1. block diagram of 8051
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 19

3.1.4 Pin configuration of AT89c51 Microcontroller


Fig3.1.2. 8051 micro controller
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 20

3.1.5 Pin Description:
VCC
Supply voltage
GND
Ground
Port 0
Port 0 is an 8-bit open drain bi-directional I/O port. As an output port, each pin
can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as
high impedance inputs.
Port 0 can also be configured to be the multiplexed low order address/data bus
during access to external program and data memory. In this mode, P 0 has internal pull-
ups. Port 0 also receives the code bytes during Flash programming and outputs the code
bytes during program verification. External pull- ups are required during program
verification.
Port 1
Port 1 is an 8-bit bi-directional I/O port with internal pull- ups. The port 1output
buffers can sink/source four TTL inputs. When 1s are written to port 1 pins, they are
pulled high by the internal pull- ups can be used as inputs. As inputs, Port 1 pins that are
externally being pulled low will source current (1) because of the internal pull- ups.

Port 2
Port 2 is an 8-bit bi-directional I/O port with internal pull- ups. The port 2 output
buffers can sink/source four TTL inputs. When 1s are written to port 2 pins, they are
pulled high by the internal pull- ups can be used as inputs. As inputs, Port 2 pins that are
externally being pulled low will source current because of the internal pull- ups.
Port 2 emits the high-order address byte during fetches from external program
memory and during access to DPTR. In this application Port 2 uses strong internal pull-
ups when emitting 1s. During accesses to external data memory that use 8-bit data
address (MOVX@R1), Port 2 emits the contents of the P2 Special Function Register.
Port 2 also receives the high-order address bits and some control signals during Flash
programming and verification.
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 21

Port 3
Port 3 is an 8-bit bi-directional I/O port with internal pull- ups. The port 3 output
buffers can sink/source four TTL inputs. When 1s are written to port 3 pins, they are
pulled high by the internal pull- ups can be used as inputs. As inputs, Port 3 pins that are
externally being pulled low will source current because of the internal pull- ups.
Port 3 also receives some control signals for Flash Programming and verification.
TABLE 3.1 port 3 description.

Port pin Alternate Functions
P3.0 RXD(serial input port)
P3.1 TXD(serial input port)

P3.2 INT0(external interrupt 0)
P3.3 INT1(external interrupt 1)
P3.4 T0(timer 0 external input)
P3.5 T1(timer 1 external input)
P3.6 WR(external data memory write strobe)
P3.7 RD(external data memory read strobe)

RST
Rest input A on this pin for two machine cycles while the oscillator is running
resets the device.
ALE/PROG:
Address Latch Enable is an output pulse for latching the low byte of the address
during access to external memory. This pin is also the program pulse input (PROG)
during Flash programming.
In normal operation ALE is emitted at a constant rate of 1/16 the oscillator
frequency and may be used for external timing or clocking purpose. Note, however, that
one ALE pulse is skipped during each access to external Data memory.
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 22

PSEN
Program Store Enable is the read strobe to external program memory when the
AT89c51 is executing code from external program memory PSEN is activated twice each
machine cycle, except that two PSEN activations are skipped during each access to
external data memory.
__
EA /VPP
External Access Enable (EA) must be strapped to GND in order to enable the
device to fetch code from external program memory locations starting at 0000h up to
FFFFH. Note, however, that if lock bit 1 is programmed EA will be internally latched on
reset. EA should be strapped to Vcc for internal program executions. This pin also
receives the 12-volt programming enable voltage (Vpp) during Flash programming when
12-volt programming is selected.
XTAL1
Input to the inverting oscillator amplifier and input to the internal clock operating
circuit.
XTAL 2
Output from the inverting oscillator amplifier.
3.2 LIQUID CRYSTAL DISPLAY
Liquid crystal displays (LCD s) have materials which combine the properties of
both liquids and crystals. Rather than having a melting point, they have a temperature
range within which the molecules are almost as mobile as they would be in a liquid, but
are grouped together in an ordered form similar to a crystal.
An LCD consists of two glass panels, with the liquid crystal material sand
witched in between them. The inner surface of the glass plates are coated with transparent
electrodes which define the character, symbols or patterns to be displayed polymeric
layers are present in between the electrodes and the liquid crystal, which makes the liquid
crystal molecules to maintain a defined orientation angle.
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 23

One each polarisers are pasted outside the two glass panels. These polarisers
would rotate the light rays passing through them to a definite angle, in a particular
direction
When the LCD is in the off state, light rays are rotated by the two polarisers and
the liquid crystal, such that the light rays come out of the LCD without any orientation,
and hence the LCD appears transparent.
When sufficient voltage is applied to the electrodes, the liquid crystal molecules
would be aligned in a specific direction. The light rays passing through the LCD would
be rotated by the polarisers, which would result in activating / highlighting the desired
characters.
The LCDs are lightweight with only a few millimeters thickness. Since the
LCDs consume less power, they are compatible with low power electronic circuits, and
can be powered for long durations.
The LCD s wont generate light and so light is needed to read the display. By
using backlighting, reading is possible in the dark. The LCDs have long life and a wide
operating temperature range.
Changing the display size or the layout size is relatively simple which makes the
LCDs more customer friendly.
The LCD s used exclusively in watches, calculators and measuring instruments is
the simple seven-segment displays, having a limited amount of numeric data. The recent
advances in technology have resulted in better legibility, more information displaying
capability and a wider temperature range. These have resulted in the LCD s being
extensively used in telecommunications and entertainment electronics. The LCD s has
even started replacing the cathode ray tubes (CRTs) used for the display of text and
graphics, and also in small TV applications.
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 24


Fig3.3 Lcd display
LCD operation
In recent years the LCD is finding widespread use replacing LED s (seven-segment
LED or other multi segment LED s). This is due to the following reasons:
1. The declining prices of LCD s.
2. The ability to display numbers, characters and graphics. This is in
contract to LED s, which are limited to numbers and a few characters.
3. Incorporation of a refreshing controller into the LCD, there by relieving the CPU
of the task of refreshing the LCD. In the contrast, the LED must be refreshed by
the CPU to keep displaying the data.
4. Ease of programming for characters and graphics.
LCD pin description
The LCD discussed in this section has 14 pins. The function of each pin is given
in table.


Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 25

TABLE 3.2: Pin description for LCD:

Pin symbol I/O Description
1 Vss -- Ground
2 Vcc -- +5V power supply
3 VEE -- Power supply to
control contrast
4 RS I RS=0 to select
command register
RS=1 to select
data register
5 R/W I R/W=0 for write
R/W=1 for read
6 E I/O Enable
7 DB0 I/O The 8-bit data bus
8 DB1 I/O The 8-bit data bus
9 DB2 I/O The 8-bit data bus
10 DB3 I/O The 8-bit data bus
11 DB4 I/O The 8-bit data bus
12 DB5 I/O The 8-bit data bus
13 DB6 I/O The 8-bit data bus
14 DB7 I/O The 8-bit data bus


Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 26

TABLE 3.3: LCD Command Codes

Code
(hex)

Command to LCD Instruction
Register
1 Clear display screen
2 Return home
4 Decrement cursor
6 Increment cursor
5 Shift display right
7 Shift display left
8 Display off, cursor off
A Display off, cursor on
C Display on, cursor off
E Display on, cursor on
F Display on, cursor blinking
10 Shift cursor position to left
14 Shift cursor position to right
18 Shift the entire display to the left
1C Shift the entire display to the right
80 Force cursor to beginning of 1
st
line
C0 Force cursor to beginning of 2
nd
line
38 2 lines and 5x7 matrix

Uses:
The LCDs used exclusively in watches, calculators and measuring instruments are
the simple seven-segment displays, having a limited amount of numeric data. The recent
advances in technology have resulted in better legibility, more information displaying
capability and a wider temperature range. These have resulted in the LCDs being
extensively used in telecommunications and entertainment electronics. The LCDs have
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 27

even started replacing the cathode ray tubes (CRTs) used for the display of text and
graphics, and also in small TV applications.

Lcd Interfacing
Sending commands and data to LCDs with a time delay:

Fig 3.4. lcd interfacing

To send any command from table 2 to the LCD, make pin RS=0. For data, make
RS=1.Then place a high to low pulse on the E pin to enable the internal latch of the LCD.
3.3 RELAY SWITCH
A relay is an electrically operated switch. Many relays use an electromagnet to
mechanically operate a switch, but other operating principles are also used, such as solid
state relays - . Relays are used where it is necessary to control a circuit by a low-power
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 28

signal (with complete electrical isolation between control and controlled circuits), or
where several circuits must be controlled by one signal. The first relays were used in long
distance telegraph circuits as amplifiers . they repeated the signal coming in from one
circuit and re-transmitted it on another circuit.Relays were used extensively in telephone
exchanges and early computers to perform logical operations.
Ex: A relay is used to control the air conditioner in your home. The AC unit
probably runs off of 220VAC at around 30A. That's 6600 Watts! The coil that controls
the relay may only need a few watts to pull the contacts together.


Fig 3.5. relay switch
The internal structure of the relay is shown in the image above which is embedded
inside the plastic covering.

Relay switch shown in the image above consists of five terminals. Two terminals are
used to give the input DC voltage also known as the operating voltage of the
relay. Relays are available in different operating voltages like 6V, 12V, 24V etc. The rest
of the three terminals are used to connect the high voltage AC circuit. The terminals are
called Common, Normally Open (NO) and Normally Closed (NC). Relays are available
in various types & categories and in order to identify the correct configuration of the
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 29

output terminals, it is best to see the data sheet or manual. You can also identify the
terminals using a multimeter and at times it is printed on the relay itself.
Working
The working of a relay can be better understood by explaining the following
diagram given below.

Fig 3.6. internal structure
The diagram shows an inner section diagram of a relay. An iron core is
surrounded by a control coil. As shown, the power source is given to the electromagnet
through a control switch and through contacts to the load. When current starts flowing
through the control coil, the electromagnet starts energizing and thus intensifies the
magnetic field. Thus the upper contact arm starts to be attracted to the lower fixed arm
and thus closes the contacts causing a short circuit for the power to the load. On the other
hand, if the relay was already de-energized when the contacts were closed, then the
contact move oppositely and make an open circuit.
As soon as the coil current is off, the movable armature will be returned by a
force back to its initial position. This force will be almost equal to half the strength of the
magnetic force. This force is mainly provided by two factors. They are the spring and
also gravity.
Relays are mainly made for two basic operations. One is low voltage application
and the other is high voltage. For low voltage applications, more preference will be given
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 30

to reduce the noise of the whole circuit. For high voltage applications, they are mainly
designed to reduce a phenomenon called arcing.
Relay Basics
The basics for all the relays are the same. Take a look at a 4 pin relay shown
below. There are two colours shown. The green colour represents the control circuit and
the red colour represents the load circuit. A small control coil is connected onto the
control circuit. A switch is connected to the load. This switch is controlled by the coil in
the control circuit. Now let us take the different steps that occour in a relay.


Fig 3.7. 4 pin relay
Energized Relay (ON)
As shown in the circuit, the current flowing through the coils represented by pins
1 and 3 causes a magnetic field to be aroused. This magnetic field causes the closing of
the pins 2 and 4. Thus the switch plays an important role in the relay working. As it is
apart of the load circuit, it is used to control an electrical circuit that is connected to it.
Thus, when the relay in energized the current flow will be through the pins 2 and 4.


Fig 3.8. Energized relay
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 31

De Energized Relay (OFF)
As soon as the current flow stops through pins 1 and 3, the switch opens and thus
the open circuit prevents the current flow through pins 2 and 4. Thus the relay becomes
de-energized and thus in off position.

Fig 3.9. De-Energized relay
In simple, when a voltage is applied to pin 1, the electromagnet activates, causing
a magnetic field to be developed, which goes on to close the pins 2 and 4 causing a
closed circuit. When there is no voltage on pin 1, there will be no electromagnetic force
and thus no magnetic field. Thus the switches remain open.
BLOCK DIAGRAM:

Fig 3.10. circuit diagram of relay
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 32

Relay Applications
Relays are used to realize logic functions. They play a very important role in
providing safety critical logic.
Relays are used to provide time delay functions. They are used to time the delay
open and delay close of contacts.
Relays are used to control high voltage circuits with the help of low voltage
signals. Similarly they are used to control high current circuits with the help of low
current signals.
They are also used as protective relays. By this function all the faults during
transmission and reception can be detected and isolated.
3.4 I R SENSORS
An infrared sensor is an electronic instrument that is used to sense certain
characteristics of its surroundings by either emitting and/or detecting infrared radiation. It
is also capable of measuring heat of an object and detecting motion. Infrared waves are
not visible to the human eye.
In the electromagnetic spectrum, infrared radiation is the region having
wavelengths longer than visible light wavelengths, but shorter than microwaves. The
infrared region is approximately demarcated from 0.75 to 1000m. The wavelength
region from 0.75 to 3m is termed as near infrared, the region from 3 to 6m is termed
mid- infrared, and the region higher than 6m is termed as far infrared.
Infrared technology is found in many of our everyday products. For example, TV
has an IR detector for interpreting the signal from the remote control. Key benefits of
infrared sensors include low power requirements, simple circuitry, and their portable
feature.
Types of Infra-Red Sensors
Infra-red sensors are broadly classified into two types:
Thermal infrared sensors These use infrared energy as heat. Their photo
sensitivity is independent of wavelength. Thermal detectors do not require cooling;
however, they have slow response times and low detection capability.
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 33

Quantum infrared sensors These provide higher detection performance and
faster response speed. Their photo sensitivity is dependent on wavelength. Quantum
detectors have to be cooled so as to obtain accurate measurements. The only exception is
for detectors that are used in the near infrared region.
Working Principle
A typical system for detecting infrared radiation using infrared sensors includes
the infrared source such as blackbody radiators, tungsten lamps, and silicon carbide. In
case of active IR sensors, the sources are infrared lasers and LEDs of specific IR
wavelengths. Next is the transmission medium used for infrared transmission, which
includes vacuum, the atmosphere, and optical fibers.
Thirdly, optical components such as optical lenses made from quartz, CaF
2
, Ge
and Si, polyethylene Fresnel lenses, and Al or Au mirrors, are used to converge or focus
infrared radiation. Likewise, to limit spectral response, band-pass filters are ideal.
Finally, the infrared detector completes the system for detecting infrared radiation. The
output from the detector is usually very small, and hence pre-amplifiers coupled with
circuitry are added to further process the received signals.
Applications
* The following are the key application areas of infrared sensors:
* Tracking and art history
* Climatology, meteorology, and astronomy
* Thermography, communications, and alcohol testing
* Heating, hyperspectral imaging, and night vision
* Biological systems, photobiomodulation, and plant health
* Gas detectors/gas leak detection
* Water and steel analysis, flame detection
* Anesthesiology testing and spectroscopy
* Petroleum exploration and underground solution
* Rail safety.

Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 34

A ) TRANSMITTER
IR Transmitter and Receiver pair can be easily made using 555 Timer, IR LED
and TSOP1738 IR Receiver. This can be used for remote controls, burglar alarms etc.
TSOP1738 is a very commonly used IR receiver for PCM remote control systems. It has
only 3 pins, Vcc, GND and Output. It can be powered using a 5V power supply and its
active low output can be directly connected to a microcontroller or microprocessor. It has
high immunity against ambient light and other electrical disturbances. It is able to transfer
data up to 2400 bits per second. The PCM carrier frequency of TSOP1738 is 38KHz, so
we want to design a astable multivibrator of 38KHz. This can be done by using 555
Timer. and TSOP1738 IR Receiver. This can be used for remote controls, burglar alarms
etc. TSOP1738 is a very commonly used IR receiver for PCM remote control systems. It
has only 3 pins, Vcc, GND and Output. It can be powered using a 5V power supply and
its active low output can be directly connected to a microcontroller or microprocessor. It
has high immunity against ambient light and other electrical disturbances. It is able to
transfer data up to 2400 bits per second. The PCM carrier frequency of TSOP1738 is
38KHz, so we want to design a astable multivibrator of 38KHz. This can be done by
using 555 Timer.
Circuit Diagram of Transmitter

Fig 3.11. circuit diagram of transmitter
In the above circuit, 555 Timer is wired as an Astable Multivibrator. The 100F
capacitor (C1) is used to reduce ripples in the power supply. 1
st
and 8
t h
pins of 555 are
used to give power Vcc and GND respectively. 4
t h
pin is the reset pin which is active low
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 35

input, hence it is connected to Vcc. 5
t h
pin is the Control Voltage pin which is not used in
this application, hence it is grounded via a capacitor to avoid high frequency noises
through that pin. Capacitor C2, Resistors R1, R2 determines the time period of
oscillation. Capacitor C2 charges to Vcc via resistors R1 and R2. It discharges through
Resistor R2 and 7
t h
pin of 555. The voltage across capacitor C2 is connected to the
internal comparators via 2
nd
and 6
t h
pins of 555. Output is taken from the 3
ed
pin of the
IC. Please read the article Astable Multivibrator using 555 Timer for more detailed
working. Charging time constant of the capacitor (output HIGH period) is determined by
the expression 0.693(R1+R2)C2 and discharging time constant (output LOW period) is
determined by 0.693R2C2. They are approximately equal.
B) RECEIVER

Fig 3.12. receiver
For receiving signals send by the transmitter you need only TSOP1738. Connect 5V to
Vs and Ground to GND pin of TSOP1738. The output will be active low. Output of
TSOP1738 will be HIGH when no signals fall on it and the output will be LOW when
38KHz infrared rays fall on it.
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 36

3.4.1 TSOP1738
The TSOP 1738 is a member of IR remote control receiver series. This IR sensor
module consists of a PIN diode and a pre amplifier which are embedded into a single
package. The output of TSOP is active low and it gives +5V in off state. When IR waves,
from a source, with a centre frequency of 38 kHz incident on it, its output goes low.
Lights coming from sunlight, fluorescent lamps etc. may cause disturbance to it and
result in undesirable output even when the source is not transmitting IR signals. A
bandpass filter, an integrator stage and an automatic gain control are used to suppress
such disturbances.

Fig 3.13. tsop
TSOP module has an inbuilt control circuit for amplifying the coded pulses from
the IR transmitter. A signal is generated when PIN photodiode receives the signals. This
input signal is received control (AGC). For a range of inputs, the output is fed back to
AGC in order to adjust the gain to a suitable level. The signal from AGC is passed to a
band pass filter to filter undesired frequencies. After this, the signal goes to a
demodulator and this demodulated output drives an npn transistor. The collector output of
the transistor is obtained at pin 3 of TSOP module.
Members of TSOP17xx series are sensitive to different centre frequencies of the
IR spectrum. For example TSOP1738 is sensitive to 38 kHz whereasTSOP1740 to 40
kHz centre frequency.y an automatic gain
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 37

AVAILABLE TYPES FOR DIFFERENT CARRIER FREQUENCIES
TSOP1730 30 KHZ
TSOP1733 33 KHZ
TSOP1736 36 KHZ
TSOP1737 36.7 KHZ
TSOP1738 38 KHZ
TSOP1740 40 KHZ
TSOP1756 56 KHZ
BLOCK DIAGRAM OF TSOP1738

Fig 3.14.block diagram of tsop
3.4.2 FEATURES OF TSOP1738
* Photo detector and preamplifier in one package
* Internal filter for PCM frequency
* Improved shielding against electrical
* field disturbance
* TTL and CMOS compatibility
* Output active low
* Low power consumption
* High immunity against ambient light
* Continuous data transmission possible
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 38

(1200 bit/s)
*Suitable burst length 10 cycles/burst
ADVANTAGES AND FUTURE SCOPES
* It can be used in our homes because we often forget to switch off our room lights
* It helps in energy conservation
* In future , we can send this data to remote areas using mobile or internet
* Voice alarm system can be used to indicate that room is full & person cant enter inside
* It can be used in various rooms like seminar halls , where the capacity of the room is
limited and should not be exceeded.
















Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 39

CHAPTER 4
SOFTWARE DESCRIPTION
This project is implemented using following softwares:
KEIL Compiler- for compilation part
Proload-for simulation part
4.1 KEIL Compiler:
Keil compiler is software used where the machine language code is written and
compiled. After compilation, the machine source code is converted into hex code which
is to be dumped into the microcontroller for further processing. Keil compiler also
supports C language code.
Its important that you know C language for microcontroller which is
commonly known as Embedded C. As we are going to use Keil C51 Compiler, hence we
also call it Keil C.
Keil C is not much different from a normal C program. If you know assembly,
writing a C program is not a crisis. In keil, we will have a main function, in which all
your application specific work will be defined. In case of embedded C, you do not have
any operating system running in there. So you have to make sure that your program or
main file should never exit. This can be done with the help of simple while (1) or for (;;)
loop as they are going to run infinitely.
We have to add header file for controller you are using, otherwise you will not
be able to access registers related to peripherals.
#include <REG51.h> //header file for 89C51
4.2 Proload:
Proload is software which accepts only hex files. Once the machine code is
converted into hex code, that hex code has to be dumped into the microcontroller and this
is done by the Proload. Proload is a programmer which itself contains a microcontroller
in it other than the one which is to be programmed.
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 40

This microcontroller has a program in it written in such a way that it accepts
the hex file from the Kiel compiler and dumps this hex file into the microcontroller which
is to be programmed. As the proload programmer kit requires power supply to be
operated, this power supply is given from the power supply circuit designed above. It
should be noted that this programmer kit contains a power supply section in the board
itself but in order to switch on that power supply, a source is required. Thus this is
accomplished from the power supply board with an output of 12volts or from an adapter
connected to 230V AC.
4.3 Procedural steps for compilation, simulation and dumping:
4.3.1 Compilation and simulation steps:
To create a project, write and test the previous example source code, follow
the following steps:
1. Open Keil and start a new project.

Fig 4.3: Step-1
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 41

2. You will be prompted to choose a name for your new project, Create a separate folder
where all the files of your project will be stored, choose a name and click save. The
following window will appear where you will be asked to select a device for Target
'Target 1'
3. From the list at the left, seek for the brand name ATMEL, then under ATMEL, select
AT89S52. You will notice that a brief description of the device appears on the right.
Leave the two upper check boxes unchecked and click OK. The AT89S52 will be called
your 'Target device', which is the final destination of your source code. You will be asked
whether to 'copy standard 8051 startup code' click No.


Fig 4.4: Step-2, 3
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 42

4. Click File, New, and something similar to the following window should appear. The
box named 'Text1' is where your code should be written later.


Fig 4.5: Step-4
5. Now you have to click 'File, Save as' and choose a file name for your source code
ending with the letter '.c'. You can name as 'code.c' for example and click save. Then
you have to add this file to your project work space at the left as shown in the
following.
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 43

6.After right-clicking on 'source group 1', click on 'Add files to group...', then you will
be prompted to browse the file to add to 'source group 1', choose the file that you just
saved, eventually 'code.c' and add it to the source group.
You will notice that the file is added to the project tree at the left.

Fig4.6: Step-5, 6
7. In some versions of this software you have to turn ON manually the option to generate
HEX files. make sure it is turned ON, by right-clicking on target 1, Options for target
'target 1', then under the 'output' tab, by checking the box 'generate HEX file'. This step
is very important as the HEX file is the compiled output of your project that is going to
be transferred to the microcontroller.
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 44

8. You can then start to write the source code in the window titled 'code.c' then before
testing your source code; you have to compile your source code, and correct eventual
syntax errors. In KEIL IDE, this step is called ' rebuild all targets' and has this icon: .

Fig 4.7: Step-7
9. If after rebuilding the targets, the 'output window' shows that there is 0 errors, then
you are ready to test the performance of your code. In keil, like in most development
environment, this step is called Debugging, and has this icon: . After clicking on the
debug icon, you will notice that some part of the user interface will change; some new
icons will appear, like the run icon circled in the following figure:

Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 45


Fig 4.8: Step-8

10. Select the ports and click on the RUN Option. It will end up the compilation and
simulation processes.
4.3.2 Dumping steps:
After designing the project using Keil Compiler, to observe the output, the
program should be dumped in microcontroller of your project using a dumper and the
procedure for dumping is as follows:
1. Install the Proload Software in the PC.
2. Now connect the Programmer kit to the PC (CPU) through serial cable.
3. Power up the programmer kit from the ac supply through adapter.
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 46

4. Now place the microcontroller in the GIF socket provided in the Programmer kit.
5. Click on the proload icon in the PC. A window appears providing the information like
Hardware model, com port, device type, Flash size etc. Click on browse option to select
the hex file to be dumped into the microcontroller and then click on Auto program to
program the microcontroller with that particular hex file.
6. The status of the microcontroller can be seen in the small status window in the bottom
of the page.
7. After this process is completed, remove the microcontroller from the programmer kit
and place it in your system board. Now the system board behaves according to the
program written in the microcontroller.
4.4 PROGRAM CODE
#include<reg51.h>
#define LCD P2
sbit rs=P1^0;
sbit rw=P1^1;
sbit en=P1^2;
sbit Ir1=P1^3;
sbit Ir2=P1^4;
sbit relay=P1^5;
void delay();
void lcdcmnd(unsigned char);
void lcddata(unsigned char);
void main()
{
unsigned char E[]="bulb is on", M[]="bulb is off";
unsigned char lcmd[]={0x38,0x01,0x0E,0x06,0x80};
unsigned int i,z;
for(i=0;i<5;i++)
{
LCD=lcmd[i];
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 47

rs=0;
rw=0;
en=1;
delay();
en=0;
}
while(1)
{
lcdcmnd(0x01);
delay();
lcdcmnd(0x0C);
delay();
z=0;
for(i=0;i<1000;i++)
{
if(Ir1==1&&Ir2==0);
{
Relay=1;
for(i=0;i<10;i++)
{
lcddata(E[i]);
}
++z;
}
Else if(Ir1==0&&Ir2==1)
{
--z;
}
}
if(z==0)
{
Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 48

lcdcmnd(0x01);
Relay=0;
for(i=0;i<11;i++)
{
lcddata(M[i]);
}
}
}
}
void delay()
{
int i;
for(i=0;i<1000;i++);
}















Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 49

CHAPTER 5
RESULT
RESULT ANALYSIS:
When an object moves into a room it will be detected by the IR sensor 1 this
makes the microcontroller to switch on the light using relay switch by
understanding that something has moved in to the room. if the last object moves
out of the room it has passes through IR sensor 2 and microcontroller will
switch OFF the light using relay.
Low cost, Easy to use. can be implemented in single door, Can be used to
automatic room light control.
Main advantage of this project is that it helps in energy conservation. Because
when there is nobody inside the room then lights are turned off.














Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 50

CONCLUSION
The goal of this project is to develop a system, which used to save power
automatically.
This project mainly consists of microcontroller (89C51) and LCD which helps the
project to be cost effective.
Even though the project was completed successfully but during the development
some obstructions were faced like for loose connection we have got some erroneous
output. Also due to some internal problem in the equipment we have not got desirable
output. So, for better output or for better display we have to be very careful while doing
the project.
During the project it has also been noticed that It is used only when one person
cuts the rays of the sensor hence cannot be used when two or more persons cross the door
simultaneously.













Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 51

FUTURE SCOPE
Sensors can acts as alarm for security purpose. Mainly used for power
consumption.It can be used in our homes because we often forget to switch off our room
lights It helps in energy conservation In future, we can send this data to remote areas
using mobile or internet Voice alarm system can be used to indicate that room is full &
person cant enter inside It can be used in various rooms like seminar halls, where the
capacity of the room is limited and should not be exceeded.


















Automatic room light controller with sensors

ELECTRONICS & COMMUNICATION ENGG.(KGRCET) Page 52

REFERENCES
Muhammad Ali Mazidi- THE 8051 MICROCONTROLLER AND EMBEDDED
SYSTEMS, Pearson.
Ayala- INTRODUCTION TO 8051 MICROCONTROLLER.
www.microcontroller8051.com
www.miniproject.com
www.howstuffworks.com
www.instructables.com/id/cellphone-operated-robot/
www.dnatechindia.com
www.answers.com

You might also like