2016년 5월 24일 화요일

Raspberry Pi - PIR Motion Sensor test

PIR motion sensor used to detect whether a object which emits infrared radiation has moved in or out the sensor range. If the sensor detect a moving object, it make output signal. More infromation about the sensor can be found in the following web page. In order to test, the wiringPi must be installed.

http://www.dfrobot.com/wiki/index.php/PIR_Motion_Sensor_V1.0_SKU:SEN0171

The test circuit is shown as in figure.

Component

  • Raspberry Pi 2 Model B
  • PIR Motion Sensor (DFROBOT SEN0171)


In order to test, make a simple code which is pirTest.c

#include <stdio.h>
#include <wiringPi.h>

#define PIR 1

int main(void)
{
  if(wiringPiSetup() == -1)
    return 1;

  pinMode(PIR, INPUT);

  int input = 0;

  for(;;)
  {
    if(digitalRead(PIR))
      printf("Motion Detected!\n");

    delay(100);
  }

  return 0;
}

Compile and run the program.

pi@raspberrypi ~$ gcc -o pirTest pirTest.c -lwiringPi
pi@raspberrypi ~$ sudo ./pirTest

When a moving object is detected, "Motion Detected" message will be printed.

0 개의 댓글:

댓글 쓰기