개발자/Raspberry Pi

미니 인체감지 센서 테스트 HC-SR505 Mini PIR Motion Sensor

지구빵집 2015. 10. 7. 09:17
반응형




HC-SR505 Mini PIR Motion Sensor

가 어떻게 생겨 먹었나 아래를 참고한다. 예전에 많이 사용했던 인체감지 센서와 다르게 많이 작다.
사이즈가 10mm * 23mm 이고, 센서 둥근 원형도 지름이 약 11mm 이다.




아래와 같이 연결한다.




시험을 하기 위해 Vcc 를 3.3V 로 주니 출력이 계속 High, 즉 인체가 감지된 상태의 출력만 나온다. 

그리하여 일명 스펙이라하는 데이터 시트를 찾아보았더니 아래와 같다.


Specification

  • Operating voltage range: DC4.5-20V
  • Quiescent Current: <60uA
  • Level output: Gao 3.3V / Low 0V
  • Trigger: reusable trigger (default)
  • Delay Time: The default 8S + -30%
  • Board Dimensions: 10 * 23mm
  • Induction angle: <100 degrees cone angle
  • Sensing distance: 3 meters
  • Working temperature: -20 to +80 degrees
  • Sensor Lens Dimensions: Diameter: 10mm

 


봐라. 입력 전원이 4.5V 이상이다.

5V 를 연결하고 시험했더니 잘 나온다.


라즈베리 파이에서 테스트 한 소스 코드는 아래와 같고, 참고 이미지도 올린다.

이미지 출처는   http://www.elecrow.com/hcsr505-mini-pir-motion-sensor-p-1382.html



아래 코드 넣는 자리


 #include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <wiringPi.h>


// Use GPIO Pin 17, which is Pin 0 for wiringPi library

#define MOTION_IN 0  //gpio17


// the event counter 
volatile int eventCounter = 0;
unsigned char humandetect = 0;
int counter = 0;


// -------------------------------------------------------------------------
// myInterrupt:  called every time an event occurs
void myInterrupt(void) {
   eventCounter++;
   humandetect = 1;

}


// -------------------------------------------------------------------------
// main
int main(void) {
  // sets up the wiringPi library
  if (wiringPiSetup () < 0) {
      fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno));
      return 1;
  }

  // set Pin 17/0 generate an interrupt on high-to-low transitions
  // and attach myInterrupt() to the interrupt
  if ( wiringPiISR (MOTION_IN, INT_EDGE_RISING, &myInterrupt) < 0 ) {
      fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno));
      return 1;
  }

  // display counter value every second.
  while ( 1 ) {
    if(humandetect == 1)
	{
		printf("Detect %d\n", eventCounter );
		humandetect = 0;
		while(digitalRead(MOTION_IN))
        	{
            		printf("high %d \n", counter++);
            		delay(1000);
        	}
		counter = 0;
	}
	else
	{
		printf(" No detect\n");
	}		
    //eventCounter = 0;
    delay( 500 ); // wait 1 second
  }

  return 0;
}


테스트 해보니 인체가 감지되고 약 7초간 High 신호를 유지하고, Low 로 떨어진다. 계속 감지한 채 있다면 계속 High 유지한다.


 No detect

 No detect

 No detect

Detect 123

high 0

high 1

high 2

high 3

high 4

high 5

high 6

high 7

 No detect

 No detect










끝.






반응형