在您将此问题标记为重复之前,请注意我已尝试this,this&this
我最近买了一个Arduino UNO R3和一个SIM808 GSM / GPS防护罩 . 屏蔽的RX连接到Arduino的引脚11,TX连接到引脚10,两个GND相互连接 . 我已经将我的Arduino连接到我的电脑和USB,并且屏蔽连接到带有12V适配器的外部电源 . 另外,我已将Arduino的3.3V连接到屏蔽的Vcc .
以下是我使用的草图:
// Include the GSM library
#include <GSM.h>
#define PINNUMBER ""
// initialize the library instance
GSM gsmAccess;
GSM_SMS sms;
void setup() {
// initialize serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("SMS Messages Sender");
// connection state
boolean notConnected = true;
// Start GSM shield
// If your SIM has PIN, pass it as a parameter of begin() in quotes
while (notConnected) {
if (gsmAccess.begin(PINNUMBER) == GSM_READY) {
notConnected = false;
} else {
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
}
void loop() {
Serial.print("Enter a mobile number: ");
char remoteNum[20]; // telephone number to send sms
readSerial(remoteNum);
Serial.println(remoteNum);
// sms text
Serial.print("Now, enter SMS content: ");
char txtMsg[200];
readSerial(txtMsg);
Serial.println("SENDING");
Serial.println();
Serial.println("Message:");
Serial.println(txtMsg);
// send the message
sms.beginSMS(remoteNum);
sms.print(txtMsg);
sms.endSMS();
Serial.println("\nCOMPLETE!\n");
}
/*
Read input serial
*/
int readSerial(char result[]) {
int i = 0;
while (1) {
while (Serial.available() > 0) {
char inChar = Serial.read();
if (inChar == '\n') {
result[i] = '\0';
Serial.flush();
return 0;
}
if (inChar != '\r') {
result[i] = inChar;
i++;
}
}
}
}
这里的问题与那些链接的帖子中提到的问题相同 .
条件 if (gsmAccess.begin(PINNUMBER) == GSM_READY)
永远不会被执行 . else
部分也不执行 .
串行监视器永远不会超过 SMS Messages Sender .
请注意,我使用的是AirTel India,我有一个完全激活的数据计划,PIN码已更改为0000 .
如果有人能提出有用的建议,我们将非常感激
谢谢你的时间!!
3 回答
你无法从Arduino的3.3V电源为GSM模块供电! GSM需要3A的峰值电流(是的,安培,而不是毫安) . 你真的需要一个LiPo电池为GSM供电 . 你可以用同样的LiPo电池为3V Arduino供电,实际上,如果你需要移动解决方案,而不是相反 .
请先检查模块是否响应下一个代码Example Code
另外,电源电压范围必须为3.4~4.4V,尽量不要使用较低的电压 .
Arduino的GSM库用于Quectel M10 GSM / GPRS模块,与SimCom SIMxxx模块不兼容 .
以下是可用于SIM808模块的库https://github.com/MarcoMartines/GSM-GPRS-GPS-Shield(回购中包含的示例) . 请注意,此库使用
SIM900
库,该库允许与SimCom模块的低级接口 .有关这方面的两个adafruit链接:
http://wiki.iteadstudio.com/SIM808_GSM/GPRS/GPS_Module
https://www.adafruit.com/products/2637
你是什么意思?您需要为屏蔽提供所需的电压,以提供所需的电流 . 而且你需要与你的arduino有一个共同点 .
此外,如果你的屏蔽是3.3V,你需要使用分压器从arduino转换Tx线路(因为它是5V) .
请注意,这些屏蔽还有一个需要连接的软启动按钮,以允许代码为模块供电 .