Nine Pomeranian Monsters


    0.2.0 • Public • Published

    PIR Motion Detector

    Node library for PIR sensor

    For Tessel 1, use version 0.1.0 of this package.

    I used this one from Adafruit.

    Adafruit has a lovely writeup on how PIRs work; I encourage you to read the details here. Here are some of the key pieces of information:

    • IR detects warm bodies.
    • There are two beams of IR sensitivity on the PIR.
    • If both beams detect the same amount of IR, the sensor records that no warm bodies are present.
    • When a warm body enters the field, the sensor records a positive charge differential.
    • When a warm body leaves the field, the sensor records a negative charge differential.



    The PIR I used has three pins. Here's how you connect it to Tessel:

    • +5V on the PIR goes to 5V. Here is a post on how to access 5V on Tessel 2.
    • GND goes to GND on the Tessel port you are using.
    • OUT, the signal pin, goes to any of Tessel's various digital pins. Note that the signal works on a maximum of 3.3V.

    I've left the PIR sensor in the retriggering position (H for the Adafruit one), so the signal pin will be pulled high as long as the sensor detects movement.


    npm install pir


    This basic PIR example emits events when
    a body is detected and when a body exits
    the field.
    const tessel = require('tessel');
    const pir = require('pir').use([2]);
    pir.on('ready', pir => {
      console.log('Ready and waiting...');
      pir.on('movement:start', time => {
        console.log(`Something moved! Time ${time}`);
      pir.on('movement:end', time => {
        console.log(`All is still. Time ${time}`);


    # [callback(data)] )
    Reads the value of the pin: 1 for movement; 0 for stillness. Returns the value or outputs to callback.


    # pir.on( 'ready', callback(err, pir) )
    Emitted when the pir object is first initialized

    # pir.on( 'movement', callback(time) )
    Emitted when movement is first detected.

    # pir.on( 'movement:start', callback(time) )
    Alias of movement.

    # pir.on( 'stillness', callback(time) )
    Emitted at the onset of stillness.

    # pir.on( 'movement:end', callback(time) )
    Alias of stillness.

    # pir.on( 'change', callback(time, value) )
    Emitted whenever the state changes. value is the value after the change.


    # pir.movement
    true while movement detected; false while no movement detected


    Copyright Kelsey Breseman, Apache 2.0 Licensed.


    npm i pir

    DownloadsWeekly Downloads






    Last publish


    • frijol