You are on page 1of 55

SYNOPSIS

SYNOPSIS

Our project is “Temperature Based Static Device Control” is to Design an automated

system for controlling a device based on the temperature sensor value. Temperature sensor is

connected to ADC by the o/p of ADC we can get the digital values of the temperature sensor.

Keys are connected to microcontroller by which we can set the threshold value for the

temperature which is seen in the LCD. If the sensor value is more than the given value then

the device will be OFF. If the temperature sensor value is less than given value than device

will be ON.

In a project the microcontroller is been connected to Keys, Temperature sensor, TRIAC,

Devices, LCD, ADC. So the temperature value is been given to controller using ADC and

keys are used to set the temperature value if the value is exciding then device will be OFF

otherwise device will be ON.


BLOCK DIAGRAM
BLOCK DIAGRAM:

LCD
Power
Supply

T
Temperature R DEVICE
Sensor Micro I
Controller A
C

KEYS
ADC
BLOCK DESCRIPTION
Power supply

A power supply provides a constant output regardless of voltage variations. “Fixed" three-

terminal linear regulators are commonly available to generate fixed voltages of plus 3 V, and

plus or minus 5 V, 9 V, 12 V, or 15 V when the load is less than about 7 amperes.

The "78xx" series (7805, 7812, etc.) regulate positive voltages while the "79xx" series

(7905, 7912, etc.) regulate negative voltages. Often, the last two digits of the device number

are the output voltage; eg, a 7805 is a +5 V regulator, while a 7915 is a -15 V regulator. The

78xx series ICs can supply up to 1.5 Amperes depending on the model.

PIC Microcontroller (PIC16F87X) Microcontroller Core Features:

• High-performance RISC CPU

• Only 35 single word instructions

• All single cycle instructions except for program branches which are two cycle

• Operating speed: DC - 20 MHz clock input DC - 200 ns instruction cycle

• Up to 8K x 14 words of FLASH Program Memory,

Up to 368 x 8 bytes of Data Memory (RAM)

Up to 256 x 8 bytes of EEPROM data memory

• Interrupt capability (up to 14 sources)

• Eight level deep hardware stack

• Direct, indirect and relative addressing modes

• Power-on Reset (POR)

• Power-up Timer (PWRT) and Oscillator Start-up Timer (OST)

• Watchdog Timer (WDT) with its own on-chip RC oscillator for reliable operation

• Programmable code-protection
• Power saving SLEEP mode

• Selectable oscillator options

• Low-power, high-speed CMOS FLASH/EEPROM technology

TEMPERATURE SENSOR

Temperature is the most-measured process variable in industrial automation. Most


commonly, a temperature sensor is used to convert temperature value to an electrical value.
Temperature Sensors are the key to read temperatures correctly and to control temperature in
industrials applications.

In the temperature functional module we developed, we use the LM34 series of


temperature sensors. The LM35 series are precision integrated-circuit temperature sensors,
whose output voltage is linearly proportional to the Fahrenheit temperature. The LM35 thus
has an advantage over linear temperature sensors calibrated in degrees Kelvin, as the user is
not required to subtract a large constant voltage from its output to obtain convenient
Fahrenheit scaling. The LM35 does not require any external calibration or trimming to
provide typical accuracies of ±1.2°F at room temperature and ±11.2°F over a full -50 to
+300°F temperature range. The LM34 is rated to operate over a -50° to +300°F temperature
range.

RELAY:

Relay is an electromagnetic switch which is controlled with a small current and is used for
turned on or off high electric circuits or appliances. Means its magnetic coil is turned on or
off with a small current but its magnetic contacts are used for controlling high currents. Two
types of rely modules are commonly used first one is ac relay module whose magnetic coil is
operated at ac voltages. Similarly, second one is dc relay module whose magnetic coil is
operated at dc voltages. Both relay modules are easily available in market or online shop. But
in this article, we will only talk about dc voltages relay module.
CIRCUIT DIAGRAM
CIRCUIT DIAGRAM
PIC MICROCONTROLLER
PIC Microcontroller (PIC16F87X) Microcontroller Core Features:

• High-performance RISC CPU

• Only 35 single word instructions

• All single cycle instructions except for program branches which are two cycle

• Operating speed: DC - 20 MHz clock input DC - 200 ns instruction cycle

• Up to 8K x 14 words of FLASH Program Memory,

Up to 368 x 8 bytes of Data Memory (RAM)

Up to 256 x 8 bytes of EEPROM data memory

• Interrupt capability (up to 14 sources)

• Eight level deep hardware stack

• Direct, indirect and relative addressing modes

• Power-on Reset (POR)

• Power-up Timer (PWRT) and Oscillator Start-up Timer (OST)

• Watchdog Timer (WDT) with its own on-chip RC oscillator for reliable operation

• Programmable code-protection

• Power saving SLEEP mode

• Selectable oscillator options

• Low-power, high-speed CMOS FLASH/EEPROM technology

• Fully static design

• In-Circuit Serial Programming (ICSP) via two pins

• Single 5V In-Circuit Serial Programming capability

• In-Circuit Debugging via two pins

• Processor read/write access to program memory


• Wide operating voltage range: 2.0V to 5.5V

• High Sink/Source Current: 25 mA

• Commercial and Industrial temperature ranges

• Low-power consumption:

- < 2 mA typical @ 5V, 4 MHz

- 20 mA typical @ 3V, 32 kHz

- < 1 mA typical standby current

Peripheral Features

• Timer0: 8-bit timer/counter with 8-bit prescaler

• Timer1: 16-bit timer/counter with prescaler, can be incremented during sleep via

external crystal/clock

• Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler

• Two Capture, Compare, PWM modules

- Capture is 16-bit, max. resolution is 12.5 ns

- Compare is 16-bit, max. resolution is 200 ns

