Site Tools


pub:pir_sensor

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
pub:pir_sensor [2019/01/11 16:38]
Adeept
pub:pir_sensor [2019/01/11 18:09] (current)
Adeept ↷ Page moved from pub:pir_sensor:pir_sensor to pub:pir_sensor
Line 1: Line 1:
 ===== PIR Sensor ===== ===== PIR Sensor =====
  
-what's PIR Sensor+what's PIR Sensor\\
  
 The PIR (passive Infrared) sensor can detect the Infrared rays emitted by human or The PIR (passive Infrared) sensor can detect the Infrared rays emitted by human or
Line 11: Line 11:
 size. It can be applied to any cases in detecting moving human or animals.\\ size. It can be applied to any cases in detecting moving human or animals.\\
  
-图片+{{:​pub:​pir_sensor:​pir.jpg?​400|}}\\
  
 Pin definition:​\\ Pin definition:​\\
Line 18: Line 18:
 |    -    |    GND    | |    -    |    GND    |
  
-原理图+{{:​pub:​pir_sensor:​12z.png|}}\\
  
 ---- ----
 ===== Microbit ===== ===== Microbit =====
  
-1 * microbit +1 * microbit\\ 
-1 * microbit expansion board +1 * microbit expansion board\\ 
-1 * USB cable +1 * USB cable\\ 
-1 * PIR Sensor +1 * PIR Sensor\\ 
-- Several Jumper wires+- Several Jumper wires\\
  
 connection diagram: connection diagram:
  
-添加图片+{{:​pub:​pir_sensor:​mpir_ledmodule_bb.png?​400|}}\\
  
 Code:\\ Code:\\
 +makecode:\\
  
-makecode: +{{:pub:​pir_sensor:​2019-01-11_180125.png?​600|}}\\
  
 MU python: MU python:
 <code python> <code python>
 +#​-----------------------------------------------------------
 +# File name   : PIR_sensor.py
 +# Description : The use of the PIR_sensor.
 +# Author ​     : jason
 +# E-mail ​     : jason@adeept.com
 +# Website ​    : www.adeept.com
 +# Date        : 2018/01/10
 +#​-----------------------------------------------------------
 +from microbit import *
  
 +
 +sleep(5000)
 +
 +while True: 
 +    reading = pin0.read_digital()
 +    if reading == 1:
 +        pin1.write_digital(0)
 +        sleep(3000)
 +        pin1.write_digital(1)
 +    sleep(20)
 </​code>​ </​code>​
 +
 +{{:​pub:​pir_sensor:​1m.jpg?​600|}}\\
 +
 +
 +
 ---- ----
 ===== Arduino ===== ===== Arduino =====
  
-Components +Components\\ 
-- 1 * Adeept Arduino UNO R3 Board +- 1 * Adeept Arduino UNO R3 Board\\ 
-- 1 * PIR Sensor Module +- 1 * PIR Sensor Module\\ 
-- 1 * USB Cable +- 1 * USB Cable\\ 
-- 1 * 3-Pin Wires+- 1 * 3-Pin Wires\\
  
 Build the circuit\\ Build the circuit\\
  
-图片+{{:​pub:​pir_sensor:​apirsensormodule.png?​600|}}\\
  
 |    Adeept UNO R3 Board    |    PIR Sensor Module ​   | |    Adeept UNO R3 Board    |    PIR Sensor Module ​   |
-|    D8    |    S    ​| ​   | +|    D8    |    S    | 
-|    3.3V    |    3.3V    ​| ​   | +|    3.3V    |    3.3V    | 
-|    GND    |    -    ​| ​   |+|    GND    |    -    |
  
-Code:+Code:\\
 <code c> <code c>
 +/​***********************************************************
 +File name: _12_PIRSensorModule.ino
 +Description:​ The motion has been detected by PIR sensor module,
 +             and displayed in the serial monitor ​
 +Website: www.adeept.com
 +E-mail: support@adeept.com
 +Author: Tom
 +Date: 2019/​01/​11 ​
 +***********************************************************/​
 +int PIRPin=8; ​          //Set the digital 8 to PIR
 +void setup() {
 +  pinMode( PIRPin,​INPUT);//​initialize the  PIR pin as input
 +  Serial.begin(9600); ​  //​opens serial port, sets data rate to 9600 bps
 +}
 +
 +void loop() {
 +  if(digitalRead(PIRPin)==LOW)
 +  {
 +     ​Serial.println("​No invasion"​);​ //send data to the serial monitor
 +  }else
 +  {
 +     ​Serial.println("​Invasion"​); ​   //send data to the serial monitor
 +  }
 +  delay(1000); ​                      //​delay 1s
 +}
  
 </​code>​ </​code>​
