使用Arduino UNO开发板制作家用PIR防盗警报器

本项目bom很简单,只有pir传感器、蜂鸣器、led和按钮开关几个元件,按下按钮就可关闭蜂鸣声。
首先,将arduino uno开发板的 +5v、gnd连接到面包板。
led的阴极接地,阳极(长引脚)通过330 or 220欧姆的上拉电阻器连接到arduino开发板的6#引脚。
蜂鸣器的正极连接到arduino板子的5#引脚,负极引脚接gnd。
按钮开关的一个引脚通过1k欧姆电阻器接gnd,另一引脚连接到arduino的12引脚。
pir运动传感器的+vcc、gnd、output三个引脚分别连接于arduino开发板的+vcc、gnd、pin 7引脚。
按照上述步骤连接正确后,接下来取arduino ide上传代码到。再检查serial monitor的读数,移动手掌到传感器前面,led将闪亮,蜂鸣器将会报警。
code;c/c++
// declaring pins
const int buzzerpin = 5;
const int ledpin = 6;
const int motionpin = 7;
const int buttonpin = 12;
// setting buzzer mode to false
boolean buzzer_mode = false;
// for led
int ledstate = low;
long previousmillis = 0; 
long interval = 100;  // interval at which led blinks
void setup()
{
 //the following are our output
 pinmode(ledpin,output);
 pinmode(buzzerpin,output);
 //button is our input
 pinmode(buttonpin, input);
// wait before starting the alarm
 delay(5000);
}
void loop()
{
 // to chech whether the motion is detected or not
 if (digitalread(motionpin)) {
   buzzer_mode = true; 
 }
 // if alarm mode is on,blink our led
 if (buzzer_mode){
   unsigned long currentmillis = millis();
   if(currentmillis - previousmillis > interval) {
     previousmillis = currentmillis;   
     if (ledstate == low)
       ledstate = high;
     else
       ledstate = low;
   // switch the led
   digitalwrite(ledpin, ledstate);
   }
   tone(buzzerpin,1000);
 }
 // if alarm is off
 if (buzzer_mode == false) {
// no tone & led off
   notone(buzzerpin);  
   digitalwrite(ledpin, low);
 }
 // if our button is pressed switch off ringing and setup
 int button_state = digitalread(buttonpin);
 if (button_state) {buzzer_mode = false;}
}
如果你觉得这个小制作有用处,就把它装进小盒子里,固定到窗台、门框和阳台的不显眼位置,一个属于自己的防盗警报器就诞生了。


刘永好:要让年轻人上一线,没有房,他们有的是干劲
白皮书“实现高压信号隔离质量和可靠性”
RFID蔬菜供应链怎样打造绿色的生活品质
vivoXplay5怎么样 到底值不值得买
ZigBee在路灯中有什么应用
使用Arduino UNO开发板制作家用PIR防盗警报器
凯翔科技携手中国电信打造MegaBric分布式块存储一体机
4+64g,首发联发科x30,2699元起,魅族pro7曝光
雷声公司推出面向中程防空的新型GhostEye MR雷达
ISSCC 2019,思特威成为图像传感领域首次入选的中国企业!
某新建项目中电力管理系统的研究以及应用
智能援救机器人的功能及探测应用方案
波音公司宣布将暂停737MAX飞机的生产
苹果新专利可扩大电池容量,iphone续航大升级
铜箔基板厚度的量测技术大全
兽药残留定量测定仪的性能介绍
一种可编程宽带放大器的设计
aigo固态硬盘S500的上手体验:花小钱带来大满足
AN-653: 改善高动态范围均方根射频功率检波器的温度稳定性和线性度
DM7276/DM7275高精度直流电压计的功能特性及特点