红外运动探测器

创意展示、DIY分享、经验交流
回复
头像
shaoziyang
帖子: 3917
注册时间: 2019年 10月 21日 13:48

红外运动探测器

#1

帖子 shaoziyang »

来自:https://www.hackster.io/309095/pir-moti ... tor-a31b09

图片

这个项目中使用的东西  未触发运动检测器时,在LCD上显示“正在休眠...”,检测到运动时,Particle发出正信号时,LCD上显示了“我爱高尔夫”。

提示
  • 可以使用设备电路板上的板载电位计来更改运动检测器的灵敏度。
  • 确保所有电线连接良好
  • 每次Particle编程后,请拔下设备的电源,然后重新插入。
  • Particle发生故障时,将其置于安全模式,然后重新刷新代码。
图形

图片
PIR运动传感器数据

原理图
Argon 1 (PIR Motion Sesnor)

图片Argon 2 (LCD Screen)

图片


代码

LCD

Code: Select all

// This #include statement was automatically added by the Particle IDE.


#include "application.h"
#include <LiquidCrystal.h>
/*
LiquidCrystal Library - Hello Sparky

Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.

This sketch prints "Hello World!" to the LCD
and shows the time.

The circuit:
* LCD RS pin to digital pin D0
* LCD EN pin to digital pin D1
* LCD D4 pin to digital pin D2
* LCD D5 pin to digital pin D3
* LCD D6 pin to digital pin D4
* LCD D7 pin to digital pin D5
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
* connect R/W (pin 5) to ground

Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 8 Feb 2010
by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/LiquidCrystal
*/


// Make sure to update these to match how you've wired your pins.
//pinout on LCD [RS, EN, D4, D5, D6, D7];
// pin nums LCD [ 4, 6, 11, 12, 13, 14];
// Shield Shield [RS, EN, D4, D5, D6, D7];
// Spark Core [D3, D5, D2, D4, D7, D8];
LiquidCrystal lcd(D0, D1, D2, D3, D4, D5);
int temperature;
int ledwork;
void analogvalue(const char *event, const char *data )
{
String pew = data;
temperature = pew.toInt();
}


void setup() {

Particle.subscribe("PIRMOTION", analogvalue, ALL_DEVICES);
// set up the LCD's number of columns and rows:
lcd.begin(16,2);
// Print a message to the LCD.
Particle.publish("led", ledwork, ALL_DEVICES);

}

void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):

lcd.setCursor(0, 1);
// print the number of seconds since reset:
if ( temperature > 3000 ) {
lcd.begin(16,2);
lcd.print("I love Golf");
delay (1000);
ledwork = 1;

}
else {
lcd.begin(16,2);
lcd.print("sleeping...");
led = 0;
}
}
运动检测

Code: Select all

// This #include statement was automatically added by the Particle IDE.
#include <ThingSpeak.h>

// This #include statement was automatically added by the Particle IDE.


int analogvalue = 0;

int led2 = D7; // Instead of writing D7 over and over again, we'll write led2
// This one is the little blue LED on your board. On the Photon it is next to D7, and on the Core it is next to the USB jack.



unsigned long myChannelNumber = 919100;
const char * myWriteAPIKey = "T0CB3GU5EV6G4373";


void setup()
{
Particle.variable("analogvalue", analogvalue);

pinMode(A0, INPUT);

// Subscribe to the integration response event
Particle.subscribe("hook-response/Motion", myHandler, MY_DEVICES);

pinMode(led2, OUTPUT);


}
void myHandler(const char *event, const char *data) {
// Handle the integration response
}


void loop()
{
// Read the analog value of the sensor (TMP36)
analogvalue = analogRead(A0);


Particle.publish("Motion", String(analogvalue), ALL_DEVICES);
delay(1000);
Particle.subscribe("led", ledwork, ALL_DEVICES);
// below: if the lcd is changed, the value of ledwork will be 1, and then blink the led on the motion argon.
if ledwork = 1 {

digitalWrite(led2, HIGH);

// We'll leave it on for 1 second...
delay(1000);

// Then we'll turn it off...

digitalWrite(led2, LOW);

// Wait 1 second...
delay(1000);

}


}

回复

  • 随机主题
    回复总数
    阅读次数
    最新文章