使用带有Arduino的sim900a接收短信

时间:2014-11-11 14:10:19

标签: c arduino sms

我尝试通过SMS(Ex-#RT5 - 旋转电机5轮)根据收到的命令控制步进电机。这里我使用了SIM900A GSM模块和Arduino Uno板。我使用以下代码来检查接收短信,但它无法正常工作。发送短信工作正常。我将GSM模块Rx引脚连接到Arduino Tx引脚和GSM模块Tx引脚Arduino Rx引脚和公共GND两者。

有人可以帮我处理收到的短信。

谢谢!

#include <GSM.h>
GSM gsmAccess;
GSM_SMS sms;
char senderNumber[20];
int Str3[65]={0};
int j=0;
char inchar;


void setup() {
  // put your setup code here, to run once:

Serial.begin(9600);  //Baud rate of the GSM/GPRS Module 
  Serial.print("\r");
  delay(1000);                  
  Serial.print("AT+CMGF=1\r");    
  delay(1000);
  Serial.print("AT+CMGS=\"0718529161\"\r");    //Number to which you want to send the sms
  delay(1000);
  Serial.print("Gayantha GSM Modem is Ready\r");   //The text of the message to be sent
  delay(1000);
  Serial.write(0x1A);
  //delay(1000); 
}


void sendSMS(){

  Serial.print("AT+CMGF=1\r");                                                        // AT command to send SMS message
  delay(1000);
  Serial.println("AT + CMGS = \"0718529161\"");                                     // recipient's mobile number, in international format
  delay(1000);
  Serial.println("Gayantha, Receved Character is a");        // message to send
  delay(5000);
  Serial.write(0x1A);
  //Serial.println((char)26);                       // End AT command with a ^Z, ASCII code 26
  delay(1000); 
  //Serial.println();
  //delay(5000);                                     // give module time to send SMS

}
 void sendSMS2()
{
  Serial.print("AT+CMGF=1\r");                                                        // AT command to send SMS message
  delay(1000);
  Serial.println("AT + CMGS = \"0718529161\"");                                     // recipient's mobile number, in international format
  delay(1000);
  Serial.println("Gayantha, Receved Character is b");        // message to send
  delay(1000);
  Serial.println((char)26);                       // End AT command with a ^Z, ASCII code 26
  delay(1000); 
  Serial.println();
  delay(5000);                                     // give module time to send SMS
  //SIM900power();                                   // turn off module
}

void loop(){ 
char c;

  // If there are any SMSs available()  
  while(sms.available()){
  Serial.println("SMS is Received");
  sendSMS2();
  delay(5000);
  }
}

0 个答案:

没有答案
相关问题