In this node-red project, we make a simple “people counter” as you might find at store entrances, as well as an optional addition to take pictures or videos using a connected Raspberry Pi camera when someone moves through the door
For this project, you will need:
- Raspberry Pi w SD card, PiShield and power supply
- I-CubeX ReachClose sensor (mounted facing across a door)
- (Optional) Raspberry Pi Camera module and cable
If you have your own IR sensor, you can connect it to the PiShield using the sensor pinout here.
Hardware Setup
This project makes use of just a single IR (ReachClose) sensor. The key here is to mount it so it points across the door frame so that it can detect someone moving across it. Following shows a typical setup that should work:
For the optional camera component, you may have to position the Raspberry Pi close to where the camera needs to be mounted (as the camera cable is quite short), and use a extension cable for the IR sensor.
Node-red Flow
Below is the node-red flow. The full that you can copy+paste into node-red is here. The top left is the familiar sensor node that grabs analog data from the sensor (in this case connected to the last port on the PiShield). From there we do some basic thresholding inside the “switch” node, and then output either a 1 or 0 depending on the sensor level. The rbe node filters out repeated values and only emits changes, which then is used in the “increment counter” function. The UI text node in cyan show the counter value, and provides a button for resetting the counter.
Finally, at the bottom, there is the optional part that triggers raspistill
to take a picture. The function node at the bottom grabs the current time and uses it for the filename. We assume that the images will be placed in /home/pi/camera
, but feel free to change that to somewhere else if you like. The external utility (raspistill
) is triggered via an exec node, shown in red.
The simple dashboard looks like this:
Instead of raspistill
, you can also use raspivid
to take videos instead. With some adaptation, you could turn this into an interactive photo or video booth as well. For the movement events, it would also be possible to send remote triggers (e.g. IFTTT, MQTT, etc). You could also add additional sensors to detect other kinds of motion (e.g. TapTile floor sensors for detecting steps, or the MoveOn for presence in a room, etc).
IR Sensor Threshold Calibration
You can experiment with the correct threshold by outputting the sensor into a debug node (see basic node-red tutorial here) and seeing the output as someone walks across it. Then, in the switch node set the threshold to trigger accordingly. In the example below, when someone moves through the door the sensor value goes above 200, so we set that as the threshold: