0% found this document useful (0 votes)
108 views10 pages

Design and Development of Microcontroller Based SMS Gateway For GSM Mobile

This document describes the design and development of a microcontroller-based SMS gateway for GSM mobile phones. The system interfaces an Ericsson T68i mobile phone with a PIC microcontroller via serial communication, removing the need for a PC. The SMS packet structure is analyzed for the Grameen Phone network in Bangladesh. The microcontroller-based SMS gateway is implemented using a PIC16F876 microcontroller. It is tested successfully and provides benefits over PC-based SMS gateways by being simpler, smaller, lower power, and more portable.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
108 views10 pages

Design and Development of Microcontroller Based SMS Gateway For GSM Mobile

This document describes the design and development of a microcontroller-based SMS gateway for GSM mobile phones. The system interfaces an Ericsson T68i mobile phone with a PIC microcontroller via serial communication, removing the need for a PC. The SMS packet structure is analyzed for the Grameen Phone network in Bangladesh. The microcontroller-based SMS gateway is implemented using a PIC16F876 microcontroller. It is tested successfully and provides benefits over PC-based SMS gateways by being simpler, smaller, lower power, and more portable.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 10

Design and Development of Microcontroller Based SMS Gateway for GSM

Mobile
Md. Enamul Hoque Chowdhury1, Tanvir Atahary & Md. Shafiuzzaman Khan Khadem
Department of Electronics & Telecommunication Engineering,
University of Liberal Arts Bangladesh, Dhanmondi, Dhaka – 1209
Email: enamul.hoque@ulab.edu.bd, shafiuzzaman.khadem@ulab.edu.bd, tanvir.atahary@ulab.edu.bd

Abstract
In this work, a microcontroller based SMS gateway for GSM mobile has been designed and developed.
Most of the SMS gateway system was controlled by PC based software where microcontroller only used
for controlling and sending status of devices or any appliances connected with the system. An Ericsson
T68i, one of the cheapest GSM mobile phone sets available with most of the advanced features, has been
interfaced with a PC via RS232 serial port. The SMS packet has been analyzed and its different fields
have been identified for the Grameen Phone, the largest GSM operator in Bangladesh. Then the PC has
been removed from the system and the transmission and reception technique of SMS have been
implemented into the PIC microcontroller. The developed system has been tested successfully. The
system is also simple, smarter, portable, cost effective (as the PC has been removed) and low power
consuming.

Introduction
People now in the age of modern science need the real-time information whenever they desire. And this
can be achieved by the various technological advancement of communication system. Introduction of
GSM mobile phone is one of them which is no longer a luxurious item, easily available and accessible
throughout the country and the world even. GSM technology is also most popular due to its portability,
cost-effectiveness and device availability. So, the idea of introducing SMS should be an efficient real-
time approach in any kind of appliance controlling.

SMS encoding and decoding for sending and receiving in mobile communication is usually done by PC
based software where PC is used as an SMS gateway [1]. In that case microcontroller IC plays an
important role in controlling any devices or appliances. Here microcontroller also gets instruction
through SMS and then goes for the next step. The overall system then becomes both costly and power
consuming as the PC works round the clock. If that PC is a clone then may not run for all the time and
power is a matter of availability and cost also.

The serial communication between PC and Mobile uses RS232 protocol. Data in digital form i.e. ‘1’ and
‘0’ for RS232 port are represented by the voltage level of 3V to 25V and -3V to -25V respectively. But
Mobile phones in general use only 3V or 1.8V for its internal communication. Therefore, to make

1
To whom all corresponding should be made
communication between the GSM Mobile and PC a voltage conversion device called MAX232 plays an
important role here [2].

In most of the centralized device-controlling system, PC is interfaced to mobile and then used as a server
to control the devices through the developed software. PC-based-software is easy to develop and control,
so people usually depends on PC. PIC Single-Chip-Microcontrollers are sufficient enough to encode and
decode the sending and receiving message through GSM mobile and control the devices according to the
instruction given by the SMS. PIC microcontroller can also be used as a web-server by removing the
mobile device at the end used part so that user can also control the appliances through the Internet. The
PIC are also less-expensive as well as they need not much energy and have a very good sleep mode. The
development tools (simulator, assembler, linker compiler) for PIC are also very good, available for free
and can be downloaded from Microchip [3].

Data Cable MAX232


USB Serial

(a)

Serial
Data cable

(b)

Figure 1: Block diagram of (a) PC based (b) microcontroller based SMS Gateway

