Home Chapter 9 Maxuino/Arduino passive infrared sensor

Site Search


Chinese (Simplified) French German Italian Portuguese Russian Spanish
Maxuino/Arduino passive infrared sensor

A wonderful pyroelectric sensor device that detects motion by measuring changes in the infrared (heat) levels emitted by surrounding objects is the PIR sensor. It can be used for sensing out to a distance of 30 feet down to a few feet.  The PIR  (passive infrared sensor) is best used on a platform or artworks that are not moving, as they sense by imaging infrared light emitted and when they detect a change in infrared quanta, they switch high at 5-volts.

They are robust and easy to use though they can also switch off and on quickly, that sometimes software filtering is a good idea.

They have a longer detection range, selectable by an on-board jumper and a wider supply voltage that can range from 3 to 6 VDC.

The PIR Motion Sensor:x


Detect a person up to - 30 ft. away, or up to 15 ft. away in reduced sensitivity mode

Jumper selects normal operation or reduced sensitivity

Source current up to 12 mA @ 3 V, 23 mA @ 5 V

Mounting holes for 2-56 sized screws

3-pin SIP header ready for breadboard or through-hole projects

You can find the PDF data sheet here


PIR sensor (larger then actual size.)

Notice pins (GND, VCC, and OUT) VCC goes to Voltage + and out to the signal input

You would attach this sensor exactly as if you were attaching an input switch to your Arduino UNO Microcontroller and therefore you can use the Button code provided in the Arduino Examples below.



Turns on and off a light emitting diode(LED) connected to digital

pin 13, when pressing a pushbutton attached to pin 2.

The circuit:

* LED attached from pin 13 to ground

* pushbutton attached to pin 2 from +5V

* 10K resistor attached to pin 2 from ground

* Note: on most Arduinos there is already an LED on the board

attached to pin 13.

created 2005

by DojoDave <http://www.0j0.org>

modified 30 Aug 2011

by Tom Igoe

This example code is in the public domain.



// constants won't change. They're used here to

// set pin numbers:

const int buttonPin = 2;     // the number of the pushbutton pin

const int ledPin =  13;      // the number of the LED pin

// variables will change:

int buttonState = 0;         // variable for reading the pushbutton status

void setup() {

// initialize the LED pin as an output:

pinMode(ledPin, OUTPUT);

// initialize the pushbutton pin as an input:

pinMode(buttonPin, INPUT);


void loop() {

// read the state of the pushbutton value:

buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.

// if it is, the buttonState is HIGH:

if (buttonState == HIGH) {

// turn LED on:

digitalWrite(ledPin, HIGH);

} else {

// turn LED off:

digitalWrite(ledPin, LOW);




Maxuino code for driving a PIR on the Arduino UNO


Copyright Ken Rinaldo

Instructions on Modifying hardware to make a shotgun PIR sensor

You can change the area of sensing that the PIR can see by modifying the PIR with a thin tube or by painting portions of the Fresnel lens.

Modifying the PIR sensor

In this activity, you will turn the PIR sensor into a shotgun sensor. The PIR, with the Fresnel lens, allows you to mount this sensor on the ceiling and see in a full 360-degree area. However, what if you wanted to sense in only a 180-degree area? Well, one trick is to paint out portions of the Fresnel lens to create mini sweet spots where the sensor can see vs where the sensor cannot see. For example, in order to allow it to see only 180 degrees, you would paint out half of the sensor. I recommend white acrylic paint for this and make sure it is thick enough to block the infrared heat from your infrared sources. You can also change the sensor into a shotgun sensor by putting a piece of brass tubing 3/4 inch long over the heat sensor.

Parts necessary

One PIR sensor and Google to find best prices and one small brass tube (step tubing) The sensors above can be purchased from Amazon for at the time of this writing update. You can also secure them in larger numbers from Amazon who is now stocking many more electronic parts than in past.

  1. Carefully remove the Fresnel cap that is covering the sensor. You will notice a round can-shaped form with a rectangular window. Notice, as well, the capacitors on each side.


    Fresnel lens coming off the PIR sensor
    Model by Jessica Miller

    PIR sensor revealing heat sensor and two Capacitors. Model by Jessica Miller

    PIR sensor with a small tube of one-inch long cut to fit over the cover of the sensor.
    It must slip over the sensor can and be careful not to use glue here as it can creep
    onto the sensing window of the PIR sensor.

In order to see how the Fresnel sees light try this experiment:

  1. Now, take the Fresnel lens, put it over your eye, and turn your head while looking at a light source.
  2. Notice how the light jumps from one window to the next in the lens?
  3. When the lens is attached to the sensor, this is how it is imaging infrared heat onto the can-shaped pyroelectric sensor inside.
  4. Place the small tubing that came with your kit over top of the sensor.
  5. Now run the program entered above and notice how the sensor will only sense in a narrow beam where your tube sensor is pointed?
  6. Remember to give the sensor 25 - 40 seconds to warm up.