6. PIR sensor

PIR sensor


aansluitschema:
 
 

 
 
 extra info / specificaties:
-Spanning: 5V(DC)
-Uitgangssignaal: elektrische frequentie signaal, hoge niveau 5V, lage niveau 0V.
-Sensor hoek: niet meer dan 15 graden.
-De waarnemingsafstand: 2cm ~ 450cm.
-Hoge precisie: tot 3mm
-De wijze van verbinding: VCC / trig(T) / echo(R) / GND
- DX.com art no SKU 157004
 
punten van aandacht:
- kalibratietijd van de sensor is ingesteld op 30 seconden, maar kan worden gewijzigd.
- inschakeltijd kan ook worden ingesteld.

Code:
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;
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); Serial.print("calibrating sensor");
for (int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000);
}
}
 
void loop(){
val = digitalRead(inputPin); // read input value
Serial.println(val); if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
delay(150); 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
delay(300);
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;
}
}
}

library: nvt

leveranciers: nvt

magazijn: ladekast 2 :43