84740

Arduino sending sms in GSM sim900 error

Question:

I have an Arduino Mega 2560 and a sim900 gsm module. I interfaced them successfully and written the code. Its working, but I can only send 1 sms at a time in the while loop. That means when I write a while loop to execute the sendsms() 5 times by using a while loop. Only one sms is sent.. and it stops...

The code is below:

#include <SoftwareSerial.h> #include <String.h> SoftwareSerial mySerial(52, 53); void setup() { mySerial.begin(19200); // the GPRS baud rate Serial.begin(19200); // the GPRS baud rate delay(500); } int x = 0; loop() { while (x<5) { SendTextMessage(); x++; } } void SendTextMessage() { mySerial.print("AT+CMGF=1\r"); delay(100); mySerial.println("AT + CMGS = \"+94776511996\""); delay(100); mySerial.println("hey wow"); delay(100); mySerial.println((char)26); delay(100); mySerial.println(); }

Answer1:

You can't just dump your AT commands at the SIM900 with 100mS delay, and expect it to work. The SIM900 responds to AT commands (typically with "OK"), and you should wait for this response before issuing the next command. You can getaway with ignoring these responses only if you provide enough delay between AT commands to make sure that every command is only sent after the SIM900 had enough time to respond to the previous one. To make a quick verification of this, I would add a delay(10000) - a 10 seconds delay - at the end of your sendTextMessage() function. This will (probably) give the SIM900 enough time to complete the SMS transmission before moving on to the next one.

Answer2:

void SendTextMessage(){ mySerial.write("AT+CMGF=1\r\n"); delay(1000); mySerial.write("AT+CMGS=\"+94776511996\"\r\n"); delay(1000); mySerial.write("Test"); delay(1000); mySerial.write((char)26); delay(2000); }

Recommend

  • How to read messages from GSM modem in Embedded C?
  • Passing Props from State to Child
  • How to change default stop edit behavior in jtable
  • What is this strange character in chrome's resource css viewer?
  • Time out Error in send mail
  • Appending Character to Character Array In C
  • OOP Javascript - Is “get property” method necessary?
  • GridView breaks while scrolling
  • copying resource to sdcard gives a damaged file in android
  • Database structure design with variable amounts of fields
  • how to adjust image in a panel in Java swing?
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • NetLogo BehaviorSpace - Measure runs using reporters
  • Problems to linebreak with an int in JLabel
  • How reduce the height of an mschart by breaking up the y-axis
  • output of program is not same as passed argument
  • MySQL WHERE-condition in procedure ignored
  • ActionScript 2 vs ActionScript 3 performance
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Rearranging Cells in UITableView Bug & Saving Changes
  • AT Commands to Send SMS not working in Windows 8.1
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Buffer size for converting unsigned long to string
  • Hits per day in Google Big Query
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • apache spark aggregate function using min value
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • Sorting a 2D array using the second column C++
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • failed to connect to specific WiFi in android programmatically
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal
  • How can I use threading to 'tick' a timer to be accessed by other threads?