Question: basic sketch for pir sensor
help - 0 (0%)
help - 0 (0%)
Total Voters: 0

Pages: [1]   Go Down
Author Topic: basic sketch for pir sensor  (Read 2881 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
Karma: 549
Posts: 27434
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: December 24, 2011, 11:13:52 pm by CrossRoads » Logged

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.

Pages: [1]   Go Up
Jump to: