반응형
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
끝.
반응형
'개발자 > Raspberry Pi' 카테고리의 다른 글
라즈베리파이 - 리눅스 시스템 모니터링 명령어 (0) | 2015.12.27 |
---|---|
어딜 가도 나이 드신 분들이 많이 온다. - 제15회 K.E.L.P 공개 세미나 참석 후기 (0) | 2015.12.07 |
Raspberry Pi with Linux LESSONS - 라즈베리 파이 레슨 자료 링크 (0) | 2015.11.24 |
영상의 분산 처리를 통한 무인 주행 시스템 - 참고자료 부분 (0) | 2015.10.07 |
리눅스든, 윈도우든 SD 카드 초기화 프로그램 (0) | 2015.08.12 |
오픈 소스 하드웨어 추천 사이트 정리 (0) | 2015.08.02 |
라즈베리 파이 SD 카드 만들어 부팅하기 (0) | 2015.07.26 |
라즈베리파이 개발환경을 3가지 방법으로 구현하기 (3) | 2015.07.24 |
더욱 좋은 정보를 제공하겠습니다.~ ^^