GSM SIM 900A不会使用Arduino UNO发送消息

时间:2017-10-17 07:12:54

标签: arduino arduino-uno gsm

我的连接是
5VT到D9
5VR至D10
和外部适配器供电..(5v 2A)

眨眼是好的,因为它每隔3秒闪烁一次 SIM卡已加载 但是当我运行串行监视器时,它只显示AT AT AT,有时AT显示反向问号..

这是我正在使用的代码..

#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':
      SendMessage();
      break;
    case 'r':
      RecieveMessage();
      break;
  }

 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=\"+639176344625\"\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);
}


 void RecieveMessage()
{
  mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
  delay(1000);
 }

这是我和Arduino Uno一起使用的Sim900A .. enter image description here

1 个答案:

答案 0 :(得分:0)

签出此代码以使用GSM发送简单数据。

#include <SoftwareSerial.h>
SoftwareSerial ph(9,10); // RX, TX of gsm
void setup() {
  Serial.begin(9600);
  ph.begin(9600);
  sms(600);
}
void loop() {
  // put your main code here, to run repeatedly:
}
void sms(float amount) {
  ph.println("AT+CMGF=1"); 
  delay(1000); 
  ph.println("AT+CMGS=\"123456789\"\r"); //Enter your number in place of 123456789
  delay(1000);
  ph.print("Amount:  ");
  ph.println(amount);
  delay(100);
  ph.println((char)26);// ASCII code of CTRL+Z
  delay(1000);   
}