Page 1

Susmita Ghose et al. / (IJAEST) INTERNATIONAL JOURNAL OF ADVANCED ENGINEERING SCIENCES AND TECHNOLOGIES Vol No. 2, Issue No. 1, 091 - 098

Design and Development of Microcontroller Based SMS Gateway for GSM Mobile Susmita Ghose,Md. Shafiqur Rahman, Dilruba Sharmin,Istiak Hussain,T.K.Yousufzai Dept.of Applied Physics Electronics & Communication Engineering University of Dhaka Bangladesh, Dhaka Email:shafiqrahman50&yahoo.com

T

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 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-basedsoftware 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].

ES

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. Index term—Microcontroller, SMS, LCD, PICmicro

IJ

A

I. INTRODUCTION People now in the age of modern science need the realtime 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 are no longer a luxurious item, easily available, accessible, portable, cost-effective and have device availability throughout the country and the world even. 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

MAX232

Data Cable USB

Serial (a)

ISSN: 2230-7818

@ 2011 http://www.ijaest.iserp.org. All rights Reserved.

Page 91


Susmita Ghose et al. / (IJAEST) INTERNATIONAL JOURNAL OF ADVANCED ENGINEERING SCIENCES AND TECHNOLOGIES Vol No. 2, Issue No. 1, 091 - 098

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.

T

A. 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.

ES

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].

(a)

IJ

A

II.

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.

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

B. 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

ISSN: 2230-7818

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

@ 2011 http://www.ijaest.iserp.org. All rights Reserved.

Page 92


Susmita Ghose et al. / (IJAEST) INTERNATIONAL JOURNAL OF ADVANCED ENGINEERING SCIENCES AND TECHNOLOGIES Vol No. 2, Issue No. 1, 091 - 098

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

T

D. 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 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]

IJ

A

ES

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. C. 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 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]. E. 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).

ISSN: 2230-7818

F. 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].

@ 2011 http://www.ijaest.iserp.org. All rights Reserved.

Page 93


ES

T

Susmita Ghose et al. / (IJAEST) INTERNATIONAL JOURNAL OF ADVANCED ENGINEERING SCIENCES AND TECHNOLOGIES Vol No. 2, Issue No. 1, 091 - 098

Figure 3: Schematic diagram of SMS Gateway System

IJ

A

G. 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].

III. MICROCONTROLLER SMS G ATEWAY 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

ISSN: 2230-7818

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. IV.

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 metainformation 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.

@ 2011 http://www.ijaest.iserp.org. All rights Reserved.

Page 94


Susmita Ghose et al. / (IJAEST) INTERNATIONAL JOURNAL OF ADVANCED ENGINEERING SCIENCES AND TECHNOLOGIES Vol No. 2, Issue No. 1, 091 - 098

SMS packet The SMSC Part

Length of SMSC Information

08

TPDU Part

Type of Address of the SMSC

Service Centre Number

88 10 07 00 00 06 F0

91

MSG Referen ce

First Octet PDU

11

40

Address Length of the destination

00

A7

User data length

0B

User Data

T

00

Validity Period

DCS

Destination Number

91 88 10 17 43 88 39 F0 88 01 71 34 88 93 0F 8801713488930

0D

88 01 70 00 00 60 0F 8801700000600 PID

Type of Address of the destination

D4F29C9E769F41D3E614 Testing SMS

ES

Figure 4: Data format and frame of an SMS packet

A

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.

TABLE 1 ENCODING AND DECODING TECHNIQUE OF USER DATA IN TPDU PART

ASCII

1 2 3 4 5 6 7 8 9 10 11

“T” “e” “s” “t” “i” “n” “g” “” “S” “M” “S”

Uncompressed message DEC 84 101 115 116 105 110 103 32 83 77 83

IJ

Byte No.

1010100 1100101 1110011 1110100 1101001 1101110 1100111 0100000 1010011 1001101 1010011

BINARY (Septets)

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:

ISSN: 2230-7818

1010100 1100101 1110011 1110100 1101001 1101110 1100111 0100000 1010011 1001101 1010011

Compressed message BINARY (Octets) 11010100 11110010 10011100 10011110 01110110 10011111 01000001 11010011 11100110 10100

HEX D4 F2 9C 9E 76 9F 41 D3 E6 14

The 10 octets from "Testing SMS" are D4 F2 9C 9E 76 9F 41 D3 E6 14 V. MESSAGE SENDING & RECEIVING The AT (Attention) 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

@ 2011 http://www.ijaest.iserp.org. All rights Reserved.

Page 95


Susmita Ghose et al. / (IJAEST) INTERNATIONAL JOURNAL OF ADVANCED ENGINEERING SCIENCES AND TECHNOLOGIES Vol No. 2, Issue No. 1, 091 - 098

commands are available in mobile phone, T68i developers‟ guidelines [9].

Table 2

S OME COMMON AT COMMANDS FOR SMS TRANSMISSION AND RECEPTION Description Checks the communication between the phone and any accessory. Selects memory storage spaces to be used for reading, writing, etc. Selects the procedure how the reception of new messages from the network is indicated to the TE when TE is active. 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‟. Sends message from a TE to the network. Sends message with location value <index> from message storage <mem2> to the network Stores a message to message storage <mem2>. The memory location <index> of the stored message is returned. Deletes message from preferred message <mem1> storage location <index>.

AT+CMGS (Send Message) AT+CMSS (Send From Storage) AT+CMGW (Write Message To Memory) AT+CMGD (Delete Message)

accessed for controlling various devices in the remote place through the Internet.

IJ

A

ES

V. 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 “0891881007000006F0240D91881017257845F200008050 620291324202CF25”. Microcontroller then checks the sender authentication by reading the encoded sender number between the 13th 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. VI. 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

T

Command AT(Attention Command) AT+CPMS (Preferred Message Storage) AT+CNMI (New Message Indication to TE) AT+CMGR (Read Message)

ISSN: 2230-7818

@ 2011 http://www.ijaest.iserp.org. All rights Reserved.

Page 96


Susmita Ghose et al. / (IJAEST) INTERNATIONAL JOURNAL OF ADVANCED ENGINEERING SCIENCES AND TECHNOLOGIES Vol No. 2, Issue No. 1, 091 - 098

Power ON

Start Read PDU,ctrl-z & transmit byte wise Suppress answer from mobile Display “Testing SMS”

Initialize Process PORTB for LCD interface PORTC<7:6> for USART 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 “AT+CNMI=3,3,0,0,0”,CR,LF & transmit byte wise

Save in EEPROM: AT,CR,LF AT+CPMS=“ME”,“ME”,“ME” AT+CMGS=25,CR AT+CNMI=3,3,0,0,0,CR,LF AT+CMGD=1,CR,LF PDU, ctrl-z

T

Receive data & save in GPR byte wise

Receive LF?

NO

Display “SMS Gateway”

ES

Yes

Authorized?

Start pulse?

NO

Yes

Skip 28 byte & set data length=29th byte

Read “AT”,CR,LR Yes & transmit byte wise

Receive “OK” ?

A

NO

Decode Complete?

NO

IJ

Read “AT+CMGS=25”,CR & transmit byte wise

NO

Display “Unauthorized” To start

Yes

Yes

Read “AT+CPMS=“ME”,“ME”,“ME” ”,CR,LF & transmit byte wise

NO

Display the received SMS Read “AT+CMGD=1”,CR,LR & transmit to delete SMS

To start

Receive “<” ?

Yes

Figure 5: Flow chart of the developed system

REFERENCE 1.

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

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, October31November2, 2005, Cambridge, USA

ISSN: 2230-7818

@ 2011 http://www.ijaest.iserp.org. All rights Reserved.

Page 97


Susmita Ghose et al. / (IJAEST) INTERNATIONAL JOURNAL OF ADVANCED ENGINEERING SCIENCES AND TECHNOLOGIES Vol No. 2, Issue No. 1, 091 - 098

Butterworth-Heinemann, 9780750680288

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

October

2006,

ISBN-13:

Martin P. Bates, “Interfacing PIC Microcontrollers: Embedded Design by Interactive Simulation”, Publisher:

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

8.

7.

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

Michael Harrington, “Understanding SMS: Practitioner‟s Basics” http://mobileforensics.files.wordpress.com/2007/06/unders tanding_sms.pdf accessed on 24 February, 2008

9.

Mobile PhoneT68i Developers. Guidelines AT Commands Online Reference http://pupius.co.uk/download/misc/t68iat-commands.pdf accessed on 30 June, 2008

IJ

A

ES

T

4.

ISSN: 2230-7818

@ 2011 http://www.ijaest.iserp.org. All rights Reserved.

Page 98

13-IJAEST-Volume-No-2-Issue-No-1-Design-and-Development-of-Microcontroller-Based-SMS-Gateway-for-GSM  

Dept.of Applied Physics Electronics &amp; Communication Engineering University of Dhaka Bangladesh, Dhaka Email:shafiqrahman50&amp;yahoo.com...

Read more
Read more
Similar to
Popular now
Just for you