A Node.js module for CL-USB232-PIR sensor. This module used node-serialport which is awesome module to help communicate with sensor with serial port.
yarn add node-usb232-pir
import PirSensor from 'node-usb232-pir';
const PORT_PATH = 'COM6'; // Sensor serial port path.
const sensor = new PirSensor(PORT_PATH, { autoRead: true });
sensor.on('open', () => console.log('\nPort Opened!\n'));
sensor.on('close', () => console.log('\nPort Closed!\n'));
sensor.on('data', val => console.log('Is target near from sensor? =>', val));
sensor.on('error', err => console.log('Error:', err));
Name | Type | Description |
---|---|---|
autoRead |
boolean | Automatically opens the port and read sensor data. Default is true . |
customSerialPortModule |
SerialPort |
Custom serial port module. Check out here. |
Name | data | Description |
---|---|---|
open |
- | Called when the sensor's port is opened and ready for writing. |
close |
- | Called when the sensor's port is closed. |
data |
1 or 0 |
Called when the sersor's status changed. If the data returns 1 , the target is near from sensor. And 0 , the target is far. |
error |
Error |
Called when the error occurred. |
yarn run test
This is MIT licensed and all it's dependencies are MIT or BSD licensed.