gada888 发表于 2018-8-30 08:20:50

自制一个PIR人体热感报警器

PIR简介


下面学一个简单的报警器,主控用attiny85

//---made by gada888---2018-08-30---
void setup() {
pinMode(1, OUTPUT);
pinMode(0, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {

int sensorValue = digitalRead(0);

if(sensorValue==1)
{
    digitalWrite(1, HIGH);
    delay(3000);
}

else
{
    digitalWrite(1, LOW);
}

delay(1);      // delay in between reads for stability
}
再来个个人原创的报警声音放大版的。

//---made by gada888-----
const int pirPin = 0;   // PIR sensor
const int buzzer = 1;   // buzzer

int alarmLength = 40;
// the setup routine runs once when you press reset:
void setup() {
pinMode(1, OUTPUT);
pinMode(0, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {

int sensorValue = digitalRead(0);
if(sensorValue==1){
while(alarmLength >= 0){
      alarmLength--;
      alarmOn(100);
    }
    alarmLength = 40;
}
else {
    alarmOff();
}
delay(1);      // delay in between reads for stability
}
void alarmOn(int delayMs){
analogWrite(buzzer, 100);
delay(delayMs);
analogWrite(buzzer, 0);
delay(delayMs);
}

void alarmOff(){
analogWrite(buzzer, 0);
}


https://v.youku.com/v_show/id_XMzgwMzQxOTcyNA==.html?spm=a2h3j.8428770.3416059.1

gada888 发表于 2018-8-30 08:21:26

沙发

gada888 发表于 2018-8-30 08:21:39

板凳

gada888 发表于 2018-8-30 08:21:48

地板

gada888 发表于 2018-8-30 08:21:57

地下室

gada888 发表于 2018-8-30 08:23:03

attiny85要用专用的烧录器,其实针脚一换,可以上传程序到arduino上

gada888 发表于 2018-8-30 08:24:49

电源控是LP2950-5V。忘写了

gada888 发表于 2018-8-30 08:25:25

喇叭是3-24V那种,5v声音也不小了。

gada888 发表于 2018-8-30 08:26:40

用attiny85是为了简单便携

hnyzcj 发表于 2018-8-30 22:42:19

楼主占楼的能力炒鸡厉害

嘉央 发表于 2024-7-11 16:42:19

这个在米司齐里面可以运行吗
页: [1]
查看完整版本: 自制一个PIR人体热感报警器