BASIC4MCU | 질문게시판 | 마이크로웨이브 질문합니다~
페이지 정보
작성자 야채왕 작성일2019-05-20 10:38 조회13,438회 댓글5건본문
마이크로웨이브 모션감지 센서인데 이게 주변 물체의 가속도가 클수록 큰 값이 나오거든요 그래서 일정 값이 상 나올때
led불이 켜지는 방식으로 만들어 보고싶어서 코딩좀 부탁드립니다. 일정값의 세팅은 55로 부탁드립니다.
#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.
}
댓글 5
조회수 13,438master님의 댓글
master 작성일
55라는 것이 무엇을 의미하는 것인지 모르겠습니다.
현재 코드는 1초안에 인터럽트가 몇번 걸리는지를 체크하고 있습니다.(물론 1회 이상인지만 체크합니다.)
센서 출력의 주기가 변하는지 듀티가 변하는지를 알아야하고
그 값의 범위도 알아야합니다.
//
센서 판매사이트 링크 걸어보세요
야채왕님의 댓글
야채왕 작성일
https://wiki.dfrobot.com/MicroWave_Sensor_SKU__SEN0192
제가 잘 이해를 못했나 보군요
저는 가속도가 클수록 값이 크게 출력된다고 생각해서 제가 변경하기 쉽도록 그 값이 55 이상일때 불이 켜지게 끔 부탁드린다고 글을 썼던 것입니다만..
일정 시간동안 측정되는 값이 일정수준 이상일때 led가 켜지는 메커니즘으로 코딩 부탁드립니다 ㅠㅠ
master님의 댓글
master
motion detection용 센서입니다.
예제에서는 스위치 읽듯이 읽고 있으므로 아나로그 값을 읽는 예제가 있는지 검색해보세요
야채왕님의 댓글
야채왕
아하 그런식이였군요
그렇다면 스위치 형식인데 왜 시리얼 모니터에 0 과 1 이 아닌 다른숫자도 출력이 되는것인가요?
또한 스위치 형식이라고 하셨으니까 모션이 감지될 경우 led on되는 코딩으로 부탁드립니다!
master님의 댓글
master
스스로 할 수 있어야합니다.
https://www.google.com/search?q=%EC%95%84%EB%91%90%EC%9D%B4%EB%85%B8+%EC%8A%A4%EC%9C%84%EC%B9%98+LED&pws=0&gl=us&gws_rd=cr