Control and Monitor via SMS

By WW Kong (RH2T Magazine Vol.7, Dec10)

In volume 5, we discussed about Smart Home technology. One of the features of Smart Home is that we can control the household appliances and monitor the condition of our house remotely by just using a mobile phone. This is no rocket science and can be easily achieved by using a GSM modem.

1.0 Introduction

GSM modem is specialized type of modem that operates over subscription based wireless networks which is similar to a mobile phone. A GSM modem accepts a SIM card, and basically acts like a mobile phone for the computer. Traditional modem is attached to computers for ‘dial-up’ to connect with other computer systems. A GSM modem operates in a similar fashion, except that it sends and receives data through radio waves rather than a telephone line.

  • 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. In this issue, we discuss on how to set up a simple home automation where we can control the fan and monitor the alarm status by using SMS. All the examples given are based on the MOD 9001D GSM Modem available from Cytron Technologies. The User’s Manual and GSM modem command set can be obtained from the product page here. Some of the features of this GSM Modem are as follow:
  • · RS-232 Interface
  • · Tri-Band: GSM900, GSM1800 and GSM1900
  • · Support TCP/IP
  • · Support standard extended open AT commands
  • · Support GPRS class 10
  • · Accept supply voltage from 5 to 12V
  • · Support PDU and Text mode for SMS

clip_image001clip_image002clip_image003

MOD 9001D RS232 GSM/GPRS Modem from Cytron Technologies

 

2.0 Quick Start – Interfacing GSM Modem with PC

In order to get familiar with the AT commands, we can hook up the GSM modem to the PC serial port to test the functionality of the GSM Modem. Hyper Terminal is used to send the AT command to and from the modem.

 

2.1 Sending SMS

1. Insert a valid SIM card from any mobile provider into the SIM slot.

2. Connect the GSM Modem to the supplied AC-DC adapter and also to the serial port of the PC.

3. Select the correct COM Port in Hyper Terminal and set up the parameters as follows.

clip_image005

4. Power on the GSM Modem and wait for it to initialize. While waiting, we can use the following command to make sure we can communicate with the GSM Modem.

clip_image006

The GSM Modem should respond with “OK”.

5. Once it’s ready, the following response will be received from the modem.

clip_image007

6. Now we can start sending the AT command to the GSM Modem. Start by configure the modem to use Text Mode instead of PDU mode for the SMS. This mode allows us to send SMS using AT commands without the need to encode the binary PDU field of the SMS. Use the following command to put the modem in text mode and it should respond with “OK”.

clip_image008

7. After that, we can send the SMS message with the following command:-

clip_image009

Replace the above phone number with your own number. The modem will respond with:-

clip_image010

We can now type the message and send the message using the <CTRL+Z> key.

clip_image011

After few seconds, the modem will respond with the message ID of the message, indicating that the message has been sent correctly.

clip_image012

clip_image014

AT Commands to send a SMS

 

2.2 Receiving SMS.

1. Set up the GSM Modem following step 1 – 6 in the previous section.

2. Once the GSM Modem is ready, we can use a mobile phone to send a SMS to the modem.

3. The following response received from the modem indicates a new SMS is received.

clip_image015

The last character indicates the memory index number, we use this index to read or delete this message. In this case, the index number is 1.

4. To list out all the available SMS in the SIM card, we can use the following command:

clip_image016

And the modem will respond with a list of SMS messages in the SIM card.

clip_image017

The responding messages are formatted like this:-

+CMGL: <index>,<status>,<from_address>,<mr>,<scts><CRLF><data>

· Index – The memory index number, use this index to read or delete this message.

· Status – The status of this message. There might be “REC READ” or “REC UNREAD” for received messages depending on whether the messages have been read or listed before.

· from_address – The subscriber number of the sender.

· mr – The reference number of this message. Most modems keep this field empty.

· Scts – The time when the message is forwarded to this phone or modem.

· data – The actual message data in plain text.

5. To read a single message, we have to use the read command. We must first know the index of the message. For instance, to read the message on memory location 1, we use

clip_image018

The modem will respond as follows:-

clip_image019

Please note that the status of the message is now “REC_READ” instead of “REC_UNREAD” because we have read the message.

6. Once we have read a message, we can free the memory by deleting the message from the storage. For instance, to delete the message on memory location 1, we use:

clip_image020

The modem will delete the message and return to “OK”.

clip_image022

AT Commands to read and delete a received SMS

 

3.0 Interfacing GSM Modem with MCU

After having the basic idea on how to use a GSM modem for sending and receiving SMS, we can now start to make a mini project – GSM Enabled Smart Home. In this project, we use the SK40C together with PIC16F877A as the main controller. The onboard LED will act as the lighting in the house and the push button is the alarm status. This main controller is connected to the GSM modem via a MAX232 circuit as shown in the schematic below. Don’t forget to short the DSR and DTR, also the CTS and RTS, those are pin required for hand-shacking. Without shorting these pairs of pin, your system might not work as expected.

clip_image024

Schematic for interfacing the SK40C with a GSM modem

clip_image025

Components for GSM Enabled Smart Home

Before we go further to discuss the coding part, let’s take a look at how this thing works.

When the SK40C is turned on, we need to wait until the GSM modem to initialize and “Ready” to be shown on the LCD.

