basic sketch for pir sensor
i want to try my pir sensor, can anybody help me
basic sketch for pir sensor
i want to try my pir sensor, can anybody help me
Sure.
Connect PIR sensor output to 10K resistor to +5V, and the same pin to D2 on your arduino.
Onboard LED should light up when the PIR output is active, which is usually low.
byte pirPin = 2; // define the IO pins
byte ledPin = 13;
void setup(){
pinMode (pirPin, INPUT); // set them as inputs/outputs
pinMode (ledPin, OUTPUT);
}
void loop(){
if (digitalRead (pirPin) == LOW){ // read the input pin
digitalWrite (ledPin, HIGH); // and drive the LED on
}
else { // pirPin is high, so
digitalWrite (ledPin, LOW); // drive the LED off
}
}