需求来源
1.儿子过完年6岁,喜欢玩烟花,但是胆子小,于是我就负责点火,从年前26到大年初八,每天晚上要给儿子点鞭炮啊点鞭炮。
2.这边过年要打关门炮跟开门炮,大年初一凌晨还要起来帮老妈点鞭炮,说实在的那个整串的小鞭炮也炸的太快了,每次没跑几步就开响,哥也心脏不好啊。
设计:
根据需求,我们需要个远程点火的打火机,上taobao上逛了一圈,找到了usb打火机,续电器,外加一张SIM900 arduino扩展板,回来简单的一连,就了了了。
代码:
#include <SoftwareSerial.h> #include <String.h> SoftwareSerial GPRS(7, 8); String currentLine = ""; // string to hold the text from server String triggerNo="13616761237"; String mobile = ""; boolean readingNo=false; long lastTriggerTime=0; boolean fireing=false; int led=4; void setup() { GPRS.begin(19200); // the GPRS baud rate Serial.begin(19200); // the GPRS baud rate pinMode(9, OUTPUT); pinMode(led,OUTPUT); digitalWrite(led,LOW); delay(500); powerUpOrDown(); } void loop() { if(fireing){ if( millis() - lastTriggerTime >= 12 * 1000){ Serial.println("stop fire!"); digitalWrite(led,LOW); fireing=false; }else{ return; } } while(GPRS.available()){ char inChar=GPRS.read(); currentLine +=inChar; if(inChar=='\n')currentLine=""; if(currentLine.endsWith( "+CLIP: \"")){ readingNo=true; mobile=""; } if(readingNo){ if(inChar !=','){ if(inChar !='"')mobile+=inChar; }else{ readingNo=false; Serial.println(mobile); if(mobile==triggerNo){ lastTriggerTime=millis(); Serial.println("fire!!"); fireing=true; currentLine=""; mobile=""; delay(1000); digitalWrite(led,HIGH); delay(4000); GPRS.println("ATH"); while(GPRS.available()){ GPRS.read(); } } } } } } void powerUpOrDown() { digitalWrite(9,LOW); delay(1000); digitalWrite(9,HIGH); delay(2000); digitalWrite(9,LOW); delay(3000); }
效果图(分待机状态跟触发状态):
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include <SoftwareSerial.h> #include <String.h> SoftwareSerial GPRS(7, 8); String currentLine = ""; // string to hold the text from server String triggerNo="13616761237"; String mobile = ""; boolean readingNo=false; long lastTriggerTime=0; boolean fireing=false; int led=4; long lastReadTime=0; void setup() { GPRS.begin(19200); // the GPRS baud rate Serial.begin(19200); // the GPRS baud rate pinMode(9, OUTPUT); pinMode(led,OUTPUT); digitalWrite(led,LOW); delay(500); } void loop() { if(fireing){ if( millis() - lastTriggerTime >= 12 * 1000){ Serial.println("stop fire!"); digitalWrite(led,LOW); fireing=false; }else{ return; } } while(GPRS.available()){ lastReadTime=millis(); char inChar=GPRS.read(); currentLine +=inChar; if(inChar=='\n')currentLine=""; if(currentLine.endsWith( "+CLIP: \"")){ readingNo=true; mobile=""; } if(readingNo){ if(inChar !=','){ if(inChar !='"')mobile+=inChar; }else{ readingNo=false; Serial.println(mobile); if(mobile==triggerNo){ lastTriggerTime=millis(); Serial.println("fire!!"); fireing=true; currentLine=""; mobile=""; delay(1000); digitalWrite(led,HIGH); delay(4000); GPRS.println("ATH"); while(GPRS.available()){ GPRS.read(); } } } } } if(millis()- lastReadTime >= 1000 * 30) { tryPowerUp(); } } void tryPowerUp(){ GPRS.println("AT"); delay(500); if(GPRS.available())return; powerUpOrDown(); } void powerUpOrDown() { digitalWrite(9,LOW); delay(1000); digitalWrite(9,HIGH); delay(1000); digitalWrite(9,LOW); delay(5000); }