Go Down

Topic: basic sketch for pir sensor (Read 2 times) previous topic - next topic


basic sketch for pir sensor

i want to try my pir sensor, can anybody help me


Dec 25, 2011, 04:25 am Last Edit: Dec 25, 2011, 05:13 am by CrossRoads Reason: 1
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.
Code: [Select]

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
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Go Up