常用传感器讲解七--红外警报传感器(KY-008)

327 阅读2分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

具体讲解

在这里插入图片描述

这个是一种由身体运动触发的设备,可以使用它来检测人,动物,汽车……经过某个区域时的情况。这是一个基于LASER发射器的设备,该发射器不断向光学传感器发送光束,当有人/某物通过时,传感器将不会接收到光束,并且会触发警报。 该项目基于模块,LASER模块,蜂鸣器和按钮,其概念非常简单,LASER不断向模块传感器投射光线,当有人或其他物体通过光束时,传感器会不再检测到光(当光停止时,LDR将增加电阻,这意味着将流过的电流减少,并且我们将得到一个电压降)。

例子项目:在室内光线下,使用Arduino时使用“ analogRead”功能时,传感器将给出“ 750”左右的值,而使用Arduino时传感器将给出“ 3.66V”(5V的值为1023)左右,但是当遮盖传感器时,传感器将给出大约“ 750”左右的值。 “ 10-15”代表“ 40mV”。因此,最好将传感器盖住或放置在只有激光束可以到达的情况下。

一旦激光光束被切割,即使模块再次检测到激光,警报也会响起并且直到按下按钮时才会停止。

电路连接

在这里插入图片描述

代码部分

#define Rec 0      //Light sensor output
#define Laser 2    //Laser module 
#define Button 3   //Push button input

bool detection;

void setup() {
  pinMode(Laser, OUTPUT);
  digitalWrite(Laser, HIGH); //Turning on the laser
  delay(2000);
}

void loop() {

 short Detect = analogRead(Rec);            //Constanly reading the module value
 bool  Button_state = digitalRead(Button);  //And the button value (1-0)
 
 if(Detect < 500)              //The Max value is 760, if someone passes it goes below that (every value lower than 700 can do the work)
    detection = true;          //The detection is triggered

 if(detection==true)
    {
       tone(13,2000);        //Alarm sequence will go on as long as the detection is true
       delay(50);            //This alarm has two sounds 2kHz nd 1Khz delayed by 50ms
       tone(13,1000);
       delay(50);
    }
 
 if(Button_state == HIGH)  //If the button is pressed the buzzer is turned off and the detection too
    {
      detection = false;
      noTone(13);
    }

  
}