The usefulness of this sensor allows you to detect gerakan.Mereka often refer to this as the PIR sensor, "Passive Infrared", "pyroelectric", or "IR" movement sensor. / (Digital infrared motion sensor)
PIR is basically made of a pyroelectric sensor (which you can see above a round metal can with a square crystal in the middle), which can detect infrared radiation levels. Everything emits some low-level radiation, and panas.Jika more radiation is emitted. Sensor detector will see the size of the IR from the other, and the output will swing high or low
SPECIFICATION:
- Type: Digital
- :3-5V Supply Voltage
- Current: 50μA
- Working temperature: 0 ℃ -70 ℃
- Output level (HIGH): 4V
- Output level (LOW): 0.4V
- Detect angle: 110 Degree
- Detect distance: 7 meters
- Size: 28mm x 36mm
- Weight: 25g
PIR sensor reading
PIR sensor connects to the microcontroller is really simple. PIR acts as a digital output, so all you need to do is use a pin to flip high (detected) or low (undetectable).
Power PIR to 5V and ground is connected to ground. Then connect the output to a digital pin. In this example we will use the pin 2.
The code is very simple, and basically just keep track of whether the input to pin 2 high or low. So that it prints a message when the movement has been started and stopped.
PIR sensor connects to the microcontroller is really simple. PIR acts as a digital output, so all you need to do is use a pin to flip high (detected) or low (undetectable).
Power PIR to 5V and ground is connected to ground. Then connect the output to a digital pin. In this example we will use the pin 2.
The code is very simple, and basically just keep track of whether the input to pin 2 high or low. So that it prints a message when the movement has been started and stopped.
/*
* PIR sensor tester
*/
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
0 komentar:
Posting Komentar