Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

Interfacing GSM/GPRS Modem with PIC Microcontroller – Flowcode

Interfacing GSM/GPRS Modem with PIC Microcontroller – Flowcode

Controlling and Monitoring devices with a Cellphone

Figure 1: Controlling and Monitoring devices with a Cellphone

A GSM modem is a wireless modem that works with a GSM wireless network. GSM stands for Global System for Mobile communications, this architecture is used for mobile communication in most of the countries in the world. 

A wireless modem acts basically like the traditional dial-up modem, the main difference is that a dial-up modem sends and receives data through a fixed telephone line while a wireless modem sends and receives data through radio waves. Besides the dial-up connection, GSM modem can also be used for sending and receiving SMS which is also one of the key features of GSM modem.

Some modems are GSM/GPRS modems, these modems additionally support the GPRS technology for data transmission. GPRS stands for General Packet Radio Service. It is a packet-switched technology that is an extension of GSM. A key advantage of GPRS over GSM is that GPRS has a higher data transmission speed.

The operation of a GSM modem requires a SIM (Subscriber Identity Module) card just like mobile phones to identify a subscriber to the cellular network and to store the subscriber information. Also they have IMEI (International Mobile Equipment Identity) number similar to mobile phones for their identification. 


  • Remote System Monitoring: In a remote system monitoring application, a Microcontroller for example could be used to constantly monitor the status of a remote sensors, let say temperature or moisture sensors. If a certain condition is reached, the program will send an SMS to notify the situation, if these sensors are installed in a farm for example, the farmer could be notified of any situation happening in the farm about heat, moisture, drought, etc.
  • Home Alarm System: When a motion sensor detects a movement of an intruder, an SMS will be sent to a predefined number which could be you or your security reaction company and a siren or any other sound device could be triggered in the process as well.
  • Remote Controlling System: A mobile phone can be used to Send an SMS to switch ON/OFF remote devices. You could control your entire home devices, switching ON/OFF lights, fans, pool motor, garage motor and so on with just a simple SMS from a distance.
  • Security Access Control: A security access can be implemented at apartments or housing complexes. A security guard could inform by intercom a resident if he/she has a visitor at the main gate. with a replied SMS, the resident could open remotely the gate for his/her visitor.
  • Vehicle tracking: A GSM/GPRS module together with a GPS module can be used to create a real time vehicle tracking device. An SMS could also be sent to notify that the car has entered a restricted area, notify about the level of remaining fuel in the car etc. If the vehicle is stolen not only the system can indicate the location of the vehicle but an SMS could also be sent to switch OFF the engine.
  • SMS Gateway: To send and receive SMS for advertisements.
  • Pre-paid Electricity: The customer can recharge pre-paid electricity by sending an SMS with a recharge coupon to a pre-paid electricity recharge server.

GSM Connection

It is very easy to interface a GSM Modem to a PIC Microcontroller as most GSM modems have a serial interface. The USART serial input pin RX and TX of the microcontroller are connected to the TXD and RXD pins of the GSM Modem. Some GSM modems have PCMCIA Type II or USB interfaces. Figure 2 below shows a block diagram of a GSM module connected to USART module of a PIC Microcontroller.

GSM module connected to a PIC Microcontroller

Figure 2: GSM module connected to a PIC Microcontroller

NB: Depending from the type of serial port on the Microcontroller hardware, a level translator circuit may be needed to make the system work. If the Microcontroller USART voltage level is 5V as in most of the cases, most the GSM/GPRS modems USART voltage level is about 2.8V – 3V, you need a voltage level translator circuit. A simple diodes/resistors network could do the job as shown on figure 3 below.

Three diode in series are used to drop down voltage of TX pin of microcontroller to to 2.9 volt (each diode drops 0.7V) which is in acceptable range for RXD pin of gsm module. Similarly a diode, a resistor and 5 volt source is used to increase voltage of TXD pin of GSM module to 5 volt which is logic high for RX pin of pic microcontroller.

Figure 3: A simple diodes/resistors voltage level translator circuit

>>> To learn more on Serial Communication: PIC Microcontroller Communication with RS232 Bus

There are GSM board on the market  that one can use to quickly interface to a PIC. The SmartGM862 Board from Mikroelekronika and the E-blocks GSM board from Matrix Technology Solutions are just a few examples of many boards. The SmartGM862 is a full-featured development tool for Telit GM862-QUAD GSM/GPRS module or the GM862-GPS version. It features GM862 module connector, voltage regulator, antenna holders, speaker and microphone screw terminals and more. DIP switch is provided for configuring UART communication lines with the target microcontroller. It can be connected to development boards via IDC10 connector.

Connecting the SmartGM862 Board to EasyPIC7 V7 Development Board

Figure 4: Connecting the SmartGM862 Board to EasyPIC7 V7 Development Board

The E-blocks GSM board allows easy access to the mobile phone GSM/GPRS networks. The on board GSM/GPRS module can be used to make or receive wireless voice calls and is also capable of sending and receiving SMS text messages. The GSM/GPRS E-block comes complete with on board PCB antenna, SIM card socket, 2.5mm audio jacks for MIC and Headphone audio connection and LED to display the network connection status.

The E-blocks GSM board

Figure 5: E-blocks GSM board

GSM Commands

The AT commands are used to control modems which are communicated through serial communication with a microcontroller or a PC. AT is the abbreviation for ATtention. These commands come from Hayes commands that were used by the Hayes smart modems in late 1970s. The Hayes commands started with AT to indicate the attention from the MODEM followed by a number of characters specifying the command tail.