But the resources, documentation and procedure are not available to interface the PIC with GSM mobile.
Therefore in this present work, an attempt has been taken to design a PIC microcontroller based SMS
gateway for GSM mobile system in a well-organized and systematic way so that any one can develop the
interfacing part and design the PIC for SMS gateway to control any appliances or for any other security
purpose. A system has been developed and tested as a prototype for either remote or accessible appliance
controlling. Figure 1 shows the block diagram of (b) the developed PIC based SMS Gateway which
replaces the existing (a) PC based SMS Gateway system for GSM Mobile.

System Architecture, Interfacing & Hardware Configuration:


This system runs on a 28 pins flash-based 8-bit CMOS microcontroller, PIC 16F876 with a 4 MHz
external clock. The chip has up to 8K x 14 words of FLASH Program Memory, 368 x 8 bytes of Data
Memory (RAM) and 256 x 8 bytes of EEPROM Data Memory. It has more I/O capabilities than the other
PIC of this series and also has two PWM which are useful to control any kind of motors speed [3].
The serial RS232 connection is driven by the PIC USART with a high data transmission rate. Data in the
digital form i.e. ‘1’ and ‘0’ for PIC USART are represented by the voltage level of 5V and 0V
respectively. Therefore, to make communication between the GSM Mobile and Microcontroller, no
voltage conversion device is needed.

RS232 serial communication

RS232 is the most known serial port used to interface and transmit the desired data in communication.
Though the serial port is hard enough to program than the parallel port, this is the most effective method
in which the data transmission requires less wire (only three links – transmit, receive and common
ground) that yields the low system cost. The two pins TxD & RxD are used for transmit and receive data
between the communication devices. There are some other lines in this port which are set as default [4].

The data format frame for both the PIC and RS232 protocol has been shown in figure 2. For checking the
RS232 communication between microcontroller and mobile phone, another PC with running hyper
terminal (the Micro Soft standard terminal program) has been used and Mobile has been connected to the
GND, RxD and TxD to the serial port of that PC via a MAX232 voltage conversion IC.

(a)

(b)
Figure 2: Format of data frame for serial communication (a) for PIC (b) for RS-232 I/O.

PIC USART Configuration

USART, Universal Synchronous Asynchronous Receiver Transmitter, also known as Serial


Communications Interface can be configured into two operating mode called synchronous and
asynchronous. In this present work the later one has been used which is accessed through the pins RC6
and RC7 for the PIC 16F876 and RC6 & RC7 act as data transmitter (Tx) and receiver (Rx) respectively
[3].Data is usually transmitted in 8-bit words (9 is an option), with the least significant bit sent first.
Standard clock (baud) rate is used so that the receiver can sample the input at the same rate as the data is
sent. 9600 baud is used in this work, i.e., the bits are transmitted at about 10kbps.

In this mode, the USART uses standard non-return-to zero (NRZ) format (one START bit, eight or nine
data bits, and one STOP bit). The most common data format is 8-bits. An on-chip, dedicated, 8-bit baud
rate generator can be used to derive standard baud rate frequencies from the oscillator. The transmitter
and receiver are functionally independent, but use the same data format and baud rate. To configure a
USART of the PIC; INTCON, PIR1, RCSTA, RCREG, PIE1, TXSTA, TXREG and SPBRG registers are
needed to configure.

Transmitter Configuration

The data is transmitted through the RC6/TX/CK pin from the transmit shift register (TSR) which obtains
its data from the read/write transmit buffer, TXREG. The TXREG register is loaded with data in
software. The TSR register is not loaded until the STOP bit has been transmitted from the previous load.
As soon as the STOP bit is transmitted, the TSR is loaded with new data from the TXREG register (if
available). Once the TXREG register transfers the data to the TSR register, the TXREG register is empty
and flag bit TXIF (PIR1<4>) is set. This interrupt can be enabled/disabled by setting/clearing enable bit
TXIE (PIE1<4>). Flag bit TXIF will be set, regardless of the state of enable bit TXIE and cannot be
cleared in software. It will reset only when new data is loaded into the TXREG register. While flag bit
TXIF indicates the status of the TXREG register, another bit TRMT (TXSTA<1>) shows the status of the
TSR register. Status bit TRMT is a read only bit, which is set when the TSR register is empty [3].