Line 67: Line 116:
 Compile and download the sketch to the UNO R3 board.\\ Compile and download the sketch to the UNO R3 board.\\
  
-图片 +{{:​pub:​pir_sensor:​1a.png?​600|}}\\ 
-图片+{{:​pub:​pir_sensor:​2a.png?​600|}}\\
  
 Open the Serial Monitor in Arduino IDE. When the PIR module detects human movement, Open the Serial Monitor in Arduino IDE. When the PIR module detects human movement,
 "​Invasion!"​ will be displayed on the window; otherwise, "No invasion"​\\ "​Invasion!"​ will be displayed on the window; otherwise, "No invasion"​\\
  
 +{{:​pub:​pir_sensor:​pirsensormodulea.jpg?​600|}}\\
  
 ---- ----
 ===== Raspberry pi ===== ===== Raspberry pi =====
  
-Components +Components\\ 
-- 1 * Raspberry Pi +- 1 * Raspberry Pi\\ 
-- 1 * GPIO Extension Board +- 1 * GPIO Extension Board\\ 
-- 1 * 40-Pin GPIO Cable +- 1 * 40-Pin GPIO Cable\\ 
-- 1 * Breadboard +- 1 * Breadboard\\ 
-- 1 * PIR Sensor Module +- 1 * PIR Sensor Module\\ 
-- 1 * 3-Pin Wires+- 1 * 3-Pin Wires\\
  
  
 Build the circuit\\ Build the circuit\\
  
-图片+{{:​pub:​pir_sensor:​1r6.jpg?​600|}}\\
  
  
-Code:+Code:\\
 C code:\\ C code:\\
 <code c> <code c>
 +/*
 +* File name   : Pir.c
 +* Description : Intrusion detection
 +* Website ​    : www.adeept.com
 +* E-mail ​     : support@adeept.com
 +* Author ​     : Jason
 +* Date        : 2019/01/10
 +*/
 +#include <​wiringPi.h>​
 +#include <​stdio.h>​
 +
 +#define Pir_S  0
 +
 +void myISR(void)
 +{
 + printf("​Someone invasion !!!\n"​);​
 +}
 +
 +int main(void)
 +{
 + if(wiringPiSetup() == -1){
 + printf("​setup wiringPi failed !\n");
 + return -1; 
 + }
 +
 + pinMode(Pir_S,​ INPUT);
 +
 + pullUpDnControl(Pir_S,​ PUD_DOWN);
 +
 + if(wiringPiISR(Pir_S,​ INT_EDGE_RISING,​ myISR) < 0){
 + printf("​ISR setup error!\n"​);​
 + return -1;
 + }
 +
 + while(1){
 +
 + }
 +
 + return 0;
 +}
  
 </​code>​ </​code>​
Line 100: Line 189:
 Python code:\\ Python code:\\
 <code python> <code python>
 +#​!/​usr/​bin/​env python
 +
 +import RPi.GPIO as GPIO
 +import time
 +
 +PIR_OUT_PIN = 11    # pin11
 +
 +def setup():
 + GPIO.setmode(GPIO.BOARD) ​      # Numbers GPIOs by physical location
 + GPIO.setup(PIR_OUT_PIN,​ GPIO.IN) ​   # Set BtnPin'​s mode is input
 +
 +def loop():
 + while True:
 + if GPIO.input(PIR_OUT_PIN) == GPIO.LOW:
 + print '​...Movement not detected!'​
 + else:
 + print '​Movement detected!...'​
 +
 +def destroy():
 + GPIO.cleanup() ​                    # Release resource
 +
 +if __name__ == '​__main__': ​    # Program start from here
 + setup()
 + try:
 + loop()
 + except KeyboardInterrupt: ​ # When '​Ctrl+C'​ is pressed, the child program destroy() will be  executed.
 + destroy()
 +
  
 </​code>​ </​code>​
Line 132: Line 249:
  
  
-图片 +{{:​pub:​pir_sensor:​16r.jpg?​600|}}\\
- +
- +
- +
- +
- +
  
 +\\
 +\\
 +\\
 Reference material:http://​www.adeept.com/​learn/​ \\ Reference material:http://​www.adeept.com/​learn/​ \\
 Video:http://​www.adeept.com/​video/​ \\ Video:http://​www.adeept.com/​video/​ \\
pub/pir_sensor.1547195933.txt.gz · Last modified: 2019/01/11 16:38 by Adeept