AT commands with a GSM/GPRS MODEM or mobile phone can be used to check the modem settings, to change the modem settings, to issues commands like to send an SMS, read an SMS and so on.

Below is a short list of commonly used general purpose AT commands. The command should be followed by a carriage return :

  • ATI: Modem product information
  • ATE0: Disable echo so that characters typed by the user are not echoed back by the modem.
  • ATE1: Enable the echo mode
  • AT+CMGF: Select SMS message format
  • AT+CMGS: Send SMS message
  • AT+CMGR: Read SMS message

For more info, you can check your modem datasheet or the AT Commands Reference Guide     

Flowcode provides a component for GSM communication. The GSM component is designed to be used with any GSM device that accepts standard GSM AT commands.  

GSM Component

             Figure 6: GSM Component.

To insert a GSM component, on the components tool bar click on GSM under the Misc group. A GSM component (GSM(0)) will be inserted on the panel.

Inserting a GSM component

Figure 7: Inserting a GSM component

Select the GSM component then click on the “….” next to the Ext Properties to edit the GSM properties.

GSM Properties General Tab

Figure 8: GSM Properties General Tab

General Tab:

In this tab we can set the number of scripts used (the default is 4), we can choose to either use the built in UART module and select the UART channel to use as some microcontrollers have more than one UART modules. If software mode is ticked, than any pin of the microcontroler could be use. The Transmit and receive pins will be set using the component Connection properties.

Scripts Tabs:

Depending on the number of scripts selected, they will be a different tab for each script. The Script pages enable a number of commands to be placed into a single place allowing them to be sent as one. Text can be entered directly into the Script Text box. To add a Carriage Return (the Enter  button) whilst typing in the box press Control+Enter. Figure 8 below shows two AT Commands  in Script 1 tab.

GSM Properties General Tab

Figure 9: GSM Properties Scripts Tabs

Select the GSM component then click on the “….” next to the Connections Properties to edit the GSM Connections properties.

Figure 10: GSM Connections

If the Hardware UART mode is selected in the Ext Properties, than only the optional CTS and RTS pins can be set if Flowcontrol is selected. The Tx and Rx pins are assigned automatically with Flowcode. If Software UART mode was selected, than the TX and RX pins should be set as well.

 Component Macros

Drag and drop the Component Macros from the Icons toolbar.

Component Macro

Figure 11: Component Macro

Double click the component macro to open its properties. Click on the GSM(0) to see its macros.
The GSM component has the following macros as shown in figure 11 below:

Figure 12: GSM Component Macros

Initialize ( )

This macro Initializes the GSM component ready for use. It is recommended that you place the Initialize macro at the start of a program to ensure the component is initialized before being used.

CheckNetworkStatus ( )

Checks to see if the GSM module is correctly registered on the network.

Returns 1 if the GSM is connected to the network.

Returns 0 if the GSM is not connected to the network.

Figure 12 below shows how this macro could be used in a while loop to wait until the GSM module has correctly registered to the network.

Check Network Status

Figure 13: CheckNetworkStatus Macro

SendCommand ( )

This macro is used to Sends an AT command string to the GSM module. A carriage return can also be included if need. The bSendCR is used for it. A value of zero = Nothing and 1 = Appends a carriage return character onto the end of the command string. Figure 13 below send the “ATE0” command to disable the echo. At the end of the command, a carriage return is also sent.

SendCommand Macro

Figure 14: SendCommand Macro

StringReceive ( )

This macro Receives a response string from the GSM module. A string variable has to be declare to store the received string.

SendScript ( )

This macro is used to Send one of the AT command scripts. Fast way to send multiple commands to the GSM module.

idx = is the index number of the script tab. If commands in script 1 (Script tab 1) are to be sent, than idx will be 1. The macro will return 0 for a successful transaction or 255 for a failed transaction.

CheckForIncoming ( )

This macro Checks for an incoming unsolicited message such as an incoming call or text.

Returns 0 for no incoming message detected.

Returns 1 for an incoming text message.

Returns 2 for an incoming phone call.

DialNumber ( )

Dials the number specified by the Number string as a voice call.

Returns 0 if the command was accepted.

Returns 255 if the command was rejected for example if the GSM unit is not connected to the network.

HangUpCall ( )

Hangs up an active voice call.

Returns 0 if the command was accepted.

Returns 255 if the command was rejected for example if the GSM unit is not currently in a call.

AnswerIncomingCall ( )

Answers an incoming voice call.

Returns 0 if the command was accepted.

Returns 255 if the command was rejected for example if the GSM unit is no longer being called.

SendTextMessage ( )

Sends out a SMS text message.

Number – Phone number string to send message to.

Message – Contents of the message you wish to send.

Returns 0 if the command was accepted.

Returns 255 if the command was rejected for example if the GSM unit is not connected to the network.

Figure 14 below shows the SendTextMessage macro sending a “Hello World!” message to 0123456789 phone number.

SendTextMessage macro

Figure 15: SendTextMessage Macro

ReadString ( )

Returns the received data from the last incoming data message or command acknowledge.

GetTextNumber ( )

Reads the sender phone number of an incoming text message when detected by the CheckForIncoming macro. Returns the phone number as a string.

GetTextString ( )

Reads the contents of an incoming text message when detected by the CheckForIncoming macro. Returns the contents of the message as a string.

Share this post

Select your currency
EUR Euro
USD United States (US) dollar