Transmission is enabled by setting enable bit TXEN (TXSTA<5>). The transmission can be started by
first loading the TXREG register and then setting enable bit TXEN. Normally, when transmission is first
started, the TSR register is empty. At that point, transfer to the TXREG register will result in an
immediate transfer to TSR, resulting in an empty TXREG. A back-to-back transfer is thus possible.
CLRC bit (TXSTA<7>) is ignored in asynchronous mode. The baud rate generator produces a clock,
either x16 or x64 of the bit shift rate, depending on bit BRGH (TXSTA<2>).If clock frequency is 4MHz
& BRGH is set and then generated baud rate is less deviated from the required data rate. Parity is not
supported by the hardware, but can be implemented in software (and stored as the ninth data bit) [3].

Receiver Configuration

The data is received on the RC7/RX/DT pin and drives the data recovery block. Once Asynchronous
mode is selected, reception is enabled by setting bit SPEN (RCSTA<7>) & CREN (RCSTA<4>). After
sampling the STOP bit, the received data in the receive shift register (RSR) is transferred to the RCREG
register (if it is empty). If the transfer is complete, flag bit RCIF (PIR1<5>) is set. The actual interrupt
can be enabled/disabled by setting/clearing enable bit RCIE (PIE1<5>). Flag bit RCIF is a read only bit,
which is cleared by the hardware. It is cleared when the RCREG register has been read and is empty. The
RCREG is a double buffered register (i.e., it is a two deep FIFO). It is possible for two bytes of data to be
received and transferred to the RCREG FIFO and a third byte to begin shifting to the RSR register. On
the detection of the STOP bit of the third byte, if the RCREG register is still full, the overrun error bit
OERR (RCSTA<1>) will be set. The word in the RSR will be lost. The RCREG register can be read
twice to retrieve the two bytes in the FIFO. Then the Overrun bit OERR has to be cleared in software.
This is done by resetting the receive logic (CREN is cleared and then set). If bit OERR is set, transfers
from the RSR register to the RCREG register are inhibited, and no further data will be received. It is,
therefore, essential to clear error bit OERR if it is set. Framing error bit FERR (RCSTA<2>) is set if a
STOP bit is detected as clear [3].

Figure 3: Schematic diagram of SMS Gateway System

LCD interfacing
The display is a standard LM020a which displays 4 lines of 20 characters (20×4). Each character is of
5×10 pixels. The display receives ASCII codes for each character at the data inputs (D0–D7). The data is
presented to the display inputs by the MCU, and latched in by the pulsation of the E (Enable) input. The
RW (Read/Write) line can be tied low (write mode), as the LCD is receiving data only. The RS (Register
Select) input allows commands to be sent to the display. RS = 0 selects command mode, RS = 1 data
mode. The display itself contains a microcontroller; the standard chip in this type of display is the Hitachi
HD44780. It must be initialized according to the data and display options required. More details can be
found in the web-site [5].
Microcontroller SMS Gateway
Modern mobile phones are able to send & receive SMS with appropriate AT command originated from
the microcontroller. The microcontroller circuit is used to control and interface hardware devices and the
SMS is generated, received, decoded and displayed through it. The complete system for SMS Gateway
can be setup for many applications. Some of the examples are Smart Home System and Remote Data
Collection System. The SMS Gateway main program is written using PIC Assembly Language which is
assembled using MPLAB 7.60 [3]. The main program communicates to mobile equipment (ME) via
GSM 07.07 protocol [6] is applied to send and receive SMS. Typical ME can be a mobile phone or a
GSM modem with the capability to interface with PIC. In this work, a low cost mobile phone, Ericsson
T68i has been connected to the PIC RS232 serial port via its data cable and a MAX232 voltage converter
IC has been used to have an interface with RS232 serial port of PC for the checking purpose. The system
is initiated by applying a start pulse. An SMS is automatically generated by the system which forwards to
a default number. The main program continuously looks for the arrival of any SMS that is needed to
process. The received SMS is decoded and also displayed to the LCD panel.

Encoding decoding technique of SMS packet


The SMS message can be up to 160 characters long, where each character is 7 bits according to the 7-bit
default alphabet. There are two ways of sending and receiving SMS messages: Text mode and PDU
(protocol description unit) mode. As text mode is unavailable on some phones, the PDU mode is used in
this work. The PDU string contains not only the message, but also a lot of meta-information about the
sender, SMS service centre, the time stamp etc. It is all in the form of hexa-decimal octets or decimal
semi-octets [7, 8]. Figure 4 shows details data format, frame and instruction uses within an SMS packet.

SMS packet

The SMSC Part TPDU Part