- PWM max. resolution is 10-bit

• 10-bit multi-channel Analog-to-Digital converter

• Synchronous Serial Port (SSP) with SPI (Master Mode) and I2C (Master/Slave)

• Universal Synchronous Asynchronous Receiver Transmitter (USART/SCI) with 9-bit


address detection

• Parallel Slave Port (PSP) 8-bits wide, with external RD, WR and CS controls (40/44-pin
only)
Pin layout of PIC16F877A
MEMORY ORGANIZATION

There are three memory blocks in each of these PICmicro MCUs. The Program
Memory and Data Memory have separate buses so that concurrent access can occur.

Program memory organization

The PIC16F87X devices have a 13-bit program counter capable of addressing an 8K x


14 program memory space. The PIC16F877/876 devices have 8K x 14 words of FLASH
program memory and the PIC16F873/874 devices have 4K x 14. Accessing a location above
the physically implemented address will cause a wraparound. The reset vector is at 0000h and
the interrupt vector is at 0004h.

Program memory and Stack memory


Data memory organization

The data memory is partitioned into multiple banks which contain the General
Purpose Registers and the Special Function Registers. Bits RP1(STATUS<6>) and RP0
(STATUS<5>) are the bank select bits.

Table Register bank selection

Each bank extends up to 7Fh (128 bytes). The lower locations of each bank are reserved for
the Special Function Registers. Above the Special Function Registers are General Purpose
Registers, implemented as static RAM.

General purpose register file

The register file can be accessed either directly or indirectly through the File Select
Register FSR.

Special function registers

The Special Function Registers are registers used by the CPU and peripheral modules
for controlling the desired operation of the device. These registers are implemented as static
RAM. The Special Function Registers can be classified into two sets; core (CPU) and
peripheral.

Status register

The STATUS register contains the arithmetic status of the ALU, the RESET status
and the bank select bits for data memory. The STATUS register can be the destination for
any instruction, as with any other register. If the STATUS register is the destination for an
instruction that affects the Z, DC or C bits, then the write to these three bits is disabled. These
bits are set or cleared according to the device logic. The TO and PD bits are not writable,
therefore, the result of an instruction with the STATUS register as destination may be
different than intended.

OPTION_REG register

The OPTION_REG Register is a readable and writable register, which contains


various control bits to configure the TMR0 prescaler/WDT postscaler (single assignable
register known also as the prescaler), the External INT Interrupt, TMR0 and the weak pull-
ups on PORTB.

INTCON register

The INTCON Register is a readable and writable register, which contains various
enable and flag bits for the TMR0 register overflow, RB Port change and External RB0/INT
pin interrupts.

PIE1 register

The PIE1 register contains the individual enable bits for the peripheral interrupts.

PIR1 register

The PIR1 register contains the individual flag bits for the peripheral interrupts.

PIE2 register

The PIE2 register contains the individual enable bits for the CCP2 peripheral
interrupt, the SSP bus collision interrupt, and the EEPROM write operation interrupt.

PIR2 register

The PIR2 register contains the flag bits for the CCP2 interrupt, the SSP bus collision
interrupt and the EEPROM write operation interrupt.

PCON register

The Power Control (PCON) Register contains flag bits to allow differentiation
between a Power-on Reset (POR), a Brown-out Reset (BOR), a Watch-dog Reset (WDT) and
an external MCLR Reset.
Addressing modes:

Direct Addressing

Direct Addressing is done through a 9-bit address. This address is obtained by


connecting 7th bit of direct address of an instruction with two bits (RP1, RP0) from STATUS
register as is shown on the following picture. Any access to SFR registers can be an example
of direct addressing.

Indirect Addressing

Indirect unlike direct addressing does not take an address from an instruction but
makes it with the help of IRP bit of STATUS and FSR registers. Addressed location is
accessed via INDF register which in fact holds the address indicated by a FSR. In other
words, any instruction which uses INDF as its register in reality accesses data indicated by a
FSR register. Let's say, for instance, that one general purpose register (GPR) at address 0Fh
contains a value of 20. By writing a value of 0Fh in FSR register we will get a register
indicator at address 0Fh, and by reading from INDF register, we will get a value of 20, which
means that we have read from the first register its value without accessing it directly (but via
FSR and INDF). It appears that this type of addressing does not have any advantages over
direct addressing, but certain needs do exist during programming which can be solved
smoothly only through indirect addressing.
Indirect addressing, INDF and FSR registers

The INDF register is not a physical register. Addressing the INDF register will cause
indirect addressing. Indirect addressing is possible by using the INDF register. Any
instruction using the INDF register actually accesses the register pointed to by the File Select
Register, FSR. Reading the INDF register itself indirectly (FSR = ’0’) will read 00h. Writing
to the INDF register indirectly results in a no-operation (although status bits may be
affected).

I/O Ports

Some pins for these I/O ports are multiplexed with an alternate function for the
peripheral features on the device. In general, when a peripheral is enabled, that pin may not
be used as a general purpose I/O pin.

PORTA and the TRISA Register

PORTA is a 6-bit wide bi-directional port. The corresponding data direction register
is TRISA. Setting a TRISA bit (=1) will make the corresponding PORTA pin an input (i.e.,
put the corresponding output driver in a hi-impedance mode). Clearing a TRISA bit (=0) will
make the corresponding PORTA pin an output (i.e., put the contents of the output latch on the
selected pin). Reading the PORTA register reads the status of the pins, whereas writing to it
will write to the port latch. Pin RA4 is multiplexed with the Timer0 module clock input to
become the RA4/T0CKI pin. The RA4/T0CKI pin is a Schmitt Trigger input and an open
drain output. All other PORTA pins have TTL input levels and full CMOS output drivers.
Other PORTA pins are multiplexed with analog inputs and analog VREF input. The
operation of each pin is selected by clearing/setting the control bits in the ADCON1 register
(A/D Control Register1).

