Qwiic PIR Hookup Guide
Qwiic PIR Arduino Library
We've written an Arduino library to make it easy to get started and interact with the Qwiic PIR. Before we jump into the examples for reading data from the sensor, we need to install the library and we'll take a closer look at the available functions in the library. The Arduino Library Manager is the easiest way to install the library. Open the Library Manager, search for "SparkFun Qwiic PIR Arduino Library" and click the "Install" button to download the latest version. If you prefer manually installing the library from the GitHub repository, you can download it here:
Library Functions
The list below outlines all of the functions available in the SparkFun Qwiic PIR Arduino Library along with quick descriptions of what they do. The examples cover nearly all the functions on this list so refer to them to get started or for demonstrations on how to integrate them into your own code.
Class
In the global scope, construct your sensor object (such as mySensor
or myPIR
) without arguments.
QwiicPIR mySensor;
Device Setup & Settings
bool begin(uint8_t address = DEFAULT_ADDRESS, TwoWire &wirePort = Wire);
- Initializes the Qwiic PIR on the I2C bus. Users can specify an alternate address if it has been changed as well as choose which I2C port used to communicate with the PIR.bool isConnected();
- Returns true if the PIR will acknowledge over I2C and false otherwise.uint8_t deviceID();
- Returns the 8-bit device ID.bool checkDeviceID();
- Returns true if the device ID matches the Qwiic PIR ID.uint8_t getDeviceType();
- Returns1
if a Qwiic PIR is attached to the bus and0
if no device is attached.uint16_t getFirmwareVersion();
- Returns the Qwiic PIR firmware version as a 16-bit integer. Major Revision Number = leftmost (high) byte. Minor Revision Number = rightmost (low) byte.bool setI2Caddress(uint8_t address);
- Configures the attached Qwiic PIR to initialize to the bus using the specified address.uint8_t getI2Caddress();
- Returns the I2C address of the attached Qwiic PIR.
PIR Status and Debounce Configuration
These functions are the primary ways to read whether or not an object is detected in the sensing area as well as how to customize the debounce time from the PIR to reduce noise and false detections and how to manipulate the detection queues.
bool rawPIRReading();
- Returns1
when PIR is outputting a signal,0
when not. This is the raw output from the PIR with no debouncing.bool objectDetected();
- Returns1
if a debounced object detection event occurs in the sensing area. The debounce timeobjectDetected();
waits for is set by thesetDebounceTime(uint16_t time);
.bool ojbectRemoved()
; - Returns1
if a debounced object removal event occurs in the sensing area. The debounce timeobjectRemoved();
waits for is set by thesetDebounceTime(uint16_t time);
.uint16_t getDebounceTime();
- Returns the debounce time set for the PIR reading to settle (in milliseconds).uint8_t setDebounceTime(uint16_t time);
Sets the time the Qwiic PIR waits for the raw reading from the sensor to settle. The default value for debounce time is 750ms.
Interrupt Status and Configuration
uint8_t enableInterrupt();
- When called, the interrupt pin is configured to trigger on all PIR events (detection & removal).uint8_t disableInterrupt();
- When called, the interrupt pin is no longer configured to trigger on PIR events.bool available();
- Returns theeventAvailable
bit.uint8_t clearEventBits();
- SetsobjectDetected
,objectRemoved
andeventAvailable
bits to zero.uint8_t resetInterruptConfig();
- Resets any configured interrupt functions to defaults (OFF).
Queue Manipulation
bool isDetectedQueueFull();
- Returns true if queue of object detections timestamps is full and false if not. This queue stores ten timestamp values.bool isDetectedQueueEmpty();
- Returns true if the queue of object detections timestamps is empty and false otherwise.unsigned long timeSinceLastDetect();
- Returns the time (in milliseconds) since theobjectDetected();
function last returned1
.unsigned long timeSinceFirstDetect();
- Returns the time (in milliseconds) for the oldest value stored in the Detected Queue.unsigned long popDetectedQueue();
- Returns the oldest value stored in the Detected Queue and removes it.bool isRemovedQueueFull();
- Returns true if the object removals queue is full and false if not. This queue stores ten timestamp values.bool isRemovedQueueEmpty();
- Returns true if the object removals queue is empty and false otherwise.unsigned long timeSinceLastRemove();
- Returns the time (in milliseconds) since theobjectRemoved();
function last returned1
.unsigned long timeSinceFirstRemove();
- Returns the time (in milliseconds) for the oldest value stored in the Removed Queue.unsigned long popRemovedQueue();
- Returns the oldest value stored in the Removed Queue and removes it.