Address Length
MSG Type of Address
Length of SMSC Type of Address Service Centre First Octet of Destination
Referen of the
Information of the SMSC Number PDU ce
the destination
destination Number
88 10 17 43 88 39 F0
08 91 88 10 07 00 00 06 F0 11 40 0D 91 88 01 71 34 88 93 0F
88 01 70 00 00 60 0F 8801713488930
8801700000600
Validity
Period User data
PID DCS
length User Data

00 00 A7 0B D4F29C9E769F41D3E614
Testing SMS

Figure 4: Data format and frame of an SMS packet

All the octets in the format as shown in figure 4 are hexa-decimal 8-bit octets, except the Service centre
number, the sender number and the timestamp; they are decimal semi-octets. The message part in the end
of the PDU string consists of hexa-decimal 8-bit octets, but these octets represent 7-bit data. The semi-
octets are decimal, and e.g. the sender number is obtained by performing internal swapping within the
semi-octets from "881007000006F0" to "8801700000600F". The length of the phone number is odd, so a
proper octet sequence cannot be formed by this number. This is the reason why the trailing F has been
added. The time stamp, when parsed, equals "80506202913242", where the first six bytes represent date,
the following six bytes represent time, and the last two represent time-zone related to GMT.

Following table1 shows an example of the technique for encoding and decoding of user data in TPDU
part. The message "Testing SMS" consists of 11 characters, called septets when represented by 7 bits
each. These septets need to be transformed into octets for the SMS transfer.

Table1: Encoding and Decoding technique of user data in TPDU part


Uncompressed message Compressed message
Byte ASCII DEC BINARY BINARY HEX
No. (Septets) (Octets)
1 “T” 84 1010100 1010100 11010100 D4
2 “e” 101 1100101 1100101 11110010 F2
3 “s” 115 1110011 1110011 10011100 9C
4 “t” 116 1110100 1110100 10011110 9E
5 “i” 105 1101001 1101001 01110110 76
6 “n” 110 1101110 1101110 10011111 9F
7 “g” 103 1100111 1100111 01000001 41
8 “” 32 0100000 0100000 11010011 D3
9 “S” 83 1010011 1010011 11100110 E6
10 “M” 77 1001101 1001101 10100 14
11 “S” 83 1010011 1010011

The first septet (T) is turned into an octet by adding the rightmost bit of the second septet. This bit is
inserted to the left which yields 1 + 1010100 = 11010100 ("D4"). The rightmost bit of the second
character is then consumed, so the second character (septet) needs two bits (underlined bold) of the third
character to make an 8bit octet. This process goes on and on yielding the following octets:
The 10 octets from "Testing SMS" are D4 F2 9C 9E 76 9F 41 D3 E6 14

Message Sending & Receiving

The AT (Attention) command protocol is used to communicate over a serial line discipline. The AT
commands are the basic commands that communicate with the GSM mobile phone. Table2 indicates
some common AT commands necessary for SMS transmission and reception. Detailed format of AT
commands are available in mobile phone, T68i developers’ guidelines [9].

Table 2: Some common AT commands for SMS transmission and reception


Command Description
AT(Attention Command) Checks the communication between the phone and any accessory.
AT+CPMS (Preferred Message Selects memory storage spaces to be used for reading, writing, etc.
Storage)
AT+CNMI (New Message Selects the procedure how the reception of new messages from the
Indication to TE) network is indicated to the TE when TE is active.
AT+CMGR (Read Message) Returns messages with location value <index> from preferred
message storage <mem1> to the TE. If the status of the message is
‘received unread’, the status in the storage changes to ‘received
read’.
AT+CMGS (Send Message) Sends message from a TE to the network.
AT+CMSS (Send From Sends message with location value <index> from message storage
Storage) <mem2> to the network
AT+CMGW (Write Message Stores a message to message storage <mem2>. The memory location
To Memory) <index> of the stored message is returned.
AT+CMGD (Delete Message) Deletes message from preferred message <mem1> storage location
<index>.

Testing & Result:


The total system has been designed and a prototype has also been developed based on the flowchart
shown in figure 5. The designed system has been tested whether it responses according to algorithm or
not. A start pulse was generated to initiate the system. The PIC microcontroller issues an AT command to
check whether the connection with mobile is established or not. It executes AT+CPMS command to
select the preferred storage for SMS which is chosen the phone memory. Then the microcontroller
generates the “Testing SMS” which it sends to the default cell number. At the same time it displays the
SMS in the LCD panel. An SMS containing “OK” was then sent back from the default number manually
as an acknowledgement which is read in the microcontroller as a TPDU format
“0891881007000006F0240D91881017257845F200008050620291324202CF25”. Microcontroller then
checks the sender authentication by reading the encoded sender number between the 13 th and 19th octet of
the TPDU part.

Message is then decoded from 30th octet where 29th indicates the length of the PDU. Then microcontroller
decoded the PDU and shows it in LCD which is seen “OK” as expected. The overall procedure indicates
that the developed SMS Gateway system can be used for any kind of pre-defined SMS based controlling
system. A five seconds delay was introduced for successful transmission and reception of SMS. After the
reception of the message, the PIC microcontroller executes it; delete it from the phone memory, to
release the 1st memory location.

Conclusion
Successful completion of the design and testing of the SMS Gateway indicates that the PC as an SMS
gateway can easily be replaced by a PIC microcontroller. Beside this, the additional IC, MAX232, used
for voltage adjustment between the mobile and PC is no longer needed in the proposed micro-controller
based system. It also reduces the complexity and the overall development cost of such a system.
Therefore the system becomes smarter, efficient and portable. In addition, since the microcontroller can
also be configured as a web server, this system can be accessed for controlling various devices in the
remote place through the Internet.

Power ON Start

Read PDU,ctrl-z
Initialize Process
& transmit byte wise
PORTB for LCD interface
Suppress answer from mobile
PORTC<7:6> for USART
Display “Testing SMS”
PORTC<2:1:0> for RS, R/W, E
BAUD rate = 9600
SPBRG = 25; BRGH = 1
8bit, No parity & 1stop bit for Tx/Rx 5 sec Timer
LCD initialization

Read
Save in EEPROM: “AT+CNMI=3,3,0,0,0”,CR,LF
AT,CR,LF & transmit byte wise
AT+CPMS=“ME”,“ME”,“ME”
AT+CMGS=25,CR
AT+CNMI=3,3,0,0,0,CR,LF
Receive data
AT+CMGD=1,CR,LF
& save in GPR byte wise
PDU, ctrl-z

Display “SMS Gateway”


NO Receive
LF?
NO Yes
Start pulse?

Yes Authorize
NO
d?
Read “AT”,CR,LR Yes Display
& transmit byte wise Skip 28 byte & set “Unauthorized”
data length=29th byte
To start
NO Receive
“OK” ?
Decode
NO Complet
Yes
e?
Read “AT+CPMS=“ME”,“ME”,“ME” ”,CR,LF Yes
& transmit byte wise
Display the
received SMS
Read “AT+CMGS=25”,CR
& transmit byte wise
Read
“AT+CMGD=1”,CR,LR
& transmit to delete SMS
NO Receive
“<” ? To start

Yes

Figure 5: Flow chart of the developed system


Reference:
1. A.Y. Al-Zoubi, A.A. Tahat, and O.M. Hasan, “ Mobile virtual experimentation utilizing
SMS”, proceedings of the Fourth IASTED International Conference Communication,
Internet, and Information Technology, October31-November2, 2005, Cambridge, USA

2. Siang, B.K.; Bin Ramli, A.R.; Prakash, V.; Bin Syed Mohamed, S.A.R., “SMS gateway
interface remote monitoring and controlling via GSM SMS”, Telecommunication
Technology, 2003. NCTT 2003 proceedings. 4th National Conference on Volume, Issue 14-
15, Jan.2003 Page(s): 84 – 87

3. MPLAB IDE v7.60 and datasheet of PIC16f876


http://ww1.microchip.com/downloads/en/DeviceDoc accessed on 24 February, 2008

4. Martin P. Bates, “Interfacing PIC Microcontrollers: Embedded Design by Interactive


Simulation”, Publisher: Butterworth-Heinemann, October 2006, ISBN-13: 9780750680288

5. Control a HD44780-based Character-LCD, http://home.iae.nl/users/pouweha/lcd/lcd.shtml


accessed on 12 August, 2008

6. GSM 07.05 TECHNICAL SPECIFICATION, January 1998,Ver 5.5.0


www.ctiforum.com/standard/standard/etsi accessed on 30 September, 2008

7. GSM SMS and the PDU format, http://www.dreamfabric.com/sms accessed on 5 March,


2008

8. Michael Harrington, “Understanding SMS: Practitioner’s Basics”


http://mobileforensics.files.wordpress.com/2007/06/understanding_sms.pdf accessed on 24
February, 2008

9. Mobile PhoneT68i Developers. Guidelines AT Commands Online Reference


http://pupius.co.uk/download/misc/t68i-at-commands.pdf accessed on 30 June, 2008

You might also like