Go Down

Topic: basic sketch for pir sensor (Read 4916 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.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131