AUDITORIUM CONTROLLER
ABSTRACT:
The work on Development of automatic person detection system to control electrical
fan and lights using PIC Microcontroller is a reliable circuit that takes over the task of
controlling the room lights in auditorium very accurately. When somebody enters into the
auditorium then the light in the auditorium will be switched ON and count also incremented by
one when any one leaves the room then count will be decremented by one. If the total count will
be zero, the light will be automatically switched OFF. The PIC microcontroller does the above
job. It receives the signals from the sensors, and this signal is operated under the control of
software which is stored in ROM. Pic Microcontroller 16F887A continuously monitor the
sensors, A IR Sensor is which controls the switching on/off of the light when it detects the any
person entered into the auditorium. The implementation is made simpler by using sensor to
detect person. The system includes IR sensor, microcontroller, LCD display and a 5v power is
supplied to run the system. The system uses a compact circuitry built around pic microcontroller
programs are developed in Embedded C. Flash magic is used for loading programs into
Microcontroller.
EXISTING SYSTEM:
In this existing system, manually controls the Fans, lights in the auditorium. Only the
human can controls Fans, lights in the auditorium. It is quite difficult to switch ON/OFF the fans
lights in each time when the number of people increases in the auditorium.
PROPOSED SYSTEM:
We are proposing to save the power consumption in electrical equipment like fan and
light. It can be also use for the security system in auditorium. This work is in two parts room
light control and automatic fan regulation
BLOCK DIAGRAM:
POWER SUPPLY
LCD DISPLAY
IR SENSOR IN
PIC16F877A
MICRO CONTROLLER
RELAY
LIGHTS
RELAY
FANS
IR SENSOR OUT
HARDWARE REQUIREMENTS:
IR SENSOR
MICROCONTROLLER
POWER SUPPLY UNIT
LCD DISPLAY
DC FAN
LIGHT
SOFTWARE REQUIREMENTS:
EMBEDDED C LANGUAGE
MPLAB IDE
ADVANTAGES:
APPLICATIONS:
Seminar halls
Auditorium
Colleges, Schools
Industries
The power supply section is the important one. It should deliver constant
output regulated power supply for successful working of the project. A 012V/1 mA transformer is used for this purpose. The primary of this
transformer is connected in to main supply through on/off switch& fuse for
protecting from overload and short circuit protection. The secondary is
connected to the diodes to convert 12V AC to 12V DC voltage. And filtered by
the capacitors, which is further regulated to +5v, by using IC 7805
SPI, UART for interfacing with other peripherals. PIC mainly used modified Harvard architecture and also
supports RISC (Reduced Instruction Set Computer) by the above specification RISC and Harvard we can
easily that PIC is faster than the 8051 based controller which is made-up of Von-Newman architecture.
PIC 16F877
Features of PIC16F877
The PIC16FXX series has more advanced and developed features when compared to its previous series. The
important features of PIC16F877 series is given below.
General Features
o High performance RISC CPU.
o ONLY 35 simple word instructions.
o All single cycle instructions except for program branches which are two cycles.
o Operating speed: clock input (200MHz), instruction cycle (200nS).
o Up to 3688bit of RAM (data memory), 2568 of EEPROM (data memory), 8k14 of flash memory.
o Pin out compatible to PIC 16C74B, PIC 16C76, PIC 16C77.
o Eight level deep hardware stack.
o Interrupt capability (up to 14 sources).
o Different types of addressing modes (direct, Indirect, relative addressing modes).
o Power on Reset (POR).
o Power-Up Timer (PWRT) and oscillator start-up timer.
o Low power- high speed CMOS flash/EEPROM.
o Fully static design.
o Wide operating voltage range (2.0 5.56)volts.
o High sink/source current (25mA).
o Commercial, industrial and extended temperature ranges.
o Low power consumption (<0.6mA typical @3v-4MHz, 20A typical @3v-32MHz and <1 A typical standby).
Peripheral Features
o Timer 0: 8 bit timer/counter with pre-scalar.
o Timer 1:16 bit timer/counter with pre-scalar.
o Timer 2: 8 bit timer/counter with 8 bit period registers with pre-scalar and post-scalar.
o Two Capture (16bit/12.5nS), Compare (16 bit/200nS), Pulse Width Modules (10bit).
Key Features
o Maximum operating frequency is 20MHz.
o Flash program memory (14 bit words), 8KB.
o Data memory (bytes) is 368.
o EEPROM data memory (bytes) is 256.
o 5 input/output ports.
o 3 timers.
o 2 CCP modules.
o 2 serial communication ports (MSSP, USART).
o PSP parallel communication port
o 10bit A/D module (8 channels)
Analog Features
o 10bit, up to 8 channel A/D converter.
o Brown Out Reset function.
o Analog comparator module.
Special Features
o 100000 times erase/write cycle enhanced memory.
o 1000000 times erase/write cycle data EEPROM memory.
o Self programmable under software control.
o In-circuit serial programming and in-circuit debugging capability.
o Single 5V,DC supply for circuit serial programming
o WDT with its own RC oscillator for reliable operation.
o Programmable code protection.
o Power saving sleep modes.
o Selectable oscillator options.
Pin Diagrams
PIC16F877 chip is available in different types of packages. According to the type of applications and usage,
these packages are differentiated. The pin diagrams of a PIC16F877 chip in different packages is shown in the
figure below.
Input/output ports
PIC16F877 has 5 basic input/output ports. They are usually denoted by PORT A (R A), PORT B (RB), PORT C
(RC), PORT D (RD), and PORT E (RE). These ports are used for input/ output interfacing. In this controller,
PORT A is only 6 bits wide (RA-0 to RA-7), PORT B , PORT C,PORT D are only 8 bits wide (RB-0 to RB7,RC-0 to RC-7,RD-0 to RD-7), PORT E has only 3 bit wide (RE-0 to RE-7).
PORT-A
RA-0 to RA-5
6 bit wide
PORT-B
RB-0 to RB-7
8 bit wide
PORT-C
RC-0 to RC-7
8 bit wide
PORT-D
RD-0 to RD-7
8 bit wide
PORT-E
RE-0 to RE-2
3 bit wid
All these ports are bi-directional. The direction of the port is controlled by using TRIS(X) registers (TRIS A used
to set the direction of PORT-A, TRIS B used to set the direction for PORT-B, etc.). Setting a TRIS(X) bit 1 will
set the corresponding PORT(X) bit as input. Clearing a TRIS(X) bit 0 will set the corresponding PORT(X) bit as
output.
(If we want to set PORT A as an input, just set TRIS(A) bit to logical 1 and want to set PORT B as an output,
just set the PORT B bits to logical 0.)
o Analog input port (AN0 TO AN7) : these ports are used for interfacing analog inputs.
o TX and RX: These are the USART transmission and reception ports.
o SCK: these pins are used for giving synchronous serial clock input.
o SCL: these pins act as an output for both SPI and I2C modes.
o DT: these are synchronous data terminals.
o CK: synchronous clock input.
o SD0: SPI data output (SPI Mode).
o SD1: SPI Data input (SPI mode).
o SDA: data input/output in I2C Mode.
o CCP1 and CCP2: these are capture/compare/PWM modules.
The PIC microcontroller architecture comprises of CPU, I/O ports, memory organization, A/D
converter, timers/counters, interrupts, serial communication, oscillator and CCP module which
are discussed in detailed below.
These registers are used for general purpose only as the name implies. For example, if we want
to multiply two numbers by using the PIC microcontroller. Generally, we use registers for
multiplying and storing the numbers in other registers. So these registers dont have any special
function,- CPU can easily access the data in the registers.
These registers are used for special purposes only as the name SFR implies. These registers
will perform according to the functions assigned to them , and they cannot be used as normal
registers. For example, if you cannot use the STATUS register for storing the data, these
registers are used for showing the operation or status of the program. So, user cannot change
the function of the SFR; the function is given by the retailer at the time of manufacturing.
Memory Organization
Read Only Memory (ROM)
Read only memory is a stable memory which is used to store the data permanently. In
PICmicrocontroller architecture, the architecture ROM stores the instructions or program,
according to the program the microcontroller acts. The ROM is also called as program memory,
wherein the user will write the program for microcontroller and saves it permanently, and finally
the program is executed by the CPU. The microcontrollers performance depends on the
instruction, which is executed by the CPU.
The series of PIC16 consists of five ports such as Port A, Port B, Port C, Port D & Port
E.
Port A is an 16-bit port that can be used as input or output port based on the status of
the TRISA (Tradoc Intelligence Support Activity) register.
Port B is an 8- bit port that can be used as both input and output port.
Port C is an 8-bit and the input of output operation is decided by the status of the TRISC
register.
Port D is an 8-bit port acts as a slave port for connection to the microprocessor BUS.
Port E is a 3-bit port which serves the additional function of the control signals to the
analog to digital converter.
BUS
BUS is used to transfer and receive the data from one peripheral to another. It is classified into
two types such as data bus and address.
Data Bus: It is used for only transfer or receive the data.
Address Bus: Address bus is used to transmit the memory address from the peripherals to the
CPU. I/O pins are used to interface the external peripherals; UART and USART both are serial
communication protocols which are used for interfacing serial devices like GSM, GPS,
Bluetooth, IR , etc.
BUS
A/D converters
The main intention of this analog to digital converter is to convert analog voltage values to digital
voltage values. A/D module of PIC microcontroller consists of 5 inputs for 28 pin devices and 8
inputs for 40 pin devices. The operation of the analog to digital converter is controlled by
ADCON0 and ADCON1 special registers. The upper bits of the converter are stored in register
ADRESH and lower bits of the converter are stored in register ADRESL. For this operation, it
requires 5V of an analog reference voltage.
A/D CONVERTER
Timers/ Counters
PIC microcontroller has four timer/counters wherein the one 8-bit timer and the remaining timers
have the choice to select 8 or 16-bit mode. Timers are used for generating accuracy actions, for
example, creating specific time delays between two operations.
Interrupts
PIC microcontroller consists of 20 internal interrupts and three external interrupt sources which
are associated with different peripherals like ADC, USART, Timers, and so on.
Serial Communication
Serial communication is the method of transferring data one bit at a time sequentially over
a communicationchannel.
USART: The name USART stands for Universal synchronous and Asynchronous
Receiver and Transmitter which is a serial communication for two protocols. It is used for
transmitting and receiving the data bit by bit over a single wire with respect to clock
pulses. The PIC microcontroller has two pins TXD and RXD. These pins are used for
transmitting and receiving the data serially.
SPI Protocol: The term SPI stands for Serial Peripheral Interface. This protocol is used
to send data between PIC microcontroller and other peripherals such as SD
cards, sensors and
shift
registers.
three
wire
SPI
communications between two devices on a common clock source. The data rate of SPI
protocol is more than that of the USART.
I2C Protocol: The term I2C stands for Inter Integrated Circuit , and it is a serial protocol
which is used to connect low speed devices such as EEPROMS,microcontrollers, A/D
converters, etc. PIC microcontroller support two wire Interface or I2C communication
between two devices which can work as both Master and Slave device.
Serial Communication
Oscillators
Oscillators are used for timing generation. Pic microcontroller consist of external oscillators like
RC oscillators or crystal oscillators. Where the crystal oscillator is connected between the two
oscillator pins. The value of the capacitor is connected to every pin that decides the mode of the
operation of the oscillator. The modes are crystal mode, high-speed mode and the low-power
mode. In case of RC oscillators, the value of the resistor & capacitor determine the clock
frequency and the range of clock frequency is 30KHz to 4MHz.
CCP module
The name CCP module stands for capture/compare/PWM where it works in three modes such
as capture mode, compare mode and PWM mode.
Capture Mode: Capture mode captures the time of arrival of a signal, or in other words,
when the CCP pin goes high, it captures the value of the Timer1.
Compare Mode: Compare mode acts as an analog comparator. When the timer1 value
reaches a certain reference value, then it generates an output.
PWM Mode: PWM mode provides pulse width modulated output with a 10-bit resolution
and programmable duty cycle.
PIC microcontrollers are consistent and faulty of PIC percentage is very less. The
performance of the PIC microcontroller is very fast because of using RISC architecture.
LCD
LCD Introduction
An HD44780 Character LCD is an industry standard liquid crystal display (LCD) display
device designed for interfacing with embedded electronics. These screens come in common
configurations of 8x1 characters, 16x2, and 20x4 among others. The largest such configuration is
40x4 characters, but these are rare and are actually two separate 20x4 screens seamlessly joined
together.
These screens are often found in copiers, fax machines, laser printers, industrial test equipment,
networking equipment such as routers and storage devices, etc. These are not the kind of screens
one would find in a cell phone, portable television, etc. They are limited to text only, with 8
customizable characters.
Character LCDs can come with or without backlights. Backlights can be LED, fluorescent, or
electroluminescent.
Character LCDs use a standard 14-pin interface. If the screen has a backlight, it will have 16
pins. The pinouts are as follows:
1. Ground
2. VCC (+5V)
3. Contrast adjustment
4. Register Select (R/S)
5. Read/Write (R/W)
6. Clock (Enable)
7. Bit 0
8. Bit 1
9. Bit 2
10.Bit 3
11.Bit 4
12.Bit 5
13.Bit 6
14.Bit 7
Character LCDs can operate in 4-bit or 8-bit mode. In 4 bit mode, pins 7 through 10 are unused
and the entire byte is sent to the screen using pins 11 through 14 by sending a nybble at a time.
The most commonly used LCDs found in the market today are 1 Line, 2 Line or 4 Line LCDs
which have only one controller and support at most 80 characters, whereas LCDs supporting
more than 80 characters make use of 2 HD44780 controllers. Apart from displaying some simple
static characters you can create animated text scripts and a lot more!
Lets start playing with them, but you will have to wait a little as these things mentioned below
will help you to create your own magical codes
Most LCDs with 1 controller has 14 Pins and 16 Pins (two extra pins are for back-light LED
connections). Pin description is shown in the table below. (We may also have 16 pins in 2
controllers, refer to the datasheet for exact details).
This may not match with the exact pin configuration for your LCD, check application circuit in
datasheet for exact configuration.
We will discuss here 8 bit mode first (that is data transfer through all the 8 data pins), 4 bit mode
will be discussed later on.
Read/Write (RW):
1.) RW= 0, the information is being written on LCD.
2.) RW=1, for reading from LCD. (Only one command that is Get LCD status is read
commands all others are write command)
It is a control line. When RW is low (0), the information on the data bus is being written to the
LCD. When RW is high (1), the program is effectively querying (or reading from) the LCD.
Only one instruction ("Get LCD status") is a read command. All others are write commands--so
RW will be low for majority of the time.
Registers:
There are two very important registers in the LCD. The RS pin is used for their selection.
1.) RS= 0; The Instruction command code register, allows the user to send command such as
clear display, cursor at home, etc.
2.) RS=1; the data register, allow user to send data to be displayed at LCD.
Enable (En) pin: is used to tell the LCD that we are sending it data. A high to low pulse (of
minimum length 450ns) before sending any command/data to LCD.
Display data RAM (DDRAM) stores display data represented in 8-bit character codes. Its
extended capacity is 80 X 8 bits, or 80 characters. The area in display data RAM (DDRAM) that
is not used for display can be used as general data RAM. So whatever you send on the DDRAM
is actually displayed on the LCD.
{For LCDs like 1x16, only 16 characters are visible, so whatever you write after 16 chars is
written in DDRAM but is not visible to the user.}
The answer is CGROM i.e. character generator ROM, is used to convert ASCII values send by
C into 5 x 8 dot or 5 x 10 dot character patterns from 8-bit character. (You can also add your
own characters in the list!!)
The first method is to create a delay between two consecutive commands or instructions.
(Check the datasheet for exact time of execution of an instruction). This may not be very
appropriate as the delay is not very accurate.
BUSY FLAG (BF): The MSB of the LCD data bus (D7) act as busy flag. When BF = 1
means LCD is busy and will not accept next command or data and BF = 0 means LCD is
ready for the next command or data to process. This flag is internally set by LCD & can
be monitored by C for exact amount of delay.
STEPS TO PROGRAM:
1) Initialize the LCD.
2) Select the command or instruction register.
3) Set RW low (to write).
4) Send a high to low pulse on Enable pin.
The LCD standard requires 3 control lines and 8 I/O lines for the data bus.
8 data pins D7:D0
Bi-directional data/command pins.
Alphanumeric characters are sent in ASCII format.
RS: Register Select
RS = 0 -> Command Register is selected
RS = 1 -> Data Register is selected
R/W: Read or Write
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.
Faster response
Easy pattern measurements
Flame Monitors
These types of devices are used for detecting the light emitted from the flames and to
monitor how the flames are burning. The Light emitted from flames extend from UV to IR
region types. PbS, PbSe, Two-color detector, pyro electric detector are some of the commonly
employed detector used in flame monitors.
Moisture Analyzers
Moisture analyzers use wavelengths which are absorbed by the moisture in the IR region.
Objects are irradiated with light having these wavelengths(1.1 m, 1.4 m, 1.9 m, and 2.7m)
and also with reference wavelengths. The Lights reflected from the objects depend upon the
moisture content and is detected by analyzer to measure moisture (ratio of reflected light at these
wavelengths to the reflected light at reference wavelength). In GaAs PIN photodiodes, Pbs
photoconductive detectors are employed in moisture analyzer circuits.
Gas Analyzers
IR sensors are used in gas analyzers which use absorption characteristics of gases in the
IR region. Two types of methods are used to measure the density of gas such as dispersive and
non dispersive.
Dispersive: An Emitted light is spectroscopically divided and their absorption
characteristics are used to analyze the gas ingredients and the sample quantity.
Non dispersive: It is most commonly used method and it uses absorption characteristics
without dividing the emitted light. Non dispersive types use discrete optical band pass filters,
similar to sunglasses that are used for eye protection to filter out unwanted UV radiation.
MODULE 3:RELAY
RELAY:
A relay is an electrically operated switch. Current flowing through the coil of the relay
creates a magnetic field which attracts a lever and changes the switch contacts. The coil current
can be on or off so relays have two switch positions and most have double throw (changeover)
switch contacts .
Relays allow one circuit to switch a second circuit which can be completely separate
from the first. For example a low voltage battery circuit can use a relay to switch a 230V AC
mains circuit. There is no electrical connection inside the relay between the two circuits, the link
is magnetic and mechanical.
The coil of a relay passes a relatively large current, typically 30mA for a 12V relay, but it
can be as much as 100mA for relays designed to operate from lower voltages. Most ICs (chips)
cannot provide this current and a transistor is usually used to amplify the small IC current to the
larger value required for the relay coil. The maximum output current for the popular 555 timer IC
is 200mA so these devices can supply relay coils directly without amplification.
Relays are usually SPDT or DPDT but they can have many more sets of switch contacts,
for example relays with 4 sets of changeover contacts are readily available. For further
information about switch contacts and the terms used to describe them please see the page
on switches.
Most relays are designed for PCB mounting but you can solder wires directly to the pins
providing you take care to avoid melting the plastic case of the relay.
The supplier's catalogue should show you the relay's connections. The coil will be
obvious and it may be connected either way round. Relay coils produce brief high voltage
'spikes' when they are switched off and this can destroy transistors and ICs in the circuit. To
prevent damage you must connect a protection diode across the relay coil.
The animated picture shows a working relay with its coil and switch contacts. You can
see a lever on the left being attracted by magnetism when the coil is switched on. This lever
moves the switch contacts. There is one set of contacts (SPDT) in the foreground and another
behind them, making the relay DPDT.
The relay's switch connections are usually labeled COM, NC and NO:
COM = Common, always connect to this, it is the moving part of the switch.
NC = Normally Closed, COM is connected to this when the relay coil is off.
NO = Normally Open, COM is connected to this when the relay coil is on.
Connect to COM and NO if you want the switched circuit to be on when the relay coil is
on.
Connect to COM and NC if you want the switched circuit to be on when the relay coil is
off.
Choosing a relay
You need to consider several features when choosing a relay:
1. Physicalsizeandpinarrangement
If you are choosing a relay for an existing PCB you will need to ensure that its
dimensions and pin arrangement are suitable. You should find this information in the
supplier's catalogue.
2. Coilvoltage
The relay's coil voltage rating and resistance must suit the circuit powering the relay coil.
Many relays have a coil rated for a 12V supply but 5V and 24V relays are also readily
available. Some relays operate perfectly well with a supply voltage which is a little lower
than their rated value.
3. Coilresistance
The circuit must be able to supply the current required by the relay coil. You can
use Ohm's law to calculate the current:
supply voltage
coil resistance
passes a current of
30mA. This is OK for a 555 timer IC (maximum output current 200mA), but it is too
much for most ICs and they will require a transistor to amplify the current.
5. Switch
ratings
(voltage
and
current)
The relay's switch contacts must be suitable for the circuit they are to control. You will
need to check the voltage and current ratings. Note that the voltage rating is usually
higher for AC, for example: "5A at 24V DC or 125V AC".
6. Switch
contact
arrangement
(SPDT,
DPDT
etc)
Most relays are SPDT or DPDT which are often described as "single pole changeover"
(SPCO) or "double pole changeover" (DPCO). For further information please see the
page on switches.
Protection diodes for relays
Transistors and ICs must be protected from the brief high voltage produced when a relay coil is
switched off. The diagram shows how a signal diode
(eg 1N4148) is connected 'backwards' across the
relay coil to provide this protection.
Current flowing through a relay coil creates a
magnetic field which collapses suddenly when the
current is switched off. The sudden collapse of the
magnetic field induces a brief high voltage across
the relay coil which is very likely to damage
transistors and ICs. The protection diode allows the induced voltage to drive a brief current
through the coil (and diode) so the magnetic field dies away quickly rather than instantly. This
prevents the induced voltage becoming high enough to cause damage to transistors and ICs.
Relays can switch AC and DC, transistors can only switch DC.
Relays are often a better choice for switching large currents (> 5A).
Disadvantages of relays:
Relays cannot switch rapidly (except reed relays), transistors can switch many times per
second.
Relays use more power due to the current flowing through their coil.
Relays require more current than many ICs can provide, so a low power transistor
may be needed to switch the current for the relay's coil.
This is opposed to a power source, such as a battery or generator, which produces power. [2] In
electric power circuits examples of loads are appliances and lights. The term may also refer to
the power consumed by a circuit.
The term is used more broadly in electronics for a device connected to a signal source, whether or
not it consumes power.[2] If an electric circuit has an output port, a pair of terminals that produces an
electrical signal, the circuit connected to this terminal (or its input impedance) is the load. For
example, if a CD player is connected to an amplifier, the CD player is the source and the amplifier is
the load.[2]
Load affects the performance of circuits with respect to output voltages or currents, such as
in sensors, voltage sources, and amplifiers. Mains power outlets provide an easy example: they
supply power at constant voltage, with electrical appliances connected to the power circuit
collectively making up the load. When a high-power appliance switches on, it dramatically reduces
the load impedance.
If the load impedance is not very much higher than the power supply impedance, the voltages will
drop. In a domestic environment, switching on a heating appliance may cause incandescent lights to
dim noticeably.
FAN
The LM35 is precision integrated-circuit temperature sensor, whose output voltage is linearly
proportional to the Celsius (Centigrade) temperature. The LM35 thus has an advantage over
linear temperature sensors calibrated in Kelvin, as the user is not required to subtract a large
constant voltage from its output to obtain convenient Centigrade scaling.
The temperature sensor output voltage variation is 10mV/C. The output voltage corresponds to
Temperature inside the CPU. The output voltage of LM35 is fed to PGA by port P0(1). The
amplified voltage is given to ADC. The ADC output is digital form of the input voltage and is
displayed on LCD. The digital output is used to program the PWM. When temperature inside
CPU is at room temperature, the fan is in OFF condition (PWM ON-period=00). Above the room
temperature the CPU fan is turned on. As temperature is increased the ON-period of PWM is
increased and fan speed is increased. The output of PWM module is connected to base of BC547
NPN transistor. The BC547 NPN transistor drives the CPU fan which is provided with 12V dc
Supply.