5499| 0
|
[进阶] arduino激光报警器tripwire |
记得小时候看的国外电影,尤其对里面的激光报警很感兴趣。 看了几个程序,搜索了下资料。就搭建了个激光报警电路 把这个很简单的程序给更多和我一样的小白参考下 Arduino这么多io口,可以完全做一个以其为核心的功能完善的报警系统了。 太多啦下一个项目的主角就是你了先看一个简单点的 [mw_shl_code=applescript,true] int ldrPin = A4; // the battery and 10K pulldown are connected to a0 int sirenPin = 11; int ledPin = A0; long ldrValue1, ldrValue2; void setup(void) { pinMode (sirenPin,OUTPUT); // set the siren pin as output pinMode (ledPin,OUTPUT); // set the siren pin as output pinMode (ldrPin,INPUT); // set the siren pin as output //Serial.begin(9600); } void loop(void) { ldrValue1 = analogRead(ldrPin); delay(10); ldrValue2 = analogRead(ldrPin); if (ldrValue1-ldrValue2 > 20){ digitalWrite(sirenPin,HIGH); digitalWrite(ledPin,HIGH); delay(1000); } else{ digitalWrite(sirenPin,LOW); digitalWrite(ledPin,LOW); } //Serial.print("Analog reading = "); //Serial.println(ldrValue1); // the raw analog reading } [/mw_shl_code] 再加个警车警报 [mw_shl_code=applescript,true] int ldrPin = A4; // the cell and 10K pulldown are connected to a0 int sirenPin = 11; //pin 3 selected!! int ledPin = A0; long ldrValue1, ldrValue2; void setup(void) { pinMode (sirenPin,OUTPUT); // set the siren pin as output pinMode (ledPin,OUTPUT); // set the siren pin as output pinMode (ldrPin,INPUT); // set the siren pin as output //Serial.begin(9600); } void loop(void) { ldrValue1 = analogRead(ldrPin); delay(10); ldrValue2 = analogRead(ldrPin); if (ldrValue1-ldrValue2 > 20){ //digitalWrite(sirenPin,HIGH); digitalWrite(ledPin,HIGH); //void beep(){ // Toggle the buzzer at various speeds for (byte x = 255 ; x > 50 ; x=x-2) { for (byte y = 0 ; y < 5 ; y=y+2) { digitalWrite(sirenPin,HIGH); //digitalWrite(sirenPin, HIGH); delayMicroseconds(x); digitalWrite(sirenPin, LOW); delayMicroseconds(x); } //delay(1000); } } else{ digitalWrite(sirenPin,LOW); digitalWrite(ledPin,LOW); } //Serial.print("Analog reading = "); //Serial.println(ldrValue1); // the raw analog reading } [/mw_shl_code] |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed