我目前在「物聯網」領域下研究我的迷你項目。我選擇使用GSM模塊設計無線通知板。如何從嵌入式C中的GSM調制解調器讀取消息?
我將項目分爲兩個模塊。首先,完美完成的Arduino-LED板接口。
二,GSM-Arduino接口。基本上,信息/短信將從手機發送到GSM模塊,然後我們必須使用Arduino從GSM模塊讀取該信息。我在這裏面臨一個問題。該消息正被髮送到GSM調制解調器,但我無法閱讀。我嘗試寫不同的代碼,但它不工作。該消息未被顯示。
這是我試過的代碼片段。
`#include SoftwareSerial.h
SoftwareSerial SIM900A(2,3);// RX | TX
// Connect the SIM900A TX to Arduino pin 2 RX
// Connect the SIM900A RX to Arduino pin 3 TX.
void setup()
{
SIM900A.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor(Arduino)
Serial.println ("SIM900A Ready");
delay(100);
Serial.println (" Press s to send and r to recieve ");
}
void loop()
{
if (Serial.available()>0)
switch(Serial.read())
{
case 's': SendMessage();
break;
case 'r': RecieveMessage();
break;
}
if (SIM900A.available()>0)
Serial.write(SIM900A.read());
}
void SendMessage()
{
SIM900A.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000); // Delay of 1000 milli seconds or 1 second
Serial.println ("Set SMS Number");
SIM900A.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); //Replace with your mobileno.
delay(1000);
Serial.println ("Set SMS Content");
SIM900A.println("Hello, I am SIM900A GSM Module");// The SMS text you want to send
delay(100);
Serial.println ("Finish");
SIM900A.println((char)26);// ASCII code of CTRL+Z
delay(1000);
Serial.println (" ->SMS Sent");
}
void RecieveMessage()
{
Serial.println ("SIM900A Receiving SMS");
delay (1000);
SIM900A.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
delay(1000);
Serial.write (" ->Unread SMS Recieved");
}`
我們不知道你的硬件是否工作。我們不能幫助硬件調試。你在範圍上看到什麼? – ThingyWotsit
硬件工作正常!當我們在GSM模塊中插入SIM卡並測試它是否從移動電話發送時接收到任何消息時,它將完全正常工作。如何閱讀接收消息是我面臨問題的地方。我無法閱讀GSM的消息。 –
'測試它是否接收到任何消息' - 如果您無法接收Arduino接口上的任何數據,如何測試它? – ThingyWotsit