我正在使用Arduino Uno和GSM 900A模块将SMS发送到我的手机。这是代码
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);
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)
switch(Serial.read())
{
case 's':
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1 second
mySerial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile number 91 is country code
delay(1000);
mySerial.println("Hi");// The SMS text you want to send
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z for saying the end of sms to the module
delay(1000);
break;
case 'r':
mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
delay(1000);
break;
}
if (mySerial.available()>0)
Serial.write(mySerial.read());
}
这是我得到的输出https://imgur.com/a/YYhfP8c
GSM模块的状态为蓝灯,网络的黄灯为稳定,这意味着该网络对模块有利。另外,Uno上的TX灯持续发光,但RX灯永不发光
即使回答为时已晚,以我的经验,这也是由于电源问题(噪声和电力不足)引起的。尝试使用至少2A的外部电源为调制解调器供电,并使用与调制解调器的VCC GND引脚并联的多个10nF或100nF电容器。