PORTB and the TRISB Register

PORTB is an 8-bit wide, bi-directional port. The corresponding data direction register
is TRISB. Setting a TRISB bit (=1) will make the corresponding PORTB pin an input.
Clearing a TRISB bit (=0) will make the corresponding PORTB pin an output. Three pins of
PORTB are multiplexed with the Low Voltage Programming function; RB3/PGM, RB6/PGC
and RB7/PGD. Each of the PORTB pins has a weak internal pull-up. A single control bit can
turn on all the pull-ups. This is performed by clearing bit RBPU (OPTION_REG<7>). The
weak pull-up is automatically turned off when the port pin is configured as an output. The
pull-ups are disabled on a Power-on Reset. Four of PORTB’s pins, RB7:RB4, have an
interrupt on change feature. Only pins configured as inputs can cause this interrupt to occur.
The input pins (of RB7:RB4) are compared with the old value latched on the last read of
PORTB. The “mismatch” outputs of RB7:RB4 are OR’ed together to generate the RB Port
Change Interrupt with flag bit RBIF (INTCON<0>).

PORTC and the TRISC Register

PORTC is an 8-bit wide, bi-directional port. The corresponding data direction register
is TRISC. Setting a TRISC bit (=1) will make the corresponding PORTC pin an input.
Clearing a TRISC bit (=0) will make the corresponding PORTC pin an output. When the I2C
module is enabled, the PORTC (3:4) pins can be configured with normal I2C levels or with
SMBUS levels by using the CKE bit (SSPSTAT <6>).

PORTD and TRISD Registers

PORTD is an 8-bit port with Schmitt Trigger input buffers. Each pin is individually
configurable as an input or output. PORTD can be configured as an 8-bit wide
microprocessor port (parallel slave port) by setting control bit PSPMODE (TRISE<4>). In
this mode, the input buffers are TTL.
PORTE and TRISE Register

PORTE has three pins, RE0/RD/AN5, RE1/WR/AN6 and RE2/CS/AN7, which are
individually configurable as inputs or outputs. These pins have Schmitt Trigger input buffers.
I/O PORTE becomes control inputs for the microprocessor port when bit PSPMODE
(TRISE<4>) is set. In this mode, the input buffers are TTL. PORTE pins are multiplexed
with analog inputs. When selected as an analog input, these pins will read as ’0’s. TRISE
controls the direction of the RE pins, even when they are being used as analog inputs.

Data EEPROM and FLASH Program Memory

The Data EEPROM and FLASH Program Memory are readable and writable during
normal operation over the entire VDD range. The data memory is not directly mapped in the
register file space. Instead it is indirectly addressed through the Special Function Registers
(SFR). There are six SFRs used to read and write the program and data EEPROM memory.

These registers are: EECON1, EECON2, EEDATA, EEDATH, EEADR and


EEADRH.

The EEPROM data memory allows byte read and writes. When interfacing to the data
memory block, EEDATA holds the 8-bit data for read/write and EEADR holds the address of
the EEPROM location being accessed. The registers EEDATH and EEADRH are not used
for data EEPROM access. These devices have up to 256 bytes of data EEPROM with an
address range from 0h to FFh.

Program memory access allows for checksum calculation and calibration table
storage. A byte or word write automatically erases the location and writes the new data (erase
before write). Writing to program memory will cease operation until the write is complete.
The program memory cannot be accessed during the write, therefore code cannot execute.
During the write operation, the oscillator continues to clock the peripherals, and therefore
they continue to operate When the write completes, the next instruction in the pipeline is
executed and the branch to the interrupt vector address will occur. When interfacing to the
program memory block, the EEDATH:EEDATA registers form a two byte word, which holds
the 14-bit data for read/write. The EEADRH:EEADR registers form a two byte word, which
holds the 13-bit address of the EEPROM location being accessed. These devices can have up
to 8K words of program EEPROM with an address range from 0h to 3FFFh
Timer0 Module

Timer mode is selected by clearing bit T0CS (OPTION_REG<5>). In timer mode, the
Timer0 module will increment every instruction cycle (without prescaler). If the TMR0
register is written, the increment is inhibited for the following two instruction cycles. The
user can work around this by writing an adjusted value to the TMR0 register. Counter mode
is selected by setting bit T0CS (OPTION_REG<5>). In counter mode, Timer0 will increment
either on every rising or falling edge of pin RA4/T0CKI. The incrementing edge is
determined by the Timer0 Source Edge Select bit T0SE (OPTION_REG<4>). Clearing bit
T0SE selects the rising edge. The prescales is mutually exclusively shared between the
Timer0 module and the watchdog timer. The prescaler is not readable or writable.

Timer0 Interrupt

The TMR0 interrupt is generated when the TMR0 register overflows from FFh to 00h.
This overflow sets bit T0IF (INTCON<2>). The interrupt can be masked by clearing bit T0IE
(INTCON<5>). Bit T0IF must be cleared in software by the Timer0 module interrupt service
routine before re-enabling this interrupt. The TMR0 interrupt cannot awaken the processor
from SLEEP since the timer is shut off during SLEEP.

Timer1 Module

The Timer1 module is a 16-bit timer/counter consisting of two 8-bit registers


(TMR1H and TMR1L), which are readable and writable. The TMR1 Register pair
(TMR1H:TMR1L) increments from 0000h to FFFFh and rolls over to 0000h. The TMR1
Interrupt, if enabled, is generated on overflow, which is latched in interrupt flag bit TMR1IF
(PIR1<0>). This interrupt can be enabled/disabled by setting/clearing TMR1 interrupt enable
bit TMR1IE (PIE1<0>).Timer1 can operate in one of two modes 1) As a timer, 2) As a
counter.

The operating mode is determined by the clock select bit, TMR1CS (T1CON<1>). In
timer mode, Timer1 increments every instruction cycle. In counter mode, it increments on
every rising edge of the external clock input. Timer1 can be enabled/disabled by
setting/clearing control bit TMR1ON (T1CON<0>).
Block diagram of TIMER

TIMER2 MODULE

Timer2 is an 8-bit timer with a prescaler and a postscaler. It can be used as the PWM time
base for the PWM mode of the CCP module(s). The TMR2 register is readable and writable
and is cleared on any device Reset.

Master Synchronous Serial Port (MSSP) Module

The Master Synchronous Serial Port (MSSP) module is a serial interface useful for
communicating with other peripheral or microcontroller devices. These peripheral devices
may be serial EEPROMs, shift registers, display drivers, A/D converters, etc. The MSSP
module can operate in one of two modes:

• Serial Peripheral Interface (SPI)

• Inter-Integrated Circuit (I2C)

MSSP I2C Operation

The MSSP module in I2C mode fully implements all master and slave functions
(including general call support) and provides interrupts-on-start and stop bits in hardware to
determine a free bus (multi-master function). The MSSP module implements the standard
mode specifications, as well as 7-bit and 10-bit addressing.

Two pins are used for data transfer. These are the SCL pin, which is the clock, and the
SDA pin, which is the data. The SDA and SCL pins are automatically configured when the
I2C mode is enabled. The SSP module functions are enabled by setting SSP Enable bit
SSPEN (SSPCON<5>). The SSPCON register allows control of the I2C operation. Four
mode selection bits (SSPCON<3:0>) allow one of the following I2C modes to be selected:

• I2C Slave mode (7-bit address)

• I2C Slave mode (10-bit address)

• I2C Master mode, clock = OSC/4 (SSPADD +1)

The SSPSTAT register gives the status of the data transfer. SSPBUF is the register to
which the transfer data is written to or read from. In receive operations; the SSPBUF and
SSPSR create a doubled buffered receiver. This allows reception of the next byte to begin
before reading the last byte of received data. When the complete byte is received, it is
transferred to the SSPBUF register and flag bit SSPIF is set.

Master Mode

Master mode of operation is supported by interrupt generation on the detection of the


START and STOP conditions. The STOP (P) and START (S) bits are cleared from a reset or
when the MSSP module is disabled. In master mode, the SCL and SDA lines are manipulated
by the MSSP hardware. The following events will cause the SSP Interrupt Flag bit, SSPIF, to
be set (SSP Interrupt if enabled):

• START condition

• STOP condition

• Data transfer byte transmitted/received

• Acknowledge transmit

• Repeated Start
TEMPERATURE SENSOR
TEMPERATURE SENSOR

Temperature is the most-measured process variable in industrial automation. Most


commonly, a temperature sensor is used to convert temperature value to an electrical value.
Temperature Sensors are the key to read temperatures correctly and to control temperature in
industrials applications.

A large distinction can be made between temperature sensor types. Sensors differ a lot in
properties such as contact-way, temperature range, calibrating method and sensing element.
The temperature sensors contain a sensing element enclosed in housings of plastic or metal.
With the help of conditioning circuits, the sensor will reflect the change of environmental
temperature.

In the temperature functional module we developed, we use the LM35 series of


temperature sensors. The LM35 series are precision integrated-circuit temperature sensors,
whose output voltage is linearly proportional to the Fahrenheit temperature. The LM35 thus
has an advantage over linear temperature sensors calibrated in degrees Kelvin, as the user is
not required to subtract a large constant voltage from its output to obtain convenient
Fahrenheit scaling. The LM35 does not require any external calibration or trimming to
provide typical accuracies of ±1.2°F at room temperature and ±11.2°F over a full -50 to
+300°F temperature range. The LM35 is rated to operate over a -50° to +300°F temperature
range.

 LM35 is a temperature measuring device having an analog output voltage


proportional to the temperature.
 It provides output voltage in Centigrade (Celsius). It does not require any external
calibration circuitry.
 The sensitivity of LM35 is 10 mV/degree Celsius. As temperature increases, output
voltage also increases.
 It is a 3-terminal sensor used to measure surrounding temperature ranging from -55
°C to 150 °C.
 LM35 gives temperature output which is more precise than thermistor output.
+5V

OUTPUT
LM35

GND
GND

Circuit diagram for the LM35 temperature sensor functional module

It is easy to include the LM35 series in a temperature measuring application. The output
voltage of LM35 is linearly proportional to the Fahrenheit temperature, it has a Linear +10.0
mV/°F scale factor which means that you will get n*10.0 mV output voltage if the
environment temperature is n°F.

The LM35 series is available packaged in hermetic TO-46 transistor packages, while the
LM35C, LM35CA and LM35D are also available in the plastic TO-92 transistor package.
The LM35D is also available in an 8-lead surface mount small outline package. In our
functional module, LM35H in metal can package (TO-46) is used in the functional module, it
is very important to know that the wiring of sensor should be based on the positions of the
leading pins in different packages.

VCC: Supply Voltage (4V – 30V)

VCC: Supply Voltage (4V – 30V)

Out: It gives analog output voltage which is proportional to the temperature (in degree Celsius).

GND: Ground
Application Setup

LM35 is a temperature sensor which can measure temperature in the range of -55°C to
150°C.It is a 3-terminal device that provides analog voltage proportional to the temperature.
Higher the temperature, higher is the output voltage. The output analog voltage can be
converted to digital form using ADC so that a microcontroller can process it.

Interfacing Diagram
Driver IC ULN 2003A
Driver IC ULN 2003A

ULN2003 is a relay driver IC consisting of a Darlington array. It is made up of seven


