Arduino and Visuino: Send and Receive Text Messages (SMS) With GSM SIM900 Shield From Seeed Studio

by BoianM in Circuits > Arduino

19097 Views, 39 Favorites, 0 Comments

Arduino and Visuino: Send and Receive Text Messages (SMS) With GSM SIM900 Shield From Seeed Studio

578c21484fbade00a9000333.jpeg

One of the essential elements of building IoT project is the ability to connect devices. Wi-Fi and Bluetooth are good low cost choices, but they work only at close ranges, or in hotspot areas. When the device needs to be at a remote location GSM is a good and easy to setup option.

In this Instructable, I will show you how easy it is to send and receive SMS messages over GSM with Arduino.

In the following Instructables, I will also show you how you can connect over GSM to Internet and access servers, and how you can handle voice calls.

Components

578ad32c937ddb0236000101.jpeg
DSC04781.JPG
  1. One Arduino Mega (You can use other boards, but it is best to use a board that has 2 or more serial ports. The project can be modified to use Software Serial, but using a hardware serial is recommended)
  2. One SIM900 based GSM Shield or compatible Shield or Module with installed SIM Card (Picture 2) (I used a Version 1.0 GSM/GPRS Shield from Seeed Studio)
  3. 2 Female-Male jumper wires

Connect the GSM Shield to Arduino

DSC04778.JPG
DSC04742.JPG
DSC04744.JPG
DSC04738.JPG
578c21484fbade00a9000333.jpeg
  1. Remove the jumper Caps from the GSM Shield's RX and TX Selection Jumpers (Picture 1)
  2. Plug the GSM Shield on the top of the Arduino Mega
  3. Connect the Male End of a Male-Female jumper wire (Orange wire) to the RX1 Pin of the Arduino Mega (Pictures 2 and 3)
  4. Connect the Male End of a Male-Female jumper wire (Brown wire) to the TX1 Pin of the Arduino Mega (Pictures 2 and 3)
  5. Connect the Female end of the RX1 wire (Orange wire) to the center pin of the RX Selection Jumper of the GSM Shield (Picture 4)
  6. Connect the Female end of the TX1 wire (Brown wire) to the center pin of the TX Selection Jumper of the GSM Shield (Picture 4)
  7. Picture 5 shows the installed and connected GSM Shield

Start Visuino, and Select the Arduino Board Type

SelectBoardTolsEdited.png
SelectMega.png

To start programming the Arduino, you will need to have the Arduino IDE installed from here: http://www.arduino.cc/ .

Make sure that you install 1.6.7 higher, otherwise this Instructable will not work!

The Visuino: https://www.visuino.com also needs to be installed.

  1. Start Visuino as shown in the first picture
  2. Click on the "Tools" button on the Arduino component (Picture 1) in Visuino
  3. When the dialog appears, select "Arduino Mega 2560" as shown in Picture 2

In Visuino: Set the Speed of the Serial 1 Channel to 19200

SetSerialSpeed1.png
SetSerialSpeed2.png
SetSerialSpeed3.png

The GSM Shield is configured by default for 19200 serial port speed. We need to configure Serial Port 1 for this speed:

  1. In the Object Inspector, expand the "Serial" property, then the "Item[ 1 ]" Sub-Property, and select its "Speed" Sub-Property (Picture 1)
  2. In the Object Inspector, click on the "Down Arrow" button next to the value of the "Speed" Sub-Property (Picture 1)
  3. From the Drop Down list select the "19200" (Picture 2), to change the property value (Picture 3)

In Visuino: Add and Connect GSM/GPRS Serial Component

ComponentGSM.png
ComponentGSMConnect1.png
ComponentGSMConnect2.png
ComponentGSMConnect3.png

We need to add component to control the GSM Module. The Module is controlled through the Serial channel, so we need to connect it. Digital Pin 9 is used to power On/Off the Module:

  1. Type "gsm" in the Filter box of the Component Toolbox, then select the "GSM/GPRS Serial" component (Picture 1), and drop it in the design area (Picture 2)
  2. Connect the "Out" output pin of the GSM1 component to the "In" input pin of the "Serial[ 1 ]" channel of the Arduino component (Picture 2)
  3. Connect the "Power" output pin of the GSM1 component to the "Digital" input pin of the "Digital[ 9 ]" channel of the Arduino component (Picture 3). This pin will turn On/Off the power of the GSM Module

In Visuino: Add, Setup and Connect Text Value Component

ComponentTextValue.png
ComponentTextValueText.png
ComponentTextValueConnect1.png
ComponentTextValueConnect2.png

It takes some time for the GMS Module to initialize. It is nice if we have some indication that the module is ready. For this we will send "GSM Ready" text to the Serial port when the module is ready:

  1. Type "text val" in the Filter box of the Component Toolbox, then select the "Text Value" component (Picture 1), and drop it in the design area (Picture 2)
  2. In the Object Inspector set the value of the "Value" property to "GSM Ready" (Picture 2)
  3. Connect the "Ready" output pin of the GSM1 component to the "In" input pin of the TextValue1 component (Picture 3)
  4. Connect the "Out" output pin of the TextValue1 component to the "In" input pin of the "Serial[ 0 ]" channel of the Arduino component (Picture 4)

