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 17:53]
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 23: Line 23:
 ===== 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:
Line 34: Line 34:
  
 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>​
  
Line 61: Line 80:
  
 |    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 97: Line 141:
  
  
-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 105: 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 139: Line 251:
 {{:​pub:​pir_sensor:​16r.jpg?​600|}}\\ {{:​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.1547200431.txt.gz · Last modified: 2019/01/11 17:53 by Adeept