Category Archives: Sensor

Introduction to Passive Infrared Sensor

I just received a PIR sensor in my latest Adafruit delivery. I quickly scanned the web and found 2 projects that I don’t want to do with infrared: Send email and a Walmart greeter… But I’ll use these projects to learn how to wire the PIR and how to read it’s input.

The PIR is very simple to wire up. Black and red to ground and +5v, the middle yellow wire goes into an input pin on the Arduino.  To keep things simple, I’m using a digitalWrite() so the motion sensor will either output HIGH when motion is detected and LOW when no movement is sensed.

Here’s the code. It’s light a LED on pin 11 when the sensor is triggered:

* Simple example of reading from a Passive IR Sensor

// Connect PIR miidle pin to A1
const int inPirSensorPin = 7;
const int redLedPin = 11;

void setup() {
  // initialize serial com
  // PIR will be a digital input
  pinMode(inPirSensorPin, INPUT);
  // Red LED is an output
  pinMode(redLedPin, OUTPUT);

void loop() {
  // read the sensor:
  //int pirSensorValue = analogRead(pirSensorPin);
  int pirSensorValue = digitalRead(inPirSensorPin);
  if (pirSensorValue == HIGH) {
    analogWrite(redLedPin, 255);
  else {
    analogWrite(redLedPin, 0);
  // print out to serial
  //Serial.print("PIR value:"); Serial.println(pirSensorValue);
  // wait 100 ms

My first surprise is that the signal is very low frequency. You can read it every 100 milliseconds if you like (as in the example), but the signal only changes about every 10 seconds. I noticed there are 2 pots on the side of the PIR sensor unit. I will look into and report on a following post.