open collector Darlington pairs with common emitter. Moreover, ULN2003A has a capability
of handling seven different Relays simultaneously. A single Darlington pair consists of two
bipolar transistors and operates in the range of 500mA to 600mA current.

It is basically a relay driver IC and it is a Darlington array having high voltages and high
currents as well. It is made up of seven open collector Darlington pairs having common
emitter which shows ULN2003 has a capability of handling seven different relays at a time.
You should also have a look at Relay Interfacing with Microcontroller using ULN2003A.
ULN2003A is exactly the same as ULN2003with some small differences which are not of
much importance.

A single Darlington pair consists of two bipolar transistors and it operates on the current
range of 500mA to 600mA. ULN200X is a well known series of IC’s. ULN2003 is also the
part of this series. ULN2003 operates on 5V and TTL (Transistor Transistor Logic) and
CMOS (Complementary Metal Oxide Semi Conductor). Its pin configuration is designed so
that the input pins are at the left side of the IC whereas the the output pins of it are on right
side in front of the corresponding input pin. This IC has a very wide range of applications.
They are commonly used as relay drivers in order to drive different kinds of loads.
ULN2003A can also be used to drive different motors (e.g. DC Motors or Stepper Motors)
with Microcontrollers (like Arduino, PIC Microcontroller or 8051 Microcontroller etc.) .
Some of the other applications of ULN2003 include logic buffers, lamp drivers, line drivers,
LED display, motor driver circuits etc.

ULN 2003 PIN OUT

 ULN2003 has 16 pins in total out of which there are:


