skip to Main Content

RPi Node-Red: PIR Motion Sensor

Authors: Adam, Ben

Goal:
Setup a PIR motion sensor and read its output in node-red

What you will learn:
What is a PIR motion sensor, how it's wired to a raspberry pi, and how to setup node-red to read its output.

Parts List:

What is a PIR?

A passive infrared motion sensor or PIR is able to detect movement by measuring the change of infrared radiation over time as an object moves in-front of its multi-faceted lens.  This PIR comes in a 3 pin package, if you remove the lens cap you can see that the pins are labeled “VCC”, “OUT”, and “GND”.  VCC means “voltage at the common collector” and normally refers to a power rail within a circuit, this sensor requires 5 volts. OUT is the pin we will read information from.  GND is the ground connection.

Video Tutorial:

Wiring up the sensor:

I encourage gently taking off the diffusion cap on the PIR to view the pins labels.  

  • GND -> GND
  • OUT -> PIN38 #20
  • VCC -> 5V

 

Setting up Node-Red

Start Node-Red and navigate to 127.0.0.1:1880.  Drag a Raspberry Pi input node and a Debug node into the flow area.

Double click on the Raspberry Pi input node to open its configuration menu.  Set the Pin to 38 GPIO20.  Name the node “PIR”.

The debug node can be left with it’s default settings, wire the button node to the debug node and deploy the flow.

If everything has been put together correctly, the state under the PIR node should change from a 0 to a 1 if movement has been detected and then back to 0 after a period of time, inspect the debug tab to view a log of these state transitions.  You may have noticed the two components under the PIR with a plus pattern on them. These are adjustable potentiometers, they control the sensitivity of the PIR and the duration of the activated state.

Whats Next?

Back To Top