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

问题描述 投票:2回答:1

我的连接是 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

arduino arduino-uno gsm
1个回答
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);   
}
© www.soinside.com 2019 - 2024. All rights reserved.