본문 바로가기

개발자/Raspberry Pi

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

반응형




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










끝.






반응형

캐어랩 고객 지원

취업, 창업의 막막함, 외주 관리, 제품 부재!

당신의 고민은 무엇입니까? 현실과 동떨어진 교육, 실패만 반복하는 외주 계약, 아이디어는 있지만 구현할 기술이 없는 막막함.

우리는 알고 있습니다. 문제의 원인은 '명확한 학습, 실전 경험과 신뢰할 수 있는 기술력의 부재'에서 시작됩니다.

이제 고민을 멈추고, 캐어랩을 만나세요!

코딩(펌웨어), 전자부품과 디지털 회로설계, PCB 설계 제작, 고객(시장/수출) 발굴과 마케팅 전략으로 당신을 지원합니다.

제품 설계의 고수는 성공이 만든 게 아니라 실패가 만듭니다. 아이디어를 양산 가능한 제품으로!

귀사의 제품을 만드세요. 교육과 개발 실적으로 신뢰할 수 있는 파트너를 확보하세요.

지난 30년 여정, 캐어랩이 얻은 모든 것을 함께 나누고 싶습니다.

카카오 채널 추가하기

카톡 채팅방에서 무엇이든 물어보세요

당신의 성공을 위해 캐어랩과 함께 하세요.

캐어랩 온라인 채널 바로가기

캐어랩