In any case, the communication between Arduino and GSM module is serial. So we are supposed to use serial pins of Arduino (Rx and Tx). So if you are going with this method, you may connect the Tx pin of GSM module to Rx pin of Arduino and Rx pin of GSM module to Tx pin of Arduino. Serial GSM modem over TCP/IP. A very reliable way to use a serial GSM modem on a server that has no serial port is with a TCP/IP to RS232 convertor. An extra advantage is that the actual GSM modems can be placed anywhere in the network, even on remote locations.
In this tutorial we will learn how to interface GSM Modem and send SMS. GSM Modems are easy long range interface where we need to read sensor data or control electrical equipment. We will start with selection of GSM modem, AT commands and connection of GSM Module with Arduino. A GSM modem is a specialized type of modem or phone hardware on small PCB which accepts a SIM card, and operates over a subscription to a mobile operator, just like a mobile phone.
What you will learn?
- Which GSM Modem should I use?
- How to connect GSM Modem with Arduino?
- How to send SMS using GSM module using Arduino?
Selection of GSM Modem
GSM modem are selected based on price, interface required and size. You can find detailed explanation here.We will not go deep into selection process. We are using SIM900A GSM Modem for this tutorial.
Connection of GSM Modem with Arduino Uno
![Router Router](/uploads/1/2/6/3/126346129/766882745.jpg)
Connecting GSM modem with arduino is very simple just connect RX Line of Arduino to TX Line of GSM Modem and vice versa TX of arduino to Rx of GSM modem. Make sure use TTL RX, TX lines of GSM modem.
Give 12V 2Amp power supply to GSM modem, Use of less current power supply can cause reset problem in GSM modem, give sufficient current to GSM modem.
Arduino Code for Sending SMS using GSM Modem
SMS Sending Code Arduino
2 4 6 8 10 12 14 16 18 20 22 24 26 | // circuits4you.com voidsetup() Serial.begin(9600);//Initialise serial to communicate with GSM Modem { delay(10000);//Give enough time for GSM to register on Network while(1);//Wait forever { Serial.println('AT+CMGF=1');//To send SMS in Text Mode Serial.println('AT+CMGS='+9198xxxxxxxx'r');//Change to destination phone number Serial.println('Hello from GSM Modem!');//the content of the message Serial.println((char)26);//the stopping character Ctrl+Z } |
Code is kept very simple we are using we are using few AT commands to send the SMS. every AT command ends with Carrige return. Always use Serial.println.
- AT+CMGF=1 set the GSM modem in text mode.
- AT+CMGS=”+9198xxxxxxxx” Send SMS to this number
- Message text
- Message closing character Control+Z. (char(26))
Note: While Programming Remove GSM Modem serial lines. You can use software serial also.
Testing of Code
- Insert the sim card.
- Upload Code with removed RX,TX lines.
- After uploading power off and connect RX,TX Lines.
- Turn on Both Arduino and GSM Modem.
- Wait for few seconds and see the blinking of network LED slows down. It means it is registered on network.
- You will receive SMS after 15 Seconds. If it takes too long to register on network in crease the 10 Second delay to larger value.
- For queries comment below.
- To use GSM Modem with Other microcontroller use this tutorial this.
In this tutorial you learned how to interface GSM Modem and send SMS. Its very simple but need to take care of Power supply current requirements, and Serial interface voltage levels USART(TTL) or RS232.
Related
ReferenceLanguage | Libraries | Comparison | Changes
GSM library
The GSM library is included with Arduino IDE 1.0.4 and later. With the Arduino GSM Shield, this library enables an Arduino board to do most of the operations you can do with a GSM phone: place and receive voice calls, send and receive SMS, and connect to the internet over a GPRS network. The GSM shield has a modem that transfers data from a serial port to the GSM network. The modem executes operations via a series of AT commands. The library abstracts low level communications between the modem and SIM card. It relies on the Software Serial library for communication between the moden and Arduino. Typically, each individual command is part of a larger series necessary to execute a particular function. The library can also receive information and return it to you when necessary. To use this library #include <GSM.h> Library structureAs the library enables multiple types of functionality, there are a number of different classes.
Ethernet library compatibilityThe library tries to be as compatible as possible with the current Ethernet library. Porting a program from an Arduino Ethernet or WiFi library to an Arduino with the GSM Shield should be fairly easy. While it is not possible to simply run Ethernet-compatible code on the GSM shield as-is, some minor, library specific, modifications will be necessary, like including the GSM and GPRS specific libraries and getting network configuration settings from your cellular network provider. ExamplesThere are two groups of examples for the GSM shield. There are examples to illustrate the possibilities of the shield, like how to send SMS messages and connect to the internet. There is also set of example tools that you can use to debug the functionality of the library and the hardware at lower level.
For additional information on the GSM shield, see the Getting Started page and the GSM shield hardware page. Last revision 2019/12/24 by SM | GSM classThis class prepares the functions that will communicate with the modem.
GSMVoiceCall classEnables voice communication through the modem. A microphone and speaker need to be added for full use.
GSM_SMS classFacilitates sending and receiving Short Message Service (SMS) messages.
GPRS classThis class is responsible for including the files that are part of the library that involve TCP communication.
GSMClient classThe client class creates clients that can connect to servers and send and receive data.
GSMServer classThe Server class creates servers which can send data to and receive data from connected clients (programs running on other computers or devices).
GSMModem classThe GSMModem class facilitates diagnostic communication with the modem.
GSMScanner classThe GSMScanner class provides diagnostic information about the network and carrier.
GSMPIN classThe GSMPIN class has utilities for communicating with the SIM card.
GSMBand classThe GSMBand class provides information about the frequency band the modem connects to. There are also methods for setting the band.
|
Corrections, suggestions, and new documentation should be posted to the Forum.
The text of the Arduino reference is licensed under aCreative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.