정보나눔

오픈소스하드웨어 프로젝트에 대한 다양한 정보를 나누는 공간입니다.

microwave motion sensor
gkgk | 2018-08-02

#include <MsTimer2.h>           //Timer interrupt function library
int pbIn = 0;                    // Define interrupt 0 that is digital pin 2
int ledOut = 13;                 // Define the indicator LED pin digital pin 13
int number=0;                    //Interrupt times
volatile int state = LOW;         // Defines the indicator LED state, the default is not bright
 
void setup()
{      
     Serial.begin(9600);          
     pinMode(ledOut, OUTPUT);// 
     attachInterrupt(pbIn, stateChange, FALLING); // Set the interrupt function, interrupt pin is digital pin D2, interrupt service function is stateChange (), when the D2 power change from high to low , the trigger interrupt.
     MsTimer2::set(1000, Handle); // Set the timer interrupt function, running once Handle() function per 1000ms 
     MsTimer2::start();//Start timer interrupt function
}
 
void loop()                     
{
Serial.println(number); // Printing the number of times of interruption, which is convenient for debugging.
    delay(1);        
    if(state == HIGH)  //When a moving object is detected, the ledout is automatically closed after the light 2S, the next trigger can be carried out, and No need to reset. Convenient debugging.
  {
    delay(2000);
    state = LOW;
    digitalWrite(ledOut, state);    //turn off led
  }
 }
 
void stateChange()  //Interrupt service function
{  
  number++;  //Interrupted once, the number +1
}
void Handle()   //Timer service function
{
  if(number>1)  //If in the set of the interrupt time the number more than 1 times, then means have detect moving objects,This value can be adjusted according to the actual situation, which is equivalent to adjust the threshold of detection speed of moving objects.
       {
                   state = HIGH;            
                   digitalWrite(ledOut, state);    //light led
                   number=0;   //Cleare the number, so that it does not affect the next trigger
       }
        else
            number=0;   //If in the setting of the interrupt time, the number of the interrupt is not reached the threshold value, it is not detected the moving objects, Cleare the number.
}

 

https://blog.naver.com/PostView.nhn?blogId=rlrkcka&logNo=221293761624&categoryNo=18&parentCategoryNo=0&viewDate=&currentPage=1&postListTopCurrentPage=1&from=post

 

위의 블로그처럼 회로를 구성하고 코딩을하여 모션 센서 1개를 이용해서는 감지 횟수를 카운트 할 수 있었는데,

만약 모션센서 2개를 사용해서 한개가 감지하면 나머지 한개도 작동되어, 두 센서 모두 감지될때만 카운트 되도록 할 수 있을까요?

된다면 어떻게 코딩해야나요..?

이전글   |    헤더 파일 컴파일 에러 2018-07-31
다음글   |    2.8 tftlcd 그리기예제 2018-08-02