Arduino+sim800C家居安防火灾报警 拨打电话 发送短信例程程序

家居安防报警器,参考程序。

火灾报警
涉及用sim800c发短信,拨打电话通知。
在这里插入图片描述             在这里插入图片描述

接线:

Sim800c 3.3V -> Arduino 3.3V
Sim800c GND -> Arduino GND
Sim800c RX -> Arduino TX
Sim800c TX -> Arduino RX
#include <SoftwareSerial.h>        // 采用软件的串口
#define Infrared 7     //启动开关

SoftwareSerial SIM800C(10, 11);     // Serial RX, TX
boolean bState, bOldState;
int incomingByte = 0;               // for incoming serial data
int Infrared_NUM = 0;

void setup() {
  // put your setup code here, to run once:
  // Open serial communications and wait for port to open
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(Infrared,INPUT_PULLUP);
  digitalWrite(13,LOW);
  digitalWrite(12,LOW);
  
  Serial.begin(9600);
  while (!Serial) {  // wait for serial port to connect. Needed for native USB port only
  } 

  Serial.println("Good Morning, my old friend!");
  
  SIM800C.begin(9600);
  SIM800C.println("AT+CMGF=1");
  
}

void loop() {
  // put your main code here, to run repeatedly:
  if (SIM800C.available()) {
    Serial.write(SIM800C.read());
    digitalWrite(13, HIGH);// 如果通信成功,则把Arduino上面的L13 LED 灯打开
  }
  if (Serial.available()) {
    SIM800C.write(Serial.read());
//    incomingByte = Serial.read();
//    Serial.print("I received: ");
//    Serial.println(incomingByte, DEC);
//    digitalWrite(13, !digitalRead(13));
  }
  
  Infrared_NUM = digitalRead(Infrared);//检测启动开关
  if(Infrared_NUM == LOW){
   // sendMeg();//发送短信例程代码
    SIM800C.println("AT");
     delay(2000);
    SIM800C.println("ATD12345678900;\r");//12345678900改成你要拨打的电话号码
    digitalWrite(12,HIGH);
    delay(5000);
    while(!digitalRead(Infrared));
    digitalWrite(12,LOW);
    //SIM800C.println("ATH");
    delay(1000);
  }
}

//发送短信例程代码
void sendMeg()
  {
   
  SIM800C.println("AT");
  delay(2000);
  SIM800C.println("AT+CMGF=1");
  delay(2000);
  SIM800C.println("AT+CMGS=\"12345678900\"");//这里改成你的号码 \"转义
  delay(2000);
  SIM800C.print("Test\r\n");//这里写内容
  delay(2000);
  SIM800C.write(0x1A);//发送:0x1A,即“CTRL+Z”的键值,用于告诉 SIM800C,要执行发送操作
                      //发送: 0x1B,即“ESC”的键值,用于告诉 SIM800C,取消本次操作,不执行发送。 
  }

在这里插入图片描述在这里我们发送了一个AT命令,SIM800C返回一个Ok。再发送一个AT+GSV,返回:
  13:33:20.943 -> SIMCOM_Ltd
  13:33:20.943 -> SIMCOM_SIM800C
  13:33:20.979 -> Revision:1418B06SIM800C24
  通讯成功。任务初步完成。

//参考资料

//指令https://blog.csdn.net/cqdawnxsg/article/details/80680270
//https://www.cnblogs.com/xiaqiuchu/p/11568269.html
//https://www.arduino.cn/thread-6985-1-1.html


---------------------
作者:icloudelectron
来源:CSDN
原文:https://blog.csdn.net/icloudelectron/article/details/106472907
版权声明:本文为作者原创文章,转载请附上博文链接!
内容解析By:CSDN,CNBLOG博客文章一键转载插件

  • 2
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值