본문 바로가기

임베디드 보드/아두이노

NANO + PIR SENSOR + RELAY + AIR CURTAINS

728x90

에어커튼을 인체감지시에만 동작하도록 프로그래밍

 

NANO 설정


https://m.blog.naver.com/hy10101010/221562445464

PIR SENSOR

   
센서 민감도를 조정

릴레이

   
 
   

구성

   
PIR SENSOR

ARDUINO NANO

RELAY MODULE
   

 

 

소스코드

int PIN_PIR = A7;
int PIN_D12 = 12;
int PIN_RELAY = 2;
#define RELAY_TIMEOUT 100 // 20 sec
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(PIN_PIR, INPUT);
  pinMode(PIN_D12, OUTPUT);
  pinMode(PIN_RELAY, OUTPUT);
  digitalWrite(PIN_D12, 0);
  digitalWrite(PIN_RELAY, false);
  
}

int timeout = 0;

void loop() {
  // put your main code here, to run repeatedly:
  int value = 500 < analogRead(PIN_PIR) ? 1 : 0;

  
  if(value == 1) {
    if(timeout == 0) {
      timeout = RELAY_TIMEOUT;
      digitalWrite(PIN_RELAY, true);
    }
  }

  Serial.print(value);
  Serial.print(',');
  Serial.println(timeout);

  if(0 < timeout) {
    timeout -= 1;  
    if(timeout == 0) digitalWrite(PIN_RELAY, false);
  }
  
  delay(100);
}

테스트