In Visuino: Add Short Message Element to the GSM Component, and Then Send Message Function to the Element

ComponentGSMModules.png
ComponentGSMAddSMS.png
ComponentGSM_SMSFunctions.png
ComponentGSM_SMSFunctionsAddSend.png

The GSM component consists of many modules performing different tasks. Since we will use only SMS we need to add only "Short Message" module, and then add one "Send SMS" function to it:

  1. In the Design Area, select the GSM1 component (Picture 1)
  2. In the Object Inspector, click on the "..." button next to the value of the "Module" property of the GSM1 component (Picture 1)
  3. In the Modules editor select “Short Message”, and then click on the "+" button (Picture 2) to add one (Picture 3)
  4. In the Object Inspector, click on the "..." button next to the value of the "Functions" property of the "Short Message" module (Picture 3)
  5. In the Functions editor select “Send SMS”, and then click on the "+" button (Picture 2) to add one

In Visuino: Configure the Send SMS Function, and Connect the Received Message Info to the Serial

ComponentGSM_SMSSendAddressEdited.png
ComponentGSM_SMSSendAddTextPin1.png
ComponentGSM_SMSSendAddTextPin2.png
ComponentGSM_SMSConnect1.png
  1. In the Object Inspector, set the value of the "Address" property of the "Send SMS" element to the phone number where you want to send the message (In my case, to test I entered the number of my SIM card so the module will receive and print the messages that it sends) (Picture 1 - shows a made up number)
  2. In the Object Inspector, select the "Text" property (Picture 2)
  3. Click on the "Pin" button at front of the "Text" property (Picture 2)
  4. From the Drop Down list, select the "String SinkPin" (Picture 3). This will add new "Text" pin to the "Send SMS" function (Picture 4)
  5. Close the Element editor dialogs (Picture 4)
  6. Connect the "Out" output pin of the "MessageInfo" block of the GSM1 component to the "In" input pin of the "Serial[ 0 ]" channel of the Arduino component (Picture 4)

In Visuino: Add and Connect Char to Text Component

ComponentCharToText.png
ComponentCharToTextConnect1.png
ComponentCharToTextConnect2.png

The Serial port receives one character at a time. To send an SMS messages, we need to get all the characters from a line, create a Text out of it, and send it to the GSM Module:

  1. Type "char" in the Filter box of the Component Toolbox, then select the "Char to Text" component (Picture 1), and drop it in the design area (Picture 2)
  2. Connect the "Out" output pin of the "Serial[ 0 ]" channel of the Arduino component to the "In" input pin of the CharToText1 component (Picture 2)
  3. Connect the "Out" output pin of the CharToText1 component to the "Text" input pin of the "Send SMS" element of the GSM1 component (Picture 3)

In Visuino: Add, Setup, and Connect Delay Component

ComponentDelay.png
ComponentDelayProperty.png
ComponentDelayConnect1.png
ComponentDelayConnect2.png

We need to make sure that we send the SMS after the text has been properly updated. We can use a Delay component with short delay for that:

  1. Type "delay" in the Filter box of the Component Toolbox, then select the "Delay" component (Picture 1), and drop it in the design area (Picture 2)
  2. In the Object Inspector, set the value of the "Interval" property to "100" (Picture 2)
  3. Connect the "Out" output pin of the CharToText1 component to the "In" input pin of the Delay1 component (Picture 3)
  4. Connect the "Out" output pin of the Delay1 component to the "Clock" input pin of the "Send SMS" element of the GSM1 component (Picture 4)

Generate, Compile, and Upload the Arduino Code

GenerateCtopped.png
ArduinoIDE.png
  1. In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE
  2. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)

And Play...

578ad31f937ddbe0880005df.jpeg
VisuinoDiagramCrop.png
Serial1.png
Serial2.png
Serial3.png

Congratulations! You have completed the project.

Picture 1 shows the connected and powered up project.

On Picture 2 you can see the complete Visuino diagram.

If you connect with Serial Terminal to the Arduino, after about 30 seconds you will see the "GSM Ready" message appear (Picture 3)

Once the message appears, if you Type some text, and click "Send" (Picture 4), the text will be sent as SMS message.

If you have selected as phone number on Step 8 to the phone of the SIM card on the Shield, after a while you will receive the message, and it will be shown on the Serial Terminal (Picture 5)

If you have set the number of a different device on Step 8, the messages will be sent to that device.

You can send SMS messages to the phone number from other phones and devices, and they also will be shown in the serial terminal.

Also attached is the Visuino project, that I created for this Instructable. You can download and open it in Visuino: https://www.visuino.com