Skip to content

Interrupt Example


The Example2_Interrupts.ino example file can be accessed from the File > Examples > SparkFun STHS34PF80 Arduino Library > Example2_Interrupts drop-down menu. This example builds upon the previous code in Example1_BasicReadings.ino. Instead of constantly streaming the human presence detection values from the STHS34PF80 sensor, the microcontroller waits until an interrupt is triggered before data is retrieved through the I2C interface.

Code Verification

This code was last verified to be functional under the following parameters:

  IDE: Arduino 2.2.1
  Hardware Platform: SparkFun RedBoard Qwiic    
  SparkFun Human Presence and Motion Sensor - STHS34PF80 (Qwiic) Version: 1.0
  SparkFun Qwiic Mini Human Presence and Motion Sensor - STHS34PF80 Version: 1.0

  Read human presence detection value from the STHS34PF80 sensor, print them
  to terminal using the interrupt flag instead of the typical data ready flag. 
  Prints raw IR presence values (cm^-1).

  SparkFun STHS34PF80 Arduino Library
  Madison Chodikov @ SparkFun Electronics
  Original Creation Date: September 19th, 2023

  Development environment specifics:

  IDE: Arduino 2.2.1
  Hardware Platform: SparkFun RedBoard Qwiic    
  SparkFun Human Presence and Motion Sensor - STHS34PF80 (Qwiic) Version: 1.0
  SparkFun Qwiic Mini Human Presence and Motion Sensor - STHS34PF80 Version: 1.0

  Do you like this library? Help support SparkFun. Buy a board!

    SparkFun Human Presence and Motion Sensor - STHS34PF80 (Qwiic)

    SparkFun Qwiic Mini Human Presence and Motion Sensor - STHS34PF80

  Hardware Connections:
  Use a Qwiic cable to connect from the RedBoard Qwiic to the STHS34PF80 breakout (QWIIC).
  You can also choose to wire up the connections using the header pins like so:

  SDA (A4) --> SDA
  SCL (A5) --> SCL
  INT (2) --> INT
  3.3V --> 3.3V
  GND --> GND

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <>.

#include "SparkFun_STHS34PF80_Arduino_Library.h"
#include <Wire.h>

STHS34PF80_I2C mySensor;

// Values to fill with presence data
int16_t presenceVal = 0;

// Change the pin number to the pin that has been chosen for your setup
int intPin = 2;

// Star the flag as false
bool volatile interruptFlag = false;

// ISR to set the triggered interrupt
void isr1()
  interruptFlag = true;

void setup()
    Serial.println("STHS34PF80 Example 2: Interrupts");

    // Begin I2C
    if(Wire.begin() == 0)
      Serial.println("I2C Error - check I2C Address");

    // Establish communication with device 
    if(mySensor.begin() != 0)
      Serial.println("Error setting up device - please check wiring.");

    // Set INT pin to be triggered on rising and falling edges of INT pin
    pinMode(intPin, INPUT);
    // Attach interrupt to the pin as a digital pin that triggers on a change
    attachInterrupt(digitalPinToInterrupt(intPin), isr1, CHANGE);

    // Route all interrupts from device to interrupt pin

    // Enable the presence interrupt source 
    // (see page 17 of application note AN5867 for more information)

    // Set interrupt value to pulsed on the INT pin


void loop() 
  // If interrupt is triggered
  if(interruptFlag == true)
    interruptFlag = false;

    sths34pf80_tmos_func_status_t status;

    Serial.println("Data ready!");

    // If the flag is high, then read out the information
    if(status.pres_flag == 1)
      // Presence Units: cm^-1
      Serial.print("Presence: ");

Hardware Connections

For this example, users simply need to connect their Qwiic Human Presence/Motion Sensor board to their microcontroller, utilizing the I2C interface and interrupt pin. Users can easily connect the I2C interface with the Qwiic connection system on their boards. To connect the interrupt pin, we recommend utilizing an IC-hook for a temporary connection.

The sensor connected to a RedBoard Plus

The sensor connected to a RedBoard Plus

The Qwiic Human Presence/Motion Sensor boards are connected to a RedBoard Plus, with a Qwiic cable and an IC-hook.

Pin Connections

For users with a development board without a Qwiic connector, the table below illustrates the required pin connections. Make sure that the logic-level of the sensor is compatible with the development board that is being connected.

Sensor Pin Microcontroller Pin RedBoard/Uno
INT Interrupt Pin D2
SCL I2C - Serial Clock SCL/A5
SDA I2C - Serial Data SDA/A4
3V3 Power: 1.7 to 3.6V 3.3V
GND Ground GND

Serial Monitor

This example waits until an interrupt is triggered by one of the detection modes before the raw IR presence value (cm-1) is retrieved from the STHS34PF80 sensor. The data is then displayed in the Serial Monitor.

Data stream in the serial monitor

The human presence detection values being streamed from the STHS34PF80 sensor into the Serial Monitor.


For this example wave different objects in front of the sensor, with varying ranges in and out of the sensor's field of view. Objects that emit black body radiation work the best and should trigger the interrupt.