o 7 Input pins (Pin # 1 to Pin # 7)
o 7 Output pins (Pin # 10 to Pin # 16)
o 1 Ground pin (Pin # 8)
o 1 COM pin (Pin # 9)
 The pin diagram for ULN2003 is shown in the figure below.

Its pin division on the basis of functions associated with them is shown in above
figure. Further description will be given in this tutorial later. In short the pins can be
divided into four different categories i.e. input pins, output pins, ground pin and common
pin. These pins along with their positions are shown below.

ULN 2003 PIN DESCRIPTION

The functions associated with each pin of ULN2003 along with the pin names are shown in
the table given below.
The ULx200xA devices are high-voltage, high-current Darlington transistor arrays.
Each consists of seven NPN Darlington pairs that feature high-voltage outputs with common-
cathode clamp diodes for switching inductive loads.

The collector-current rating of a single Darlington pair is 500 mA. The Darlington
pairs can be paralleled for higher current capability. Applications include relay drivers,
hammer drivers, lamp drivers, display drivers (LED and gas discharge), line drivers, and
logic buffers. For 100-V (otherwise interchangeable) versions of the ULx2003A devices, see
the SLRS023 data sheet for the SN75468 and SN75469 devices.

The ULN2002A device is designed specifically for use with 14-V to 25-V PMOS
devices. Each input of this device has a Zener diode and resistor in series to control the input
current to a safe limit. The ULx2003A devices have a 2.7-kΩ series base resistor for each
Darlington pair for operation directly with TTL or 5-V CMOS devices.

The ULx2004A devices have a 10.5-kΩ series base resistor to allow operation
directly from CMOS devices that use supply voltages of 6 V to 15 V. The required input
current of the ULx2004A device is below that of the ULx2003A devices, and the required
voltage is less than that required by the ULN2002A device.

INTERNAL CIRCUIT DIAGRAM OF ULN 2003

Internal circuit diagram of ULN 2003 having different resistors and diodes is shown in the
figure below.
LOGIC DIAGRAM

 Internally, ULN2003A is made of hybrid combination of logic gates and diodes.

 The logic diagram for ULN2003 is shown in the figure below.

There are a lot of keys features associated with the relay driver ULN2003. A few of
which are given below.

 500mA of rated collector.

 High output voltage of around 50V.

 Relay driver applications.

 Output clamp diodes.

 Compatible input with popular logic types.

 Some of the key features are also given in the table below for the better understanding
about the working conditions of ULN2003
APPLICATIONS

The relay circuit driver ULN2003 has a wide range of applications in real life. Some
of the major applications associated with ULN-2003 are given below.

 Logic buffers.
 Line drivers.
 Relay drivers (for driving different loads).
 Lamp drivers.
 LED display drivers (display devices).
Motor (stepper and DC brushed motor) drivers

SIMULATON
RELAY, UNIVERSAL MOTOR AND LCD POWERSUPPLY
RELAY
Relay is an electromagnetic switch which is controlled with a small current and is
used for turned on or off high electric circuits or appliances. Means its magnetic coil is turned
on or off with a small current but its magnetic contacts are used for controlling high currents.
Two types of rely modules are commonly used, first one is ac relay module whose magnetic
coil is operated at ac voltages. Similarly, second one is dc relay module whose magnetic coil
is operated at dc voltages. Both relay modules are easily available in market or online shop.
But in this article, we will only talk about dc voltages relay module

A Simple Dc Operated Relay Module


Pin Configuration of Relay Module
Relay modules are available in different channels such as single channel and multi
channel etc. Single channel consists of only single relay and multi channel consists of multi
relays which are connected in parallel with each other. Every relay normally consists three
inputs pins such as VCC, GND and signal etc. Similarly, it also consists of three output pins
such as NC (normally close), NO (normally open) and COM (common). Supply voltages are
applied at VCC and GND pin which are normally 5V dc and signal voltages are applied at
signal pin. Every relay module also consists of two LEDs which tell the relay is power on or
off.

Working Principle of Relay Module


Relay works on the principle of electromagnetic switch. When voltages are applied at
its input pins such as at VCC and GND then this relay is power on, means it comes into
active position. Because its consists of normally open (NO) and normally close (NC) contacts
which are used for controlling high current and this current could be ac or dc. Both positions
such as when voltages are applied at input pins and when voltages are not applied at input
pins are shown in figure 2
Relay Module Activated and Deactivated Positions
According to when dc voltages are not applied at input pins of relay module then this
relay does not come into in active position and common point remain connected with NC
point means with normally close point. During this position if any current is available at
common point then this current is passed through normally close point. Then the circuit or
thing which is connected with normally close point, it would be come into turned on position
otherwise it would be remained in turned off position. Similarly, when the voltages are
applied at input pins of relay then this relay come into in active position means when voltages
are applied at coil terminals then electromagnetic field is produced.

This electromagnetic field attracts the armature which is the liver connected through
spring. During this position the common point is connected with normally open point then
current is passed through common point to normally open point.

To interface pic microcontroller with relay, we need to use digital output port of pic
16F877A microcontroller. When we apply digital high signal to relay, relay becomes on and
when we apply digital low signal to relay, relay turns off. As

This microcontroller controlled the relay with so efficiently and intelligently. Circuit
diagram for relay module interfacing with pic16f877a microcontroller is shown below. I have
connected a push button with pic microcontroller which will be used to turn on and turn off
relay module. Suppose we want to turn on the relay module for any specific time then we
shell tell the microcontroller through programming to turn on the relay module for some time
Then this microcontroller automatically gives 5V dc voltages for that specific time to turn on
the relay module. So, we can easily control the relay module with pic 16f877a
microcontroller.
POWER SUPPLY:

A power supply provides a constant output regardless of voltage variations."Fixed" three-


terminal linear regulators are commonly available to generate fixed voltages of plus 3 V, and
plus or minus 5 V, 9 V, 12 V, or 15 V when the load is less than about 7 amperes.

The "78xx" series (7805, 7812, etc.) regulate positive voltages while the "79xx" series
(7905, 7912, etc.) regulate negative voltages. Often, the last two digits of the device number
are the output voltage; eg, a 7805 is a +5 V regulator, while a 7915 is a -15 V regulator. The
78xx series ICs can supply up to 1.5 Amperes depending on the model.

Features

1. Output Current up to 1A
2. Output Voltages of 5, 6, 8, 9, 10, 12, 15, 18, 24
3. Thermal Overload Protection
4. Short Circuit Protection
5. Output Transistor Safe Operating Area Protection

When you have a requirement for a project of say 12V, or even 5V if it's a digital project,
then these are the types you use. 7805 or 7812 are the types. There are of course negative
voltage regulators with the numbers 79XX which are substantially the same as those
discussed here excepting they are negative. We will not consider them further. Assume your
project calls for a basic fixed 12V D.C. to operate. Looking back to our earlier tutorial we
apply all the same principles. Look at the original schematic.
The basic power supply schematic

In a typical linear power supply, AC line voltage is first down-converted to a smaller


peak voltage using a transformer which is then rectified using a full wave bridge rectifier
circuit. A capacitor filter is then used to smoothen the obtained sinusoidal signal. The residual
periodic variation or ripple in this filtered signal is eliminated using an active regulator.

To obtain a DC power supply with both positive and negative output voltages, a
center-tapped transformer is used, where a third wire is attached to the middle of the
secondary winding and it is taken as the common ground point. Then voltages from the
opposite ends of the winding will be positive or negative with respect to this point.

Circuit description

This circuit is a small +5V power supply, which is useful when experimenting with
digital electronics. Small inexpensive wall transformers with variable output voltage are
available from any electronics shop and supermarket. Those transformers are easily available,
but usually their voltage regulation is very poor, which makes then not very usable for digital
circuit experimenter unless a better regulation can be achieved in some way. The following
circuit is the answer to the problem. This circuit can give +5V output at about 150 mA
current, but it can be increased to 1 A when good cooling is added to 7805 regulator chip.
The circuit has over overload and terminal protection.

Circuit diagram of the power supply.

The capacitors must have enough high voltage rating to safely handle the input voltage feed
to circuit. The circuit is very easy to build for example into a piece of veroboard.

Pinout of the 7805 regulator IC.


1. Unregulated voltage in
2. Ground
3. Regulated voltage out
LCD DISPLAY

A liquid crystal display (LCD) is an electro-optical amplitude modulator realized as a


thin, flat display device made up of any number of color or monochrome pixels arrayed in
front of a light source or reflector. It is often utilized in battery-powered electronic devices
because it uses very small amounts of electric power.

Each pixel of an LCD typically consists of a layer of molecules aligned between two
transparent electrodes, and two polarizing filters, the axes of transmission of which are (in
most of the cases) perpendicular to each other. With no liquid crystal between the polarizing
filters, light passing through the first filter would be blocked by the second (crossed)
polarizer..

Interfacing an LCD to PIC Microcontroller.

LCD Operation:

In recent years the LCD is finding widespread use replacing LEDs (seven-segment
LEDs or other multisegment LEDs). This is due to the following reasons:

 The declining prices of LCDs.


 The ability to display numbers, characters, and graphics. This is in contrast to
LEDs, which are limited to numbers and a few characters.
 Incorporation of a refreshing controller into the LCD, thereby relieving the
CPU of the task of refreshing the LCD. In contrast, the LED must be refreshed
by the CPU (or in some other way) to keep displaying the data.
 Ease of programming for characters and graphics.
LCD pin descriptions:

The LCD discussed in this section has 14 pins. The function of each pin is given in
the table below.

VCC, VSS, and VEE:

While VCC and VSS provide +5V and ground, respectively, VEE is used for controlling
LCD contrast.

RS, Register Select:


There are two very important registers inside the LCD. The RS pin is used for their
selection as follows. If RS=0, the instruction command code register is selected, allowing the
user to send a command such as clear display, cursor at home, etc. If RS=1 the data register is
selected, allowing the user to send data to be displayed on the LCD.

R/W, Read/Write:

R/W input allows the user to write information to the LCD or read information from
it. R/W=1 when reading; R/W=0 when writing.

E, Enable:

The enable pin is used by the LCD to latch information presented to its data pins.
When data is supplied to data pins, a high-to-low pulse must be applied to this pin in order
for the LCD to latch in the data present at the data pins. This pulse must be a minimum of
450ns wide.

D0-D7:

The 8-bit data pins, D0-D7, are used to send information to the LCD or read the
contents of the LCD’s internal registers.

To display letters and numbers, we send ASCII codes for the letters A-Z, a-z, and
numbers 0-9 to these pins while making RS=1.

There are also instruction command codes that can be sent to the LCD to clear the
display or force the cursor to the home position or blink the cursor. Table lists the instruction
command codes.

We also use RS=0 to check the busy flag bit to see if the LCD is ready to receive
information. The busy flag is D7 and can be read when R/W=1 and RS=0, as follows: if
R/W=1, RS=0. When D7=1 (busy flag=1), the LCD is busy taking care of internal operations
and will not accept any new information.

Note: It is recommended to check the busy flag before writing any data to the LCD.
Code ( Command to LCD Instruction Register
Hex )

1 Clear display screen

2 Return home

4 Decrement cursor ( shift cursor to left )

6 Increment cursor ( shift cursor to right )

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 blinking

F Display off, 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 1st line


C0 Force cursor to beginning of 2nd line

38 2 lines and 5x7 matrix

Pin Name Function USE


No

1 Vss Ground

2 Vdd +ve Supply 5v Volts Regulated DC

3 Vee Contrast This is used to set the contrast1

4 RS Register Set Register select signal 0:Instruction


register (when writing) Busy flag &
address counter (When reading) 1:Data
register (when writing & reading)

5 R/W Read / Write Read/write select signal “0” for writing ,


“1” for reading

6 E Enable Operation (data read/write) enable


signal

7 D0 Data Bit 0

8 D1 Data Bit 1

9 D2 Data Bit 2

10 D3 Data Bit 3

11 D4 Data Bit 4

12 D5 Data Bit 5

13 D6 Data Bit 6

14 D7 Data Bit 7

15 A +4.2 for Back light Positive supply for back light if available

16 K Power supply Back light (


0V)

In some LCD's you might not find the 15 and 16 pin so don’t worry. Here is how you
must wire them up.
UNIVERSAL MOTOR
A universal motor is a special type of motor which is designed to run on either DC or single
phase AC supply. These motors are generally series wound (armature and field winding are
in series), and hence produce high starting torque (See characteristics of DC motors here).
That is why, universal motors generally comes built into the device they are meant to drive.
Most of the universal motors are designed to operate at higher speeds, exceeding 3500 RPM.
They run at lower speed on AC supply than they run on DC supply of same voltage, due to
the reactance voltage drop which is present in AC and not in DC.
There are two basic types of universal motor : (i)compensated type and (ii) uncompensated

type

A universal motor works on either DC or single phase AC supply. When the universal
motor is fed with a DC supply, it works as a DC series motor. (see working of a DC series
motor here). When current flows in the field winding, it produces an electromagnetic field.
The same current also flows from the armature conductors. When a current carrying
conductor is placed in an electromagnetic field, it experiences a mechanical force. Due to this
mechanical force, or torque, the rotor starts to rotate. The direction of this force is given by
Fleming's left hand rule. When fed with AC supply, it still produces unidirectional torque.
Because, armature winding and field winding are connected in series, they are in same phase.
Hence, as polarity of AC changes periodically, the direction of current in armature and field .

Applications of universal motor

 Universal motors find their use in various home appliances like vacuum cleaners, drink
and food mixers, domestic sewing machine etc.
 The higher rating universal motors are used in portable drills, blenders etc.
ADVANTAGE AND APPLICATION:

ADVANTAGE:
 It implement is too safety to detect fault
 The motor life can be improved
 It is highly efficient

APPLICATION:
 Commercial application
 Indutrisal applicaton
CODING:

#include <16F877A.h>

#device *=16

#device adc=10

#use delay(clock=10000000)

#fuses HS,NOLVP,NOWDT,PUT,NOPROTECT,BROWNOUT

#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

// variables for LCD port

#bit RS_LCD = PORTE.2 //LCD register selector

#bit RW_LCD = PORTE.1 //LCD Read/Write selector

#bit EN_LCD = PORTE.0 //LCD display eneable

#bit BF_LCD = PORTD.7 //LCD busy flag

//// Variable for Latch Enable

int dsec = 0;

int disp= 0;

int disp_bk = 0;

//////modbus variable////////

unsigned char recv_data = 0;

unsigned int recv_pos = 0;

unsigned char mod_id = 'A';

unsigned char mod_cmd = 0;

//unsigned char temp;

int sim_mode = 0;

int16 TEMPRATURE = 0;

int16 TEMP = 0; //variable declaration

int16 SPEED = 0;

int16 VBRS1 = 0;

int16 VBRS2 = 0;

int16 VBRS3 = 0;
//int16 VIBS = 60;

int msg = 0;

signed int TEMP_MODE = 0;

int16 flag = 0;

//int16 in_flag = 0;

//int16 spd_cnt = 0;

//int16 spd_stp = 0;

//int16 vbs_cnt = 0;

//int16 SEN_TIMER = 0;

////////////////// LCD PROGRAM //////////////////////////////

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/// LCD display busy flag routine


function////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void lcdready(void)

EN_LCD=0; //display disable

SET_TRIS_D( 0xff ); //PORTB input setting

RS_LCD=0; //command registor selector

RW_LCD=1; //read operation

/*while(BF_LCD==1) //while lcd busy flag set

EN_LCD=0;

EN_LCD=1;

}*/

delay_us(500);

EN_LCD =0;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////
///////// LCD Command
Routine////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void command(unsigned char lcddata)

lcdready(); // to check lcd busy flag routine

SET_TRIS_D( 0x00 ); // PORTB output setting

PORTD=lcddata; // send data to PORTB

RS_LCD=0; // command registor selector

RW_LCD=0; // write operation

EN_LCD=1; // display enable

EN_LCD=0; // display disable

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////

////// LCD Character Display


routine/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void display(unsigned char lcddata)

lcdready(); //to check lcd busy flag routine

SET_TRIS_D(0x00 ); //PORTB output setting

PORTD=lcddata; //send data to PORTB

RS_LCD=1; //data registor selector

RW_LCD=0; //write operation

EN_LCD=1; //display enable

EN_LCD=0; //display disable

delay_ms(dsec);

////////////////////////////////////////////////////////////////////////////////

///////////// lcdsetting routine////////////////////////////////////////////////

void lcdsetting(void)

{
command(0x38); // lcd 2 line ,5x7 matrix

command(0x0c); // display on,cursor on

command(0x06); // shift cursor right

command(0x01); // clear lcd

delay_ms(1);

//////////////////// LCD END PROGRAM ///////////////

////////ADC CHANNEL VALUE/////////////

#byte ADCON_0=0X1F

#byte ADCON_1=0X9F

#bit select =ADCON_0.2

int16 AI[8];

void adcvalue(int chn)

int i;

int16 avg_tot = 0;

SET_TRIS_A( 0xff );

setup_adc_ports(AN0_AN1_AN2_AN3_AN4);

setup_adc(ADC_CLOCK_INTERNAL);

for(i=0;i<chn;i++)

avg_tot = 0;

set_adc_channel(i);

select = 1;

read_adc(ADC_START_ONLY);

while(select == 1)

}
delay_us(1);

avg_tot = avg_tot + read_adc(ADC_READ_ONLY);

set_adc_channel(i);

select = 1;

read_adc(ADC_START_ONLY);

while(select==1)

delay_us(1);

avg_tot = avg_tot + read_adc(ADC_READ_ONLY);

set_adc_channel(i);

select = 1;

read_adc(ADC_START_ONLY);

while(select==1)

delay_us(1000);

avg_tot = avg_tot + read_adc(ADC_READ_ONLY);

set_adc_channel(i);

select = 1;

read_adc(ADC_START_ONLY);

while(select==1)

delay_us(1000);

avg_tot = avg_tot + read_adc(ADC_READ_ONLY);

AI[i] = avg_tot / 4 ;
}

/////////////////////////////////////////

void readAIstatus (void)

adcvalue(3); // how many channels to be used

VBRS1 = AI[0];

VBRS2 = AI[1];

VBRS3 = AI[2];

// SPEED = (int16)((float)AI[2]*0.14718);

if((VBRS1 > 100) || (GROUND == 1))

else

void MOTOR (void)

if(TEMP == 0)

TEMPRATURE++;
delay_ms(50);

if(TEMPRATURE > 100)

TEMPRATURE = 0;

////////////////////////////////////////////

void putInt16(int16 REG1)

void TITLE (void)

lcdsetting();

dsec = 10;

command(0x80); // force cursor to beginning of 1st line

printf(display," TEMPERATURE BASED ");

command(0xc0); // force cursor to beginning of 2st line

printf(display," STATIC DEVICE CONTROL ");

delay_ms(2000);

////////////////////////////////////////////

void main(void)
{

SET_TRIS_A( 0xff ); //PORTA input/output setting

SET_TRIS_B( 0x0f ); //PORTB input/output setting

SET_TRIS_D( 0x00 ); //PORTD output setting

SET_TRIS_C( 0x0f ); //PORTC output setting

SET_TRIS_E( 0x00 );

sim_mode = 0;

setup_adc_ports(AN0_AN1_AN2_AN3_AN4);

setup_adc(ADC_CLOCK_INTERNAL);

setup_psp(PSP_DISABLED); /// for RS 232 serial port setting

setup_spi(FALSE);

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_32);

setup_timer_1(T1_DISABLED);

setup_timer_2(T2_DISABLED,0,1);

setup_comparator(NC_NC_NC_NC);

setup_vref(FALSE);

enable_interrupts(INT_RTCC);

enable_interrupts(INT_RDA);

enable_interrupts(GLOBAL);

port_b_pullups(TRUE);

TITLE ();

GROUND = 1;

lcdsetting();

dsec = 0;

for(;;)

{
// lcdsetting();

dsec = 10;

command(0x80); // force cursor to beginning of 1st line

printf(display,"TEMPRATURE:%04ld",TEMPRATURE);

command(0xc0); // force cursor to beginning of 2st line

printf(display," TEMP : %04ld ",VBRS1);

printf("TEMPRATURE:%04ld\n\r",TEMPRATURE);

printf("TEMPRATURE:%04ld\n\r",VBRS1);

delay_ms(500);

readAIstatus ();

}
CONCLUSION:

The project on TEMPERATURE BASED STATIC DEVICE CONTROL is working

fine, getting the parameter envisaged during the conceptual stage.

During the design as well as during the construction greater care has been put into

avoid hiccups the final stage. The PCB layouts were prepared with utmost care to

incorporate the circuits in a modular manner. The circuits are made as simple as to our

knowledge. Also components were selected keeping in mind their availability and cost.

It was a very interesting process of developing the prototype, stage by stage and

testing the same. We have to go through fairly pages of data related to the components

etc. it was a useful and full filling assignment to get the project completed in time. This

gave us a sense of satisfaction and accomplishment

You might also like