【发布时间】:2013-04-09 07:36:58
【问题描述】:
#include <SoftwareSerial.h>
char inchar; //Will hold the incoming character from the serial port.
SoftwareSerial cell(2,3); //Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.
int led1 = A2;
void setup()
{
// Prepare the digital output pins
pinMode(led1, OUTPUT);
digitalWrite(led1, HIGH);
//Initialize GSM module serial port for communication.
cell.begin(19200);
delay(30000); // Give time for GSM module to register on network, etc.
cell.println("AT+CMGF=1"); // Set SMS mode to text
delay(200);
cell.println("AT+CNMI=3,3,0,0"); // Set module to send SMS data to serial out upon receipt
delay(200);
}
void loop()
{
//If a character comes in from the cellular module...
if(cell.available() >0)
{
delay(10);
inchar=cell.read();
if (inchar=='a')
{
delay(10);
inchar=cell.read();
if (inchar=='0')
{
digitalWrite(led1, LOW);
}
else if (inchar=='1')
{
digitalWrite(led1, HIGH);
}
delay(10);
delay(10);
}
cell.println("AT+CMGD=1,4"); // Delete all SMS
}
}
这是用于从蜂窝网络接收 SMS 的代码。我正在使用带有 SIM900 的 Arduino Gboard。代码没有错误,但是板上的 LED 没有响应 SMS 的开关。
为什么?
【问题讨论】:
-
你能添加一个问题,带问号吗?目前尚不清楚您的问题是什么。 “代码中没有错误”到底是什么意思?您是否正确接收短信?
-
不,先生,我的代码中没有 eroor。
-
那么是板上的LED灯不亮吗?
-
不,先生,我的代码中没有 eroor。问题:,我想从蜂窝网络(移动)打开或关闭 jst ......就像 #a0 或 #a1 一样将 jst 短信发送到 arduino,根据我的程序,led 是打开或关闭的,也没有问题上传但 led 没有给出响应....我的程序运行到初始级别意味着当我定义最初 led 低或 led 高但随后逻辑不遵循........所以你能告诉我有没有波特率问题??我用 19200 开始细胞...所以请尝试帮助我...thanxx
-
是的,没有 LED 闪烁....仅在开始时将 LED 定义为低或高,它可以显示,但随后逻辑 nt 应用..所以如果你有任何想法......thn请告诉我