无法使用AT命令为arduino uno发送短信

问题描述 投票:0回答:1
#include <SoftwareSerial.h>

SoftwareSerial mySerial(0, 1);

void setup()

{

  mySerial.begin(9600);   // Setting the baud rate of GSM Module 

  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)

  delay(100);

}

void loop()

{

  if (Serial.available()>0)

      SendMessage();

 if (mySerial.available()>0)

   Serial.write(mySerial.read());

}

 void SendMessage()


{

  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode

  delay(1000);  // Delay of 1000 milli seconds or 1 second

  mySerial.println("AT+CMGS=\"+1876xxxxxxx\"\r"); // Replace x with mobile number

  delay(1000);

  mySerial.println("I am SMS from GSM Module");// The SMS text you want to send

  delay(100);

  mySerial.println((char)26);// ASCII code of CTRL+Z

  delay(1000);

}

我试图通过arduino平台使用SIM 800 RPI GSM ADD-on v2.3模块发送短信,但是我尝试的一切都失败了。请协助并解释我哪里出错了。谢谢。我的代码在上面。谢谢

arduino arduino-uno gsm
1个回答
0
投票

你错过了"AT+CMGF=1"的回车。

"AT+CMGF=1"改为"AT+CMGF=1\r"

虽然命令之间的延迟有效但足以达到目的,但不推荐。最好捕获并分析SIM800返回的消息,尤其是在发生错误的情况下。

© www.soinside.com 2019 - 2024. All rights reserved.