如何使用GSM模块SIM800和Arduino Uno发送短信?

2024-04-14

我正在尝试通过 SIM800 GSM 模块从 Arduino 发送短信。消息到达给定号码,但格式不正确。 它显示“消息格式不支持”。

我在这里添加了我的代码,非常感谢您的快速回复。

#include <SoftwareSerial.h>
SoftwareSerial GPRS(11, 12); //11 = TX, 12 = RX
unsigned char buffer[64]; //port
int count=0;
int i = 0; //if i = 0, send SMS.
void setup() {
  GPRS.begin(9600); // the GPRS baud rate
  Serial.begin(9600); // the Serial port of Arduino baud rate.
  Serial.print("I'm ready");
  Serial.print("Hello?");
}

void loop() {
  if (GPRS.available()) {
    // if date is coming from softwareserial port ==> data is coming from GPRS shield
    while(GPRS.available()) {
      // reading data into char array
      buffer[count++]=GPRS.read();
      // writing data into array
      if(count == 64)
        break;
    }
    Serial.write(buffer,count);
    // if no data transmission ends, write buffer to hardware serial port
    clearBufferArray();
    // call clearBufferArray function to clear the stored data from the array
    count = 0; // set counter of while loop to zero
  }
  if (Serial.available())
    // if data is available on hardwareserial port ==> data is coming from PC or notebook
    GPRS.write(Serial.read()); // write it to the GPRS shield
  if(i == 0) {
    GPRS.write("AT+CMGF=1\r"); //sending SMS in text mode
    delay(1000);
    Serial.println("AT+CMGF=1\r");       
    GPRS.write("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // phone number
    delay(1000);
    Serial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r");       
    GPRS.write("Hello how are you?\r"); // message
    delay(1000);
    Serial.println("Hello how are you?\r"); 
    delay(1000);
    GPRS.write(0x1A);
    //send a Ctrl+Z (end of the message)
    delay(1000);
    Serial.println("SMS sent successfully");
    i++;
  }   
}

void clearBufferArray(){
  // function to clear buffer array
  for (int i=0; i<count;i++){
    buffer[i]='\0';
    // clear all index of array with command NULL
  }
}

简单的方法是为 arduino 添加 grps 库,方法是转到 Arduino IDE ->Sketch->Library->Manage Libraries,然后输入 gprs,您将获得该库并安装它 尝试这个示例代码来测试它,

    #include <gprs.h>
    #include <SoftwareSerial.h>

   GPRS gprs;

   void setup() {
     Serial.begin(9600);
     while(!Serial);
     gprs.preInit();
     delay(5000);  //wait for 5 seconds
     while(0 != gprs.init()) {
     delay(1000);
     Serial.print("Not connected,try again\r\n");
    }  
    Serial.println("Sending SMS");
    gprs.sendSMS("844******8","Testing the Module"); //Enter your phone number 
   and text
   }

   void loop() {
    //If you want the to send the Text continuously then add the code here
   }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用GSM模块SIM800和Arduino Uno发送短信? 的相关文章

  • 使用 Python 更改 XML 文件中包含的文本的最佳方法是什么?

    假设我有一个名为 MyData xml 的现有简单 XML 文件 其中包含以下内容
  • 在WPF中有效地在图像上显示文本?

    如何在图像上显示文本 使其始终可见 因为图像颜色是混合的且不可预测 我考虑了两个选择 使文本边框为白色 而文本本身为黑色 使文字与图片相反地显示 第一个选项是首选 因为它看起来更坚固 嵌入文本很简单
  • Swift - 将数组写入文本文件

    我从一个包含几千行纯文本的文件中读入 myArray 原生 Swift myData String stringWithContentsOfFile myPath encoding NSUTF8StringEncoding error ni
  • 使用 Java 控制 Arduino

    我正在寻找一个LED http en wikipedia org wiki Light emitting diode用Java程序打开和关闭 我用 C 完成了这个项目大约 5 分钟 但用 Java 似乎更具挑战性 我让 Arduino 等待
  • Java 中有可用的 SMS Pdu 解析器吗?

    任何人都知道 Java 中可用的 Pdu 解析器来自 byte 数组 我主要关心的是获得符合 GSM 标准的用户数据头 UDH 我的意思是正确地得到它 smsLib http smslib org 已经比较成熟了 您还可以使用 Androi
  • 从具有特定模式的 txt 文件创建 Pandas DataFrame

    我需要基于以下结构的文本文件创建一个 Pandas DataFrame Alabama edit Auburn Auburn University 1 Florence University of North Alabama Jackson
  • QGraphicsScene 中的文本

    如何在QGraphicsScene中的某个坐标处写入文字 我试图这样做 但没有成功 文本有黑色边框 但字母内部是白色的 我无法将其变成黑色 QPainterPath path QFont font font setPixelSize 50
  • 追加到 txt 文件中的现有行

    我有一个程序可以将一个人的姓名及其分数存储在 python 的 txt 文件中 例如这是我当前的代码 name input Name score input Score file name student scores txt file o
  • 为什么我的 MySQL 数据列中只保存了 64kB 数据?

    我试图将一个很长的文本字符串插入到 MySQL Blob 列中 但 MySQL 只保存了 64kB 的数据 该字符串的长度为 75360 个字符 我正在使用 PHP 连接mysql connect 有任何想法吗 它是 Blob 还是 Tex
  • 无法从三星设备上的通话记录中删除短信日志

    我尝试通过我的应用程序从设备中删除所有短信 但由于某种原因 短信日志仍然出现在某些三星设备的通话记录中 我尝试了一种更 激进 的方法 并使用以下 URI 删除ContentResolver content call log calls co
  • 用于图像中文本检测的霍夫变换算法[关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 霍夫变换算法是用于文本行检测和边缘检测的算法之一 霍夫变换算法可以用于检测图像中的文本吗 这道题在java中的流程或者实现应该是怎样的
  • 是否可以在 Arduino 上运行 ZeroMQ

    我想知道是否可以通过 ZeroMQ 与 Arduino 进行通信 我想使用 Arduino 来控制一些设备 并希望将大部分应用程序放在计算机上 为此 如果 Arduino 和控制器可以通过 Zeromq 以及 WiFi 或以太网扩展板进行通
  • 在声明对象之前在全局函数中使用类的成员函数

    我有一个事件处理函数 在该函数中调用了类的成员函数 事件处理函数在类 cpp 文件中声明 但不是类的一部分 它不是成员函数 当我编译代码时 编译器表示该函数在范围内 因为它正在调用全局事件处理函数中的成员函数 我的问题如下 有没有办法在全局
  • HTML5 文本画布在文本宽度大于允许的最大宽度时旋转

    朋友们 我发现旋转文本画布对象有点棘手 问题是 我正在绘制一个图形 但有时每个条形的宽度小于该条形的 值 所以我必须将 值 评定为 90 度 在大多数情况下它都会起作用 我正在做以下事情 a function x y text maxWid
  • 如何在 C# 中读取文本文件并将数据添加到 int 数组中?

    我正在尝试读取一个文本文件 其中包含以逗号分隔的数字 当我阅读时使用File Readline 我把它拿到string 我需要将其转换为 int 数组 但它给出了错误 文本文件的内容 146429 143689 144380 141523
  • 通过iPhone音频插孔读取数据

    我正在寻找一种方法来读取通过 iPhone 的音频插孔从 Arduino 发送的原始数据 我搜索了很多并发现this https github com sanjibahmad Is Headphone Plugged In tree mas
  • 从 iBeacon 接收 BLE 信号到 Bluno(arduino with BLE)

    我想从 iBeacon 到 Bluno 接收 rssi 信号和 UUID Arduino 板具有 BLE 对此有一些疑问 有没有从 BLE 到 BLE 接收 UUID 和 rssi 的解决方案 两个BLE设备可以互相通信吗 我想找一些网站来
  • 发送同一条短信两次

    我正在尝试制作一个短信Android应用程序 但我收到了一个我以前从未见过的错误 即使在谷歌中我也没有找到类似的东西 所以 如果你能帮助我 我会很高兴 由于某种原因 程序同时发送两条消息 同一条短信 但这只是发生在生产中 当我使用模拟器时
  • 使用 Powershell 按列拆分 csv 文件

    我是 powershell 的新手 但这看起来是完成此任务的最佳工具 有一个如下所示的 csv 文件 Date mary1 mary2 maryr3 mary4 9 01 2011 1 00 1 39 3 43 3 29 1 83 9 01
  • 当我启动程序时,Arduino IDE (Win10) 崩溃

    我的 Arduino IDE Win10 上的版本为 1 8 12 在启动时崩溃 运行arduino debug exe我收到此错误消息 C Program Files x86 Arduino gt arduino debug exe Se

随机推荐