室内驱狗神器的诞生

2020-01-231.1万
AI 快速预览详细 收起
该项目介绍了一个基于Arduino Uno的室内驱狗神器。硬件清单包括Arduino Uno、DF mp3模块、激光头5v、9g伺服电机和PIR传感器。当PIR传感器检测到生物靠近时,MP3会发出语音警告,并且伺服电机带动激光随机扫射2秒,以驱赶宠物。这个项目不仅能够保护家具,还能作为STEM教育的一个有趣案例,适合家长和孩子一起动手制作。
不知你们有没有这样的经历,刚买的沙发,自己都不舍得坐呢,一个不看住,狗狗把沙发造的不要不要的。
这次这个项目就是告诉大家怎么造一个驱宠神器,神器放在沙发的上面,当PIR传感识别靠近的生物时,mp3马上语音警告,同时伺服电机带动打开的激光随机扫2秒,一方面吸引狗狗的注意,一方面驱赶狗狗。


硬件清单
1.Arduino uno
室内驱狗神器的诞生图1
2.DF mp3
室内驱狗神器的诞生图2
3.激光头5v
室内驱狗神器的诞生图3
4.伺服电机9g
室内驱狗神器的诞生图4
5.PIR传感
室内驱狗神器的诞生图5
连线图
室内驱狗神器的诞生图10
PIR脚位图
室内驱狗神器的诞生图6
MP3文件拷贝目录
室内驱狗神器的诞生图9
下面是代码
[mw_shl_code=applescript,false]/*
made by gada888 in Luoyang China.Date:2020-1-20
*/
#include <SoftwareSerial.h>
SoftwareSerial Serial1(10, 11);
#include "Servo.h"  
Servo ServoOne;                  // Generates an instance of a servo object
int ServoPosition = 0;           // Variable to be used to assign position of

int laserPin = 12; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status

unsigned char order[4] = {0xAA,0x06,0x00,0xB0};

void setup() {

ServoOne.attach(9);            // Assigns pin 9 as a servo

pinMode(laserPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input

Serial.begin(115200);
Serial1.begin(9600);
volume(0x1E);//闊抽噺璁剧疆0x00-0x1E
}
void loop(){
  
val = digitalRead(inputPin); // read input value

if (val == HIGH) { // check if the input is HIGH
  
digitalWrite(laserPin, HIGH); // turn LED ON
  
  ServoPosition = random(0,90); // Generates a random number and stores it in ServoPosition
  ServoOne.write(ServoPosition); // Commands servo to spin to position
  delay(2000);                   // Delays for 1000 ms
  

if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
play(0x01);//鎸囧畾鎾斁:0x01-鏂囦欢0001
//delay(1000);
}
} else {
digitalWrite(laserPin, LOW); // turn LED OFF
//playMP3;
//delay(1000);
if (pirState == HIGH){
// we have just turned off
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
// =========FUNCTION============
void play(unsigned char Track)
{
unsigned char play[6] = {0xAA,0x07,0x02,0x00,Track,Track+0xB3};//0xB3=0xAA+0x07+0x02+0x00,鍗虫渶鍚庝竴浣嶄负鏍¢獙鍜?
Serial1.write(play,6);
}
void volume( unsigned char vol)
{
unsigned char volume[5] = {0xAA,0x13,0x01,vol,vol+0xBE};//0xBE=0xAA+0x13+0x01,鍗虫渶鍚庝竴浣嶄负鏍¢獙鍜?
Serial1.write(volume,5);
}[/mw_shl_code]

运行代码成功图
室内驱狗神器的诞生图7
演示图
室内驱狗神器的诞生图8最后说一句,本人不养宠物。




创作许可协议

本项目采用 None(不开放任何权利,保留所有权利) 进行许可。

评论(3)
kylinpoet
kylinpoet
这个好,必须支持。
DFrJ5KYVQaH
DFrJ5KYVQaH
爱护小动物是一种美德
hnyzcj
hnyzcj
虐待小动物
gada888
gada888
作者
回复hnyzcj
还好吧。那个激光头基本不会对动物带来伤害。
- 没有更多了 -