100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > Arduino+sim800C家居安防火灾报警 拨打电话 发送短信例程程序

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

时间:2023-12-26 18:41:41

相关推荐

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

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

火灾报警

涉及用sim800c发短信,拨打电话通知。

接线:

Sim800c 3.3V -> Arduino 3.3VSim800c GND -> Arduino GNDSim800c RX -> Arduino TXSim800c TX -> Arduino RX

#include <SoftwareSerial.h> // 采用软件的串口#define Infrared 7//启动开关SoftwareSerial SIM800C(10, 11);// Serial RX, TXboolean bState, bOldState;int incomingByte = 0;// for incoming serial dataint Infrared_NUM = 0;void setup() {// put your setup code here, to run once:// Open serial communications and wait for port to openpinMode(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

通讯成功。任务初步完成。

//参考资料

//指令/cqdawnxsg/article/details/80680270

///xiaqiuchu/p/11568269.html

///thread-6985-1-1.html

---------------------

作者:icloudelectron

来源:CSDN

原文:/icloudelectron/article/details/106472907

版权声明:本文为作者原创文章,转载请附上博文链接!

内容解析By:CSDN,CNBLOG博客文章一键转载插件

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。