2020-1-23 17:41:07 [显示全部楼层]
2303浏览
查看: 2303|回复: 4

[项目] 室内驱狗神器的诞生

[复制链接]
不知你们有没有这样的经历,刚买的沙发,自己都不舍得坐呢,一个不看住,狗狗把沙发造的不要不要的。
这次这个项目就是告诉大家怎么造一个驱宠神器,神器放在沙发的上面,当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最后说一句,本人不养宠物。




hnyzcj  版主

发表于 2020-1-23 18:54:34

虐待小动物
回复

使用道具 举报

DFrJ5KYVQaH  中级技匠

发表于 2020-1-24 07:51:52

爱护小动物是一种美德
回复

使用道具 举报

gada888  版主
 楼主|

发表于 2020-1-28 12:02:32


还好吧。那个激光头基本不会对动物带来伤害。
回复

使用道具 举报

kylinpoet  初级技神

发表于 2020-2-18 08:37:21

这个好,必须支持。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail