5159| 2
|
[进阶] 快上车,教你一个实用的震动MP3报警器 |
快过年了。都希望家里常平安。这次教大家一个报警器,目的是让盗贼在动你家大门时候,先是触发震动传感,继而通过Arduino 控制的MP3模块播放老人说话的声音。用来迷惑盗贼。让他们误以为家中有人。这样也许会避免不必要的财产损失。 硬件清单 1. 常闭型震动传感器模块 报警器感应模块 SW420 2.DFPlayer mini 3. 连线:DFPLayer mini 的RX,TX分别连UNO的TX,RX。 SPK-1和SPK-2连一个8欧喇叭。不分正负。 [mw_shl_code=applescript,true]//mady by gada888----2018-11-25 #include <SoftwareSerial.h> #include <DFPlayer_Mini_Mp3.h> int ledPin =13; int EP =9; void setup(){ pinMode(ledPin, OUTPUT); pinMode(EP, INPUT); //set EP input for measurment Serial.begin(9600); //init serial 9600 Serial.println("----------------------Vibration demo------------------------"); mp3_set_serial (Serial); //set Serial for DFPlayer-mini mp3 module mp3_set_volume (25); // 15 is low for unpowered speaker - had to remove reset to get vol to work delay (400); randomSeed(analogRead(0)); } void loop(){ long measurement =TP_init(); delay(50); Serial.print("measurment = "); Serial.println(measurement); z=random(1,11); if (measurement > 1000){ digitalWrite(ledPin, HIGH); mp3_play(z); } else{ digitalWrite(ledPin, LOW); } } long TP_init(){ delay(10); long measurement=pulseIn (EP, HIGH); //wait for the pin to get HIGH and returns measurement return measurement; } [/mw_shl_code] |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed