Académique Documents
Professionnel Documents
Culture Documents
ABSTRACT
In this project we interface Mobile and Microcontroller with the help of Data
Cable and RS232 level converter for example when you are away from home and want to
switch ‘on’ any Machine like Fan, Air cooler, by sending SMS that contains the
corresponding Machine number and type of mode such that ON (or) OFF the machine by the
Mobile Phone. This is interfaced with the Microcontroller in company or home.
After receiving the message, the Mobile sends the data signal to the Microcontroller
through the data cable and RS232 level logic converter. Level converter gives the signal in
the form of 0 and 5V pulse to the Microcontroller.
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
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
The Microcontroller is the embedded device which has on chip program memory
in which the machine control program is stored. Suppose if you send the SMS like Machine 1
ON, in company corresponding information is displayed in the LCD display through
Microcontroller.
1
INDEX
S.No Pg.No
1. INTRODUCTION……………………………………...………………......…....…1
2. SYSTEM MODEL…………………………………………………….....…............2
2.1.1DESCRIPTION..........................................................................................3
2.2CIRCUIT DIAGRAM……………………………......………………...…....….4
3. HARWARE DESCRIPTION……………………………………......……….......…5
3.1MICROCONTROLLER (AT89S51)……………………….....……..……....…5
3.1.2DESCRIPTION………………………………….......……………....…...6
3.1.3FEATURES……………………………………………............................7
3.1.4PIN CONFIGURATION………………………..………….....….............8
3.1.5PIN DESCRIPTION…………………………………….......……......….9
3.1.6BLOCK DIAGRAM…………………………………….........….…..…10
3.2RELAY…………………………………………...………….....………...…....11
3.2.1CIRCUIT DESCRIPTION…………………………...……..…........…..13
3.3.1PIN DESCRIPTION…………………………………...….....….………16
2
3.3.2LCD COMMAND DESCRIPTION……….......………………….……18
3.4.1 TRANSFORMER………………....…………………………......….....20
4.SOFTWARE……………………………………………………….….....…...……22
4.1INTRODUCTION TO KEIL………………………………………...........….22
4.2CONCEPT OF COMPILER…………….....……………………….........…...22
5. SOURCE CODE…………………………….....…………………………..….…..29
5.1FLOW CHART.................................................................................................32
6.1ADVANTAGES……………………….....……………………………......….35
6.2DISADVANTAGES…………….....………………………………….....…...35
6.3APPLICATIONS…………………………………......……………….....……35
7.1RESULT……………………………….....……………………………….......36
7.2CONCLUSION…………………………......…………………….…….....….36
8. REFERENCES……………………………......………………………………...…37
3
LIST OF FIGURES
S.No Pg.No
2. CIRCUIT DIAGRAM……………………………………………………...………4
5. RELCIRCUIT………………………………………...…………..……………….11
6. RELAY SWITCH………………………………..………………………………..12
7. LCD DISPLAY………………………...……………………………………….....15
9. BRIDGE RECTIFIER..............................................................................................21
LIST OF TABLES
S.No Pg.No
1. PIN DESCRIPTION................................................................................................16
2. LCD COMMANDS.................................................................................................18
4
1. INTRODUCTION
The Microcontroller is the embedded device which has on chip program memory
in which the machine control program is stored. Suppose if you send the SMS like Machine 1
ON, in company corresponding information is displayed in the LCD display through
Microcontroller.
5
2. SYSTEM MODEL
6
BASIC MODEL OF THE SYSTEM
3. HARDWARE DESCRIPTION
7
3.1.1 CRITERIA FOR CHOOSING A MICROCONTROLLER
The basic criteria for choosing a microcontroller suitable for the application are:
1) The first and foremost criterion is that it must meet the task at hand efficiently and
cost effectively. In analyzing the needs of a microcontroller-based project, it is seen whether
an 8- bit, 16-bit or 32-bit microcontroller can best handle the computing needs of the task
most effectively. Among the other considerations in this category are:
ii. Packaging: It may be a 40-pin DIP (dual inline package) or a QFP (quad flat package), or
some other packaging format. This is important in terms of space, assembling, and
prototyping the end product.
iv. The number of I/O pins and the timer on the chip.
vi. Cost per unit: This is important in terms of the final cost of the product in which a
microcontroller is used.
3.1.2 DESCRIPTION:
8
from military equipment to automobiles to the keyboard. Second only to the Motorola,
68HC11 in eight bit processors sales, the 8052 family of microcontrollers is available in a
wide array of variations from manufacturers such as Intel, Philips, and Siemens. These
manufacturers have added numerous features and peripherals to the 8052 such as I2C
interfaces, analog to digital converters, watchdog timers, and pulse width modulated outputs.
Variations of the 8052 with clock speeds up to 40MHz and voltage requirements
down to 1.5 volts are available. This wide range of parts based on one core makes the 8052
family an excellent choice as the base architecture for a company's entire line of products
since it can perform many functions and developers will only have to learn this one platform.
The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial
port, and interrupt system to continue functioning. The Power-down mode saves the RAM
con-tents but freezes the oscillator, disabling all other chip functions until the next interrupt
or hardware reset.
3.1.3 FEATURES:
9
• 4.0V to 5.5V Operating Range
• Watchdog Timer
10
PIN DIAGRAM OF 8051
11
GND: Ground.
Port 0: Port 0 is an 8-bit open drain bidirectional 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 accesses to external program and data memory.
Port 1: Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 1 output
buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled
high by the internal pull-ups and can be used as inputs. As inputs, Port 1 pins that are
externally being pulled low will source current (IIL) because of the internal pull-ups. In
addition, P1.0 and P1.1 can be configured to be the timer/counter2 external count input
(P1.0/T2) and the timer/counter 2 trigger input (P1.1/T2EX), respectively.
Port 2: Port 2 is an 8-bit bidirectional 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 and can be used as inputs. As inputs, Port2 pins that are
externally being pulled low will source current (IIL) because of the internal pull-ups
Port 3: Port 3 is an 8-bit bidirectional 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 and can be used as inputs. As inputs, Port3 pins that are
externally being pulled low will source current (IIL) because of the pull ups. Port 3 receives
some control signals for Flash programming and verification.
RST: Reset input. A high on this pin for two machine cycles while the oscillator is running
resets the device. This pin drives high for 98 oscillator periods after the watchdog times out.
12
3.1.6 BLOCK DIAGRAM:
13
3.2RELAY:
RELAY CIRCUIT
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.
14
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. 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 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. You can see a lever on the left being attracted by magnetism when the coil is
switched on. This lever moves the switch contacts.
RELAY SWITCH
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.
15
3.2.1 CIRCUIT DESCRIPTION:
This circuit is designed to control the load. The load may be motor or any other
load. The load is turned ON and OFF through relay. The relay ON and OFF is controlled by
the pair of switching transistors (BC 547). The relay is connected in the Q2 transistor
collector terminal. A Relay is nothing but electromagnetic switching device which consists of
three pins. They are Common, Normally close (NC) and Normally open (NO).
The relay common pin is connected to supply voltage. The normally open (NO)
pin connected to load. When high pulse signal is given to base of the Q1 transistors, the
transistor is conducting and shorts the collector and emitter terminal and zero signals is given
to base of the Q2 transistor. So the relay is turned OFF state.
16
3.3 LIQUID CRYSTAL DISPLAY
The LCD is used for the purpose of displaying the words which we give in the
program code. This code will be executed on microcontroller chip. By following the
instructions in code the LCD display the related words.
Liquid crystal displays (LCDs) 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.
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 LCD’s are lightweight with only a few millimeters thickness. Since the
LCD’s consume less power, they are compatible with low power electronic c rcuits, and can
be powered for long durations.
The LCD don’t generate light and so light is needed to read the display. By using
backlighting, reading is possible in the dark. The LCD’s have long life and a wide operating
temperature range.
17
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 even started
replacing the cathode ray tubes (CRTs) used for the display of text and graphics, and also in
small TV applications. . Fig below shows the LCD display.
LCD DISPLAY
The LCD display consists of two lines, 20 characters per line that is interfaced
with the PIC16F73.The protocol (handshaking) for the display is as shown in Fig. The
display contains two internal byte-wide registers, one for commands (RS=0) and the second
for characters to be displayed (RS=1). It also contains a user-programmed RAM area (the
character RAM) that can be programmed to generate any desired character that can be
formed using a dot matrix. To distinguish between these two data areas, the hex command
byte 80 will be used to signify that the display RAM address 00h will be chosen Port1 is used
to furnish the command or data type, and ports 3.2 to 3.4 furnish register select and
read/write levels.
A liquid crystal is a material (normally organic for LCDs) that will flow like a
liquid but whose molecular structure has some properties normally associated with solids.
The Liquid Crystal Display (LCD) is a low power device. The power requirement is typically
in the order of microwatts for the LCD. However, an LCD requires an external or internal
light source. It is limited to a temperature range of about 0°C to 60°C and lifetime is an area
of concern, because LCDs can chemically degrade.
18
There are two major types of LCDs which are:
• Field-effect LCDs
The turn-on and turn-off time is an important consideration in all displays. The
response time of LCDs is in the range of 100 to 300ms.The lifetime of LCDs is steadily
increasing beyond 10,000+hours limit. Since the color generated by LCD units is dependent
on the source of illumination, there is a wide range of color choice. The lifetime of LCDs is
steadily increasing . Since the color generated by LCD units is dependent on the source of
illumination, there is a wide range of color choice.
3.3.1PIN DESCRIPTION
Pins Description
1 "Vss" - Ground
6 "E" - Enable
While Vcc and Vss provide +5v and ground, respectively, Vee is used for controlling
LCD contrast.
19
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
as 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.
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 latch in the data pins. This pulse must be a minimum of 450 ns 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, send ASCII codes for
the letters A - Z, a - z, and numbers 0 - 9 to these pins while RS = 1. When 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 operation and will not accept any new
information. The description of the pins is shown in Table below.
20
RS R/W D7 D6 D5 D4 D3 D2 D1 D0 Function
Home cursor
display character
Written S=1/0:shift
screen/ cursor
21
3.3.3 CHECKING THE BUSY STATUS OF THE LCD
The first instruction send must tell the LCD whether it is to be communicated
with an 8-bit or 4-bit data bus. 5x8 dot character font should also be selected. These two
options are selected by sending the command 38h to the LCD as a command.
When the LCD is first initialized, the screen should automatically be cleared by the
controller.
c) Cursor Positioning
The cursor positioning in a LCD can be done in the right entry mode or left entry mode. As
left entry mode is flexible it is implemented.
22
3.4 POWER SUPPLY:
The power supply circuits built using filters, rectifiers, and then voltage
regulators. Starting with an ac voltage, a steady dc voltage is obtained by rectifying the ac
voltage, then filtering to a dc level, and finally, regulating to obtain a desired fixed dc
voltage. The regulation is usually obtained from an IC voltage regulator unit, which takes a
dc voltage and provides a somewhat lower dc voltage, which remains the same even if the
input dc voltage varies, or the output load connected to the dc voltage changes. The block
diagram of power supply is shown in fig below.
3.4. TRANSFORMER
The potential transformer will step down the power supply voltage (0-230V) to (0-
6V) level. Then the secondary of the potential transformer will be connected to the precision
rectifier, which is constructed with the help of op–amp. The advantages of using precision
rectifier are it will give peak voltage output as DC, rest of the circuits will give only RMS
output.
23
3.4.2BRIDGE RECTIFIER
Bridge rectifier is used to maintain the proper DC polarity at the input to the
circuit. It comprises of four diodes connected to form a bridge. It uses the entire AC wave
(both positive and negative sections). 1.4V is used up in the bridge rectifier because each
diode uses 0.7V when conducting and there are always two diodes conducting, as shown in
fig
AC I/P
BRIDGE RECTIFIER
24
4. SOFTWARE
4.1INTRODUCTION TO KEIL:
4.2CONCEPT OF COMPILER: -
Compilers are programs used to convert a High Level Language to object code.
Desktop compilers produce an output object code for the underlying microprocessor, but not
for other microprocessors. I.E the programs written in one of the HLL like ‘C’ will compile
the code to run on the system for a particular processor like x86 (underlying microprocessor
in the computer). For example compilers for Dos platform is different from the Compilers for
Unix platform.
25
4.3CONCEPT OF CROSS COMPILER: -
It means being in one environment you are writing a code for another
environment is called cross development. And the compiler used for cross development is
called cross compile
> There are several advantages of using cross compiler. Some of them are described as
follows
> By using this compilers not only can development of complex embedded systems be
completed in a fraction of the time, but reliability is improved, and maintenance is easy.
> Register allocation and addressing mode details are managed by the compiler.
> The ability to combine variable selection with specific operations improves program
readability.
> Keywords and operational functions that more nearly resemble the human thought process
can be used.
26
> Program development and debugging times are dramatically reduced when compared to
assembly language programming.
> The library files that are supplied provide many standard routines (such as formatted
output, data conversions, and floating-point arithmetic) that may be incorporated into your
application.
> Existing routine can be reused in new programs by utilizing the modular programming
techniques available with C.
> The C language is very portable and very popular. C compilers are available for almost all
target systems. Existing software investments can be quickly and easily converted from or
adapted to other processors or environments.
> Now after going through the concept of compiler and cross compilers lets we start with
Keil C cross compiler.
> Simulator
> Debugger
> Keil Software provides you with software development tools for the 8051 family of
microcontrollers. With these tools, you can generate embedded applications for the multitude
of 8051 derivatives.
> The keil 8051 tool kit includes three main tools, assembler, compiler and linker.
> A compiler is used to compile your C source code into an object file
27
> A linker is used to create an absolute object module suitable for your in-circuit emulator.
8051 project development cycle: - these are the steps to develop 8051 project using keil
To open keil software click on start menu then program and then select keil2 .You can see
three different windows on the screen. 1) project work space window 2) editing window 3)
output window. Project workspace window is for showing all the related files connected with
your project.
Editing window is the place where you will edit the code
Output window will show the output when you compile or build or run your project.
• Give the name of project as "test". By default it will be saved as *.v2 extension.
• Now you will be asked to chose your target device for which you want to write the
program.
• Scroll down the cursor and select generic from list. expand the list and select 8051
When you click OK, you will be asked to add startup code and file to your project folder.
click yes. Now on your screen expand target1 list fully.
• Now click on file menu and select new file. editor window will open. Now you can
start writing your code.
• As you start writing program in C, same way here also you have to first include the
header file. Because our target is 8051 our header file will be "reg51.h"
28
• If you scroll down cursor you will see that all the SFRs like P0-P3, TCON, TMOD,
ACC, bit registers and byte registers are already defined in this header file. so one can
directly use these register names in coding
• Now you can write your program same as c language starting with void main()
• After completing the code save the file in project folder with ".c" extension.
• Now right click on "source group 1" in project workspace window. select "add files to
source group 1"
• Select the C file you have created and click add button
• you will see that the c file has been added in source group
• Now to compile the program from project menu select "build target". In the output
window you will see the progress
• If there is any compilation error then target will not be created. Remove all the errors
and again build the target till you find "0 Error(s)"
• Now you are ready to run your program. from debug menu select "start/stop debug
session"
• You will see your project workspace window now shows most of the SFRs as well as
GPRs r0-r7. Also one more window is now opened named "watches". in this window you
can see different variable values.
• If there is any compilation error then target will not be created. Remove all the errors
and again build the target till you find "0 Error(s)"
• Now you are ready to run your program. from debug menu select "start/stop debug
session"
• You will see your project workspace window now shows most of the SFRs as well as
GPRs r0-r7. Also one more window is now opened named "watches". in this window you
can see different variable values.
29
KEIL WORK SPACE
• To add variable in watch window go to "watch#1" tab. then type F2 to edit and type
the name of your variable
• If you want to see the output on ports go to peripheral menu and select I/O ports.
Select the desire port. you can give input to port pins by checking or unchecking any check
box. Here the check mark means digit 1 and no check mark means 0. the output on the pin
will be shown in same manner
• to run the program you can use any of the option provided "go", "step by step", "step
forward", "step over" etc.
30
• Now after testing your program you need to down load this program on your target
board that is 8051. for this you have to create hex file
• To create hex file first stop debug session. Again you will be diverted to project
workspace window.
• Right click on "target 1" and select "option for target 1". Following window will
appear.
31
5. SOURCE CODE
#include <AT89X52.H>
#include <smcl_lcd.h>
void ser_init();
void ser_out(unsigned char);
void ser_conout(unsigned char*,unsigned char);
void main()
lcd_init();
ser_init();
ser_out('A');ser_out('T');ser_out(0x0d);del();
ser_conout("AT+CMGF=1",9);ser_out(0x0d);del();
ser_conout("AT+CPMS=",8);
ser_out('"'); ser_out('S'); ser_out('M'); ser_out('"');
ser_out(0x0d); del();
i=1;
status=ES=0;
ser_conout("AT+CMGR=1",9);
ser_out(0x0d);
EA=ES=1;
del();del();
ES=0;
if(i>65)
{
for(k=60; k<=70; k++)
{
32
}
if(v[k]=='2' && v[k+1]=='o' && v[k+2]=='n') {status=3; goto end;}
if(v[k]=='2' && v[k+1]=='o' && v[k+2]=='f' && v[k+3]=='f') {status=4; goto end;
}
if(v[k]=='3' && v[k+1]=='o' && v[k+2]=='n') {status=5; goto end;}
if(v[k]=='3' && v[k+1]=='o' && v[k+2]=='f' && v[k+3]=='f') {status=6; goto end;
}
if(v[k]=='4' && v[k+1]=='o' && v[k+2]=='n') {status=7; goto end;}
if(v[k]=='4' && v[k+1]=='o' && v[k+2]=='f' && v[k+3]=='f') {status=8; goto end;
}
}
status=0;
end:
if(status)
{
command(0xc0);
write(v[k]);write(v[k+1]);write(v[k+2]);write(v[k+3]);
}
ser_conout("AT+CMGD=1",9);
ser_out(0x0d);
del();
i=1;
}
if(status==1) light=0;
else if(status==5) tv = 0;
else if(status==6) tv = 1;
}
}
void ser_init()
{
EA=1;
ES=1;
SCON = 0X50;
TMOD = 0X20;
TH1 = 0XFD;
33
TR1 = 1;
EX0 = 1; IT0=1;
}
}
}
34
5.1 FLOW CHART
If
END
35
To initialize the Microcontroller Registers
Ser _init
TR1=1; // timer on
EX0=1;IT0=1;
END
Ser_out
SBUF = val; // single data transmit to mobile function using SBUF register
delay(500);
SCON = 0X50;
delay(8000);
END
36
Ser_conout
Unsigned character i;
for(i=0;i<ln;i++)
{
ser_out(dat[i]);
ENDS
6. ADVANTAGES,DISADVANTAGES&APPLICATIONS
37
6.1ADVANTAGES
2. Low Cost
6.2 DISADVANTAGES
6.3 APPLICATIONS:
4. In Home Appliances such as Water Heaters, Room Heaters and Air conditioners.
38
7.1 RESULT
In this project we interfaced Mobile and Microcontroller with the help of RS232
level converter and controlled the operation of four devices(LED’S) using four Relay circuits
by sending an SMS to the mobile which is interfaced to the Microcontroller. We used two
mobiles for transferring the message using GSM Technology. Only mobiles with AT
commands can be interfaced with the controller.
7.2 CONLUSION
Power can be saved by controlling the machines ‘on’ and ‘off’ condition with a
single SMS. This project can be further enhanced by connecting batteries to the power supply
in case of power cut. Further an acknowledgement from the machine on its ‘on’ and ‘off’
condition by modifying the code can be done.
8. REFERENCES
39
1. Using SMS in Mobile Phone for Home Appliances Controlling Through PC Parallel Port
Interfacing by Fadhil T. Aula, University of Salahaddin, College of Engineering, and
Electrical Engineering Department. Erbil, Iraq
2. SMS Based Wireless Home Appliance Control System (HACS) for Automating
Appliances and Security by Malik Sikandar Hayat Khiyal, Aihab Khan, and Erum Shehzadi
Software Engineering Dept., Fatima Jinnah Women University, Rawalpindi, Pakistan.
3. System integration of WAP and SMS for home network system by Chi-Hsiang Wu and
Rong-Hong Jan Department of Computer and Information Science, National Chiao Tung
University, 1001 Ta Hsueh Rd., Hsinchu 30050, Taiwan.
5. SMS remote control system for household appliances based on GR47 by WU Zhi-hui,
CHEN Long-dao, YE Qiang (College of Electrical Engineering, Zhejiang
University, Hangzhou 310027, China).
8. The 8051 Microcontroller and Embedded Systems by Mazidi and Mazidi,PHI, 2000.
40