clip_image026

“Ready” will be shown when the GSM modem has been initialized.

When SW1 on SK40C is pressed, it will send a SMS i.e. “Warning: Switch 1 has been triggered!” to the owner’s mobile phone.

Switch to SMS SMS will be sent to the mobile phone when SW1 is triggered

· The owner can also control the LED on the SK40C. To turn on the LEDs, type “on” and send the SMS to the GSM modem. Type “off” to turn off the LEDs.

OFF LEDs ON LEDs The LEDs can be turned on/off by sending SMS

 

4.0 Firmware

In this section, we will look at the firmware to interface with the GSM modem. Only the important parts will be discussed. The full working source code can be downloaded from here.

Let’s start with two of the most important functions in this example. The first one is the function to send an AT command to the GSM modem and the second one is to read a line of string from the modem.

clip_image035

Function to send an AT command to the GSM modem

clip_image036

Function to receive a line of string from the GSM modem.

Right after powering up the SK40C, we need to initialize the GSM modem and wait until the “Call Ready” string is received from the modem. We need to make sure that we power up the GSM modem first so that it’s ready to communicate when we turn on the SK40C. The following figure is the code snippet to initialize the GSM modem.

clip_image037

Code snippet to initialize the GSM modem

If the GSM modem has been set up successfully, “Ready” will be shown on the LCD. Now the program is waiting for the user input either from the push button or the SMS. If SW1 is pressed, the following code will be executed to send an SMS to notify the house owner. Please remember to change the highlighted number to your own mobile number.

clip_image038

Code snippet to send a SMS to the house owner when SW1 is triggered

If there is a new SMS received by the GSM modem, the program will read the content of the SMS and turn on/off the LEDs accordingly.

clip_image039

Code snippet to read a SMS and turn on/off the LEDs accordingly

4.0 Conclusion

In short, GSM modem makes remote controlling and monitoring possible without needing long range wireless transceiver provided the GSM modem is located within the coverage area of any mobile provider. Besides smart home, GSM modem is also widely used together with the GPS module as a security system for automobile. When the car is stolen, the GSM modem can send the GPS location of the car to the owner and the owner can shut off the engine of the car by just sending a SMS. If you face any problem, please do come to our technical forum to discuss.

Buy

, , , , , ,

Related Post

Control and Monitor via SMS Part 2

Raspberry Pi: GUI with a Remote Desktop Connection

Simple steps to control Stepper Motor using 2Amp Motor Driver Shield and CIKU

PIC16F VS PIC18F:Analysis of PIC Mid-Range 8 bit family and Advanced 8-bits Family

34 thoughts on “Control and Monitor via SMS

  1. I’ve made this project using the coding and circuit provided but didnt have the same result. The GSM is not responding. It dont even get the “Error…” string. Its just say Testing Com… Can u help me?

  2. I also have try using the same code and the same configuration.. but my gsm modem is not responding also. my phone not receiving any message. can help me with this? thx

  3. First i think it would be go to use serial communication to tag the signal to see what is transmitted and received in the GSM modem. We could also directly control it using the serial port.

  4. why does the modem did not reply “OK”?is there something wrong with the code?or is it because of my modem?

  5. You might need to check the setting? Please do discuss in our technical forum as we seldom check the comment space in tutorial, sorry.

  6. Please do discuss in our technical forum where you can share your hardware setup and code. We seldom check the comment space in tutorial site, sorry.

  7. hi i try to make this project but there is no response the lcd shows testing com… message only iam using GSM-2303R(INDUSTRIAL GSM MODEM) and i made the circute as in the pic above can u help me

  8. HyperTerminal is terminal software which come with Windows, but Win 7 does not have it. You can use any Terminal software you prefer, example: X-CTU, Arduino serial monitor, RealTerm, PuTTy.

  9. who can give me the coding
    my project automatic db
    when elcb trip, gsm will send the message to my phone
    i use max232,pic16f877a,gsm,no lcd
    please thank

  10. I tried to change the default baud rate but the modem reset back to original setting after power off, may i know is there any AT instruction i missed out in order to change the “default baud rate” ?

    i am using AT+IPR=, i.e. AT+IPR=2400

  11. Charles:

    I’m afraid that you can’t store any setting permanently. Everything will be reset to default value after you power off the GSM modem. Thus you need to reinitialize it every time you turn it on.

  12. Hi,

    Just checking with you, is it possible if i replace the RS232 SIM900 with GSM TC35? if possible, how would be the connection of the circuit?

  13. Hi,

    May i know how long the circuit will testing the communication with the GSM? This is because i wait almost an hour but never shown ready. Please guide.

  14. hi i have tried to reach you in technical fourm but i wasnt succes, any way can you please tell me what is the size of your crystal on sk40 you using, because as other guy i only get to point of test com and nothing is happening, i think you forgot to mention what crystal we have to use because this is very important to connect to gsm. tanx

  15. TAnx for fast reply, I’m using same 20MHz, I’m doing it with olimex board using pic16f877a and I have checked all my setting and the burd rate, but still not pacing the test comm, it just dies in there , any suggestion please? I really like to run this cheers

Leave a Reply

Your email address will not be published. Required fields are marked *