element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Blog Arduino GSM Shield
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: markvenn
  • Date Created: 27 Mar 2015 9:09 PM Date Created
  • Views 704 views
  • Likes 1 like
  • Comments 2 comments
  • sms
  • uno
  • arduino
  • gsm_shield
Related
Recommended

Arduino GSM Shield

markvenn
markvenn
27 Mar 2015

I've been playing with the GSM shield and the sms functions. As some of you may remember a while ago I was having problems with my mega and the shield. paulellison helped me out considerably with identifying problems with the mega and the shield using different pins and also we found the power drain could be quite high during some functions. Anyway, I have been playing with some ideas, using incoming sms messages to trigger events and so far I have got the Uno I am using to receive a test and, depending on the first character of the text it will reply to the sender with an appropriate text message and, if the message starts with a '#' it will discard the text and let the sender know that this is what has happened.

 

This is going to be the starting code for something I am going to try to work on during our Arduino Day so I give you the basic code now and will let you see how it works tomorrow!

 

/*
 SMS receiver

 This sketch, for the Arduino GSM shield, waits for a SMS message
 and displays it through the Serial port. Then returns message to sender
 letting them know it has been received on Arduino

 Circuit:
 * GSM shield attached to and Arduino
 * SIM card that can receive SMS messages

 created 27 Mar 2015 by Mark Venn
 based on code by Javier Zorzano / TD & Tom Igoe


*/

// include the GSM library
#include <GSM.h>

// PIN Number for the SIM
#define PINNUMBER ""

// initialize the library instances
GSM gsmAccess;
GSM_SMS sms;

// Array to hold the number a SMS is retreived from
char senderNumber[20];


void setup()
{
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.println("SMS Messages Receiver / Responder");

  // connection state
  boolean notConnected = true;

  // Start GSM connection
  while (notConnected)
  {
    if (gsmAccess.begin(PINNUMBER) == GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("GSM initialized");
  Serial.println("Waiting for messages");
}

void loop()
{
  char c;

  // If there are any SMSs available()
  if (sms.available())
  {
    Serial.println("Message received from:");

    // Get remote number
    sms.remoteNumber(senderNumber, 20);
    Serial.println(senderNumber);

    // An example of message disposal
    // Any messages starting with # should be discarded
    if (sms.peek() == '#')
    {
      Serial.println("Discarded SMS");
      sms.flush();
      Serial.println("\nSENDING REPLY");
      sms.beginSMS(senderNumber);
      sms.print("Message discarded. (Began with #");
      sms.endSMS();
      Serial.println("\nCOMPLETE");
    }
    else if (sms.peek() == '@')
    {
      Serial.println("\nSENDING REPLY");
      sms.beginSMS(senderNumber);
      sms.print("Message began @");
      sms.endSMS();
      Serial.println("\nCOMPLETE");
    }
    else if (sms.peek() == ';')
    {
      Serial.println("\nSENDING REPLY");
      sms.beginSMS(senderNumber);
      sms.print("Message began ;");
      sms.endSMS();
      Serial.println("\nCOMPLETE");
    }
    else if (sms.peek() == '!')
    {
      Serial.println("\nSENDING REPLY");
      sms.beginSMS(senderNumber);
      sms.print("Message began !");
      sms.endSMS();
      Serial.println("\nCOMPLETE");
    }
    else


    // Read message bytes and print them
    while (c = sms.read())
      Serial.print(c);

    Serial.println("\nEND OF MESSAGE");

    // return message to sms sender
    
    sms.beginSMS(senderNumber);
    sms.print("Message Received!");
    sms.endSMS();
    Serial.println("\nCOMPLETE!\n");



    // Delete message from modem memory
    sms.flush();
    Serial.println("MESSAGE DELETED");
  }

  delay(1000);

}

 

I am thinking of trying case statements instead of the dreaded if else if else mess, this was just to try to get something working ready for tomorrow! We shall see how it goes! Going to have a good day I think, odion is going over with me, he is really getting in to Arduino and using python to do clever stuff depending on what is spat out of the serial port. Will get him to write something up sometime. image

  • Sign in to reply

Top Comments

  • clem57
    clem57 over 10 years ago +1
    I used to use assembler and would code a table of 256 bytes. Each represented 1 character. A value like 4,8,12 and so on gave offset to address of routine in another table to handle that character. I could…
  • markvenn
    markvenn over 10 years ago in reply to clem57

    Very slick! image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • clem57
    clem57 over 10 years ago

    I used to use assembler and would code a table of 256 bytes. Each represented 1 character. A value like 4,8,12 and so on gave offset to address of routine in another table to handle that character. I could have more than one character go to 4 (first routine). Slick?

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube