Skip to content

Introduction

The STHS34PF80 sensor, from ST Microelectronics, is designed to measure the precise black-body radiation (as described by Plank's law) of an object; as well as monitor ambient temperature conditions within its 80° field of view. The sensor is composed of a matrix of floating vacuum thermal transistors MOS split into two parts, one exposed to IR radiation and the other one shielded. The differential reading between the segments, allows the sensor to remove self-heating effects. The STHS34PF80 also incorporates algorithms to detect and discriminate between stationary and moving objects. These features enable the sensor to work as a human presence and motion sensor in different applications such as alarm systems, anti-intruder systems, smart lighting, and room occupancy.

The sensor can operate in multiple lighting conditions and is unaffected by visible light or other bands thanks to the 5 to 20µm optical band-pass filter. The STHS34PF80 has an output data rates between 0.25 to 30 Hz and an available single-shot, which are accessed through its I²C/SPI interface. The SparkFun Qwiic Human Presence and Motion Sensor boards are available in both the standard 1"x1" Qwiic form factor and the mini breakout board. (The mini form-factor is also panel mount compatible for use in enclosures. (1))

  1. Please refer to the hardware implementation guidelines for the STHS34PF80 sensor.

 Required Materials

To get started, users will need a few items. Now some users may already have a few of these items, feel free to modify your cart accordingly.

  1. If your computer doesn't have a USB-A slot, then choose an appropriate cable or adapter.
  2. Check out our other Qwiic cable options.
  3. The mini version of this product is panel mount compatible.
Headers and Wiring

To add headers or hookup wires, users will need soldering equipment and headers/wire.

New to soldering?

Check out our How to Solder: Through-Hole Soldering tutorial for a quick introduction!

Jumper Modification

To modify the jumpers, users will need soldering equipment and/or a hobby knife.

New to jumper pads?

Check out our Jumper Pads and PCB Traces Tutorial for a quick introduction!

 Suggested Reading

As a more sophisticated product, we will skip over the more fundamental tutorials (i.e. Ohm's Law and What is Electricity?). However, below are a few tutorials that may help users familiarize themselves with various aspects of the board.

Hardware Overview

Board Dimensions

The Qwiic Mini Human Presence and Motion Sensor breakout boards are laid out in the standardized 0.5"x 1" (1.77 x 2.54 cm) mini form-factor and the normal, 1" x 1" (2.54 x 2.54 cm) Qwiic breakout board. These boards also include standard 0.13" mounting holes, which are compatible with 4-40 screws. The dimensions of these boards are illustrated in the drawings below, where the listed measurements are in inches.

Board Dimensions of the standard board

Board Dimensions of the mini board

Dimensions (PDF) for the Qwiic Human Presence/Motion Sensor boards, in inches.

Need more measurements?

For more information about the board's dimensions, users can download the eagle files for the board. These files can be opened in Eagle and additional measurements can be made with the dimensions tool.

Eagle - Free Download!

Eagle is a CAD program for electronics that is free to use for hobbyists and students. However, it does require an account registration to utilize the software.

Download from
Autodesk primary logo

📏 Dimensions Tool

This video from Autodesk demonstrates how to utilize the dimensions tool in Eagle, to include additional measurements:

QR code to play video

Power

The STHS34PF80 requires a supply voltage between 1.7V to 3.6V. This power can be provided to the board, either, through one of the polarized Qwiic connectors or the dedicated 3.3V and GND PTH pins broken out on the board.

Power connections on the standard board

Power connections on the mini board

Qwiic Human Presence/Motion Sensor boards' power connections.

Info

The Qwiic connect system is meant to run on 3.3V. Ensure that another voltage is not being supplied, when utilized in conjunction with this system.

Info

For more details, users can reference the schematic and the STHS34PF80 datasheet.

Power Status LED

The red, PWR LED will light up once 1.4V is supplied to the board; however, for most users, it will light up when 3.3V is supplied through the Qwiic connector. A jumper is available to disconnect the power from the LED, for low-power applications (see Jumpers section below).

Power LED on the standard board

Power LED on the mini board

The PWR status LED on the Qwiic Human Presence/Motion Sensor boards.

Minimum Voltage

Users should keep in mind that the forward voltage of the red LED is lower than the minimum voltage required to power the STHS34PF80 sensor. Therefore, the LED could potentially be lit, when there isn't enough voltage to power the sensor.

  STHS34PF80

The Qwiic Human Presence/Motion Sensor board features the STHS34PF80 sensor from ST Microelectronics. Composed of a matrix of floating vacuum thermal transistors MOS, the sensor measures the ambient temperature and detects the black-body radiation of objects within its 80&deg field of view. The sensor's transistor array is split into two parts, one exposed to IR radiation and the other one shielded. The differential reading between the segments, allows the sensor to remove self-heating effects.

The sensor can operate in multiple lighting conditions and is unaffected by visible light or other bands thanks to the 5 to 20µm optical band-pass filter. The STHS34PF80 also incorporates algorithms to detect and discriminate between stationary and moving objects. These features enable the sensor to work as a human presence and motion sensor in different applications such as alarm systems, anti-intruder systems, smart lighting, and room occupancy. With an output data rates between 0.25 to 30 Hz and an available single-shot measurement from the STHS34PF80, all of which can be accessed through its I2C/SPI interface.

Features:

  • I2C Address (7-bit): 0x5A (1011010)
  • Operating Voltage: 1.7 to 3.6V
    • Current Draw: 10µA
  • Range: 4m (objects 70 x 25 cm² in size)
    • Field of View: 80°
  • Optical wavelength: 5 to 20µm
  • Built-in Detection Algorithms:
    • Identify stationary objects
    • Distinguish between stationary and moving objects
  • Output Data Rate: 0.25 to 30Hz
  • IR sensitivity: 2000 LSB/°C
  • RMS noise: 25 LSBrms
  • Operating Temperature: -40 to 85°C (1)
  • Sensor accuracy: ±0.6°C (local) (2)
  • Factory calibrated
  1. The operational temperature range of the sensor is
  2. The accuracy specifications only apply under settled isothermal conditions.

Current Consumption

The average current consumption by the STHS34PF80 is 10µA with 1.5µA in power-down mode.

STHS34PF80 sensor on the mini board

The STHS34PF80 sensor on the Qwiic Human Presence/Motion Sensor boards.

Operation Modes

The STHS34PF80 has three operation modes:

  • Power-down: After the boot is completed, the device is automatically configured in power-down mode.
  • One-shot: When configured in one-shot mode, the device can read environmental data at the very moment the controlling MCU requires it.
  • Continuous: When configured in continuous mode, the device keeps reading data at predefined frequencies (fixed output data rates, ODRs).

In both one-shot mode and continuous mode, the STHS34PF80 allows performing prior averaging (filtering) of the values of ambient temperature and object temperature to obtain smoother outputs.

Info

For more details, users can refer to Section 3 of the AN5867 - Operation Manual.

Smart Detection Algorithms

The STHS34PF80 has three detection modes that are provided by the built-in smart algorithms:

  • Presence detection
  • Motion detection
  • Ambient temperature shock detection

*These are not available when wide mode is configured.

Info

For more details, users can refer to Section 7 of the AN5867 - Operation Manual.

Breakout Pins

There are six PTH pins broken out on the Qwiic Human Presence/Motion Sensor boards. The pins are evenly spaced at 0.1" on the outer edge of the board; perfect for attaching headers. These pins provide access to the I2C and SPI interfaces of the STHS34PF80 sensor, including the interrupt pin.

Note

The I2C interface can also be accessed through the Qwiic connectors on the board.

I2C Pins

The I2C interface can also be accessed either through the breakout pins or the Qwiic connectors on the board. In most cases, the Qwiic connector will be the simplest method to connect the Qwiic Human Presence/Motion Sensor boards to a microcontroller. The I2C interface is enabled by default on the Qwiic Human Presence/Motion Sensor boards.

I2C pins on the standard board

I2C pins on the mini board

I2C pins on the Qwiic Human Presence/Motion Sensor boards.

Enabling the I2C Interface

The I2C interface is enabled by default on the Qwiic Human Presence/Motion Sensor boards. To disable the I2C interface and enable the SPI interface, users must ensure that the CS pin is initially pulled down (0).

Qwiic Connector

Qwiic connectors are provided for users to seamlessly integrate I2C devices with SparkFun's Qwiic Ecosystem.

Qwiic connector and I2C pins on the standard board

Qwiic connector and I2C pins on the mini board

Qwiic connector and I2C pins on the Qwiic Human Presence/Motion Sensor boards.

SPI Pins

The STHS34PF80 sensor operates in a 3-wire SPI configuration. In a 3-wire mode, the data signal lines are combined into a single bidirectional data line. The data transactions are half-duplex to allow for bidirectional communication.

Label Pin Function
SCL SPC Clock signal
SDA SDIO Serial data (In/Out)
CS CS Chip select:
1: I²C enabled
0: SPI enabled

SPI pins on the standard board

SPI pins on the mini board

SPI pins on the Qwiic Human Presence/Motion Sensor boards. Please refer to the table above for the associated pin connections, based on the boards' labels.

Enabling the SPI Interface

The I2C interface is enabled by default on the Qwiic Human Presence/Motion Sensor boards. To disable the I2C interface and enable the SPI interface, users must ensure that the CS pin is initially pulled down. (On boot-up, the CS must be in a LOW state to enable the SPI interface.)

Interrupt Pin

By default, the interrupt pin signals when data is available. However, the detection mode employed by the sensor can also trigger an interrupt.

Interrupt pin on the standard board

Interrupt pin on the mini board

Interrupt pin on the Qwiic Human Presence/Motion Sensor boards.

Qwiic Connectors

Qwiic connectors are provided for users to seamlessly integrate with SparkFun's Qwiic Ecosystem. Otherwise, users can access the I2C interface through the PTH pins broken out on the board.

Qwiic connector on the standard board

Qwiic connector on the mini board

Qwiic connectors on the Qwiic Human Presence/Motion Sensor boards.

What is Qwiic?

Qwiic Logo - light theme Qwiic Logo - dark theme


The Qwiic connect system is a solderless, polarized connection system that allows users to seamlessly daisy chain I2C boards together. Play the video, to learn more about the Qwiic connect system or click on the banner above to learn more about Qwiic products.

QR code to instructional video

Features of the Qwiic System

no soldering - light theme no soldering - dark theme

Qwiic cables (4-pin JST) plug easily from development boards to sensors, shields, accessory boards and more, making easy work of setting up a new prototype.

polarized connector - light theme polarized connector - dark theme

There's no need to worry about accidentally swapping the SDA and SCL wires on your breadboard. The Qwiic connector is polarized so you know you’ll have it wired correctly every time.

The part numbers for the PCB connector is SM04B-SRSS (Datasheet) and the mating connector on the cables is SHR04V-S-B; or an equivalent 1mm pitch, 4-pin JST connection.

daisy chainable - light theme daisy chainable - dark theme

It’s time to leverage the power of the I2C bus! Most Qwiic boards will have two or more connectors on them, allowing multiple devices to be connected.

Jumpers

Never modified a jumper before?

Check out our Jumper Pads and PCB Traces tutorial for a quick introduction!

There are four jumpers on the back of the board that can be used to easily modify the hardware connections of the board.

  • LED - This jumper can be used to disconnect power from the red, power LED for low-power applications.
  • I2C - This jumper can be used to remove the pull-up resistors on the I2C bus.
  • INT - This jumper can be used to remove the pull-up resistor from the INT pin.
  • CS - This jumper can be used to remove the pull-up resistor from the CS pin.
    • The state of the CS pin on boot-up, controls whether the I2C or SPI interface is enabled. (1)
  1. Info

    • 1: I²C enabled
    • 0: SPI enabled

Jumpers on the standard board

Jumpers on the back of the Qwiic Human Presence/Motion Sensor board.

Jumpers on the mini board

Jumpers on the Qwiic Mini Human Presence/Motion Sensor board.

Hardware Assembly

Qwiic Cable

The simplest method to connect a microcontroller to a Qwiic Human Presence/Motion Sensor board is through the Qwiic connector.

Connecting Qwiic cable

Connecting a Qwiic cable to the Qwiic Human Presence/Motion Sensor board.

Info

The Qwiic connection system is a standardized solderless, polarized connector interface that allows users to seamlessly daisy chain I2C boards together.

Remove Tape

Users with the mini version of the Qwiic Human Presence/Motion Sensor board should remove the tape covering the Qwiic connector.

Removing tape
Removing the tape from the Qwiic connector to the Qwiic Mini Human Presence/Motion Sensor board.

Note

The tweezers are not necessary, they were only used for illustration purposes. (Fingers would have obscured the camera shot.)

Info

The tape is used by the pick-and-place machine to place the connector on the board during assembly.

Breakout Pins

The PTH pins on the Qwiic Human Presence/Motion Sensor board are broken out into 0.1"-spaced pins on the outer edge of the board.

New to soldering?

If you have never soldered before or need a quick refresher, check out our How to Solder: Through-Hole Soldering guide.

Hookup Wires

For a more permanent connection, users can solder wires directly to the board.

Soldering wires

Soldering wires to the Qwiic Mini Human Presence/Motion Sensor board.

Headers

When selecting headers, be sure you are aware of the functionality or physical arrangement required.

Soldering headers

Soldering headers to the Qwiic Human Presence/Motion Sensor board.

Software Overview

Arduino IDE

Tip

For first-time users, who have never programmed before and are looking to use the Arduino IDE, we recommend beginning with the SparkFun Inventor's Kit (SIK), which is designed to help users get started programming with the Arduino IDE.

Most users may already be familiar with the Arduino IDE and its use. However, for those of you who have never heard the name Arduino before, feel free to check out the Arduino website. To get started with using the Arduino IDE, check out our tutorials below:

Need help setting up the RedBoard Plus?

RedBoard Plus

The following instructions should help users get started with the RedBoard Plus. For more information about the board, please check out our hookup guide below:

RedBoard Plus Hookup Guide
RedBoard Plus Hookup Guide

CH340 Driver

Users will need to install the appropriate driver for their computer to recognize the serial-to-UART chip on their board/adapter. Most of the latest operating systems will recognize the CH340C chip on the board and automatically install the required driver.

To manually install the CH340 driver on their computer, users can download it from the WCH website. For more information, check out our How to Install CH340 Drivers Tutorial.

How to Install CH340 Drivers
How to Install CH340 Drivers

Selecting a Board

When selecting a board to program in the Arduino IDE, users should select the Arduino Uno from the Tools drop-down menu (_i.e. Tools > Board > Arduino AVR Boards > Arduino Uno).

Select the Arduino Uno from the Tools drop-down menu in the Arduino IDE.

Arduino IDE 2.x.x - Alternative Method

In the newest version of the Arduino IDE 2.x.x, users can also select their board (green) and port (blue) from the Select Board & Port dropdown menu (yellow).

Selecting the Arduino Uno and COM5 port from the Select Board & Port drop-down menu in the Arduino IDE (v2.0.3).

SparkFun STHS34PF80 Arduino Library

The SparkFun STHS34PF80 Arduino library can be installed from the library manager in the Arduino IDE by searching for:

SparkFun STHS34PF80 Arduino library

SparkFun STHS34PF80 Arduino library in the library manager of the Arduino IDE.

Manually Downloading the Arduino Library

For users who would like to manually download and install the library, the *.zip file can be accessed from the GitHub repository or downloaded by clicking the button below.

Download the Arduino Library

Example - Basic

Once the Arduino library has been installed, the Example1_BasicReadings.ino example file can be accessed from the File > Examples > SparkFun STHS34PF80 Arduino Library > Example1_BasicReadings drop-down menu. This example reads the human presence detection values from the STHS34PF80 sensor through the I2C interface and displays them in the Serial Monitor.

Example1_BasicReadings.ino
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
/******************************************************************************
  Example1_BasicReadings.ino

  Read human presence detection values from the STHS34PF80 sensor, print them
  to terminal. Prints raw IR presence (cm^-1), if motion was detected, and 
  temperature in degrees C.

  SparkFun STHS34PF80 Arduino Library
  Madison Chodikov @ SparkFun Electronics
  Original Creation Date: September 19th, 2023
  https://github.com/sparkfun/SparkFun_STHS34PF80_Arduino_Library

  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)
    https://www.sparkfun.com/products/22494

    SparkFun Qwiic Mini Human Presence and Motion Sensor - STHS34PF80
    https://www.sparkfun.com/products/23253

  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:

  ARDUINO --> STHS34PF80
  SDA (A4) --> SDA
  SCL (A5) --> SCL
  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
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  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 <http://www.gnu.org/licenses/>.
******************************************************************************/

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

STHS34PF80_I2C mySensor;

// Values to fill with presence and motion data
int16_t presenceVal = 0;
int16_t motionVal = 0;
float temperatureVal = 0;


void setup()
{
    Serial.begin(115200);
    Serial.println("STHS34PF80 Example 1: Basic Readings");

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

    // Establish communication with device 
    if(mySensor.begin() == false)
    {
      Serial.println("Error setting up device - please check wiring.");
      while(1);
    }

    delay(1000);
}

void loop()
{
  sths34pf80_tmos_drdy_status_t dataReady;
  mySensor.getDataReady(&dataReady);

  // Check whether sensor has new data - run through loop if data is ready
  if(dataReady.drdy == 1)
  {
    sths34pf80_tmos_func_status_t status;
    mySensor.getStatus(&status);

    // If presence flag is high, then print data
    if(status.pres_flag == 1)
    {
      // Presence Units: cm^-1
      mySensor.getPresenceValue(&presenceVal);
      Serial.print("Presence: ");
      Serial.print(presenceVal);
      Serial.println(" cm^-1");
    }

    if(status.mot_flag == 1)
    {
      Serial.println("Motion Detected!");
    }

    if(status.tamb_shock_flag == 1)
    {
      mySensor.getTemperatureData(&temperatureVal);
      Serial.print("Temperature: ");
      Serial.print(temperatureVal);
      Serial.println(" °C");
    }
  }

}

Hardware Connections

For this example, users simply need to connect their Qwiic Human Presence/Motion Sensor board to their microcontroller, utilizing the I2C interface. With the recommended hardware, users can easily connect their boards with the Qwiic connection system.

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.

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
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 reads the human presence detection values from the STHS34PF80 sensor and displays them in the Serial Monitor. It prints the raw IR presence (cm-1), if the motion detection flag was triggered, and temperature (°C).

Data stream in the serial monitor

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

Tip

For this example wave different objects in front of the sensor, with varying ranges. Objects that emit black body radiation work the best and should trigger the motion detected flag.

Example - Interrupt

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.

Example2_Interrupts.ino
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
/******************************************************************************
  Example2_Interrupts.ino

  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
  https://github.com/sparkfun/SparkFun_STHS34PF80_Arduino_Library

  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)
    https://www.sparkfun.com/products/22494

    SparkFun Qwiic Mini Human Presence and Motion Sensor - STHS34PF80
    https://www.sparkfun.com/products/23253

  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:

  ARDUINO --> STHS34PF80
  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
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  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 <http://www.gnu.org/licenses/>.
******************************************************************************/

#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.begin(115200);
    Serial.println("STHS34PF80 Example 2: Interrupts");

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

    // Establish communication with device 
    if(mySensor.begin() == false)
    {
      Serial.println("Error setting up device - please check wiring.");
      while(1);
    }

    // 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
    mySensor.setTmosRouteInterrupt(STHS34PF80_TMOS_INT_OR);

    // Enable the presence interrupt source 
    // (see page 17 of application note AN5867 for more information)
    mySensor.setTmosInterruptOR(STHS34PF80_TMOS_INT_PRESENCE);

    // Set interrupt value to pulsed on the INT pin
    mySensor.setInterruptPulsed(0);

    delay(500);
}

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

    sths34pf80_tmos_func_status_t status;
    mySensor.getStatus(&status);

    Serial.println("Data ready!");


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

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.

Tip

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.

Example - SPI

This example doesn't currently operate properly; we are actively looking into the issue. To track our progress, please refer to this [GitHub issue](https://github.com/sparkfun/SparkFun_STHS34PF80_Arduino_Library/issues/7).

Description

The Example4_SPIFunctionality.ino example file can be accessed from the File > Examples > SparkFun STHS34PF80 Arduino Library > Example4_SPIFunctionality drop-down menu. This example operates similarly to the code in Example1_BasicReadings.ino. Instead of retrieving data through the I2C interface, the serial peripheral interface (SPI) is used to access the human presence detection values from the STHS34PF80 sensor.

Example4_SPIFunctionality.ino
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
/******************************************************************************
  Example4_SPIFunctionality.ino

  Read human presence detection values from the STHS34PF80 sensor, print them
  to terminal using SPI communication instead of I2C. 
  Prints raw IR presence (cm^-1), if motion was detected, and temperature 
  in degrees C.

  SparkFun STHS34PF80 Arduino Library
  Madison Chodikov @ SparkFun Electronics
  Original Creation Date: September 19th, 2023
  https://github.com/sparkfun/SparkFun_STHS34PF80_Arduino_Library

  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)
    https://www.sparkfun.com/products/22494

    SparkFun Qwiic Mini Human Presence and Motion Sensor - STHS34PF80
    https://www.sparkfun.com/products/23253

  Hardware Connections:
  Wire the SPI Connections from the RedBoard Qwiic to the STHS34PF80 Breakout 
  with a resistive divider using the header pins like so: 

  ARDUINO --> STHS34PF80
  SCK/SCL (13) --> Clock
  SDI/SDA (12) --> Data in
  !CS (10) --> Chip Select
  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
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  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 <http://www.gnu.org/licenses/>.
******************************************************************************/

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

STHS34PF80_SPI mySensor; 

// Presence and Motion variables to fill
int16_t presenceVal = 0;
float temperatureVal = 0;

// Set your chip select pin according to your setup
uint8_t chipSelect = 10;

void setup()
{
    Serial.begin(115200);
    Serial.println("STHS34PF80 Example 4: SPI Functionality");

    // Configure the chip select pin
    pinMode(chipSelect, OUTPUT);
      digitalWrite(chipSelect, HIGH);

    // Begin SPI
    SPI.begin();

    // Establish communication with device 
    if(mySensor.begin(chipSelect) == false)
    {
      Serial.println("Error setting up device - please check wiring.");
      while(1);
    }

    delay(500);
}

void loop() 
{
  sths34pf80_tmos_drdy_status_t dataReady;
  mySensor.getDataReady(&dataReady);
  Serial.println(dataReady.drdy);

  // Check whether sensor has new data - run through loop if data is ready
  if(dataReady.drdy == 1)
  {
    sths34pf80_tmos_func_status_t status;
    mySensor.getStatus(&status);

    // If presence flag is high, then print data
    if(status.pres_flag == 1)
    {
      // Presence Units: cm^-1
      mySensor.getPresenceValue(&presenceVal);
      Serial.print("Presence: ");
      Serial.print(presenceVal);
      Serial.println(" cm^-1");
    }

    if(status.mot_flag == 1)
    {
      Serial.println("Motion Detected!");
    }

    if(status.tamb_shock_flag == 1)
    {
      mySensor.getTemperatureData(&temperatureVal);
      Serial.print("Temperature: ");
      Serial.print(temperatureVal);
      Serial.println(" °C");
    }
  }
}

Hardware Connections

For this example, users will need to modify the CS jumper to enable the SPI communication. In the setups illustrated below, right-angle headers were soldered to the boards and connected with M/F jumper wires to the microcontroller. However, users should select a connection method that suits their needs.

The sensor connected to a RedBoard Plus

The sensor connected to a RedBoard Plus

The Qwiic Human Presence/Motion Sensor boards with headers soldered to them and connected to a RedBoard Plus with jumper wires.

Pin Connections

Below are the pin connections for SPI communication with the sensor. Users should be aware of the logic-levels of their microcontroller; with the RedBoard Plus, users only need to flip a switch to configure all the board's pins to 3.3V-logic.

Sensor Pin Microcontroller Pin RedBoard Plus
CS SPI - Chip Select Pin 10
SCL SPI - Serial Peripheral Clock 13
SDA SPI - Serial Data In/Out 12
3V3 Power: 1.7 to 3.6V 3.3V
GND Ground GND

Switch on the RedBoard Plus

The logic-level switch on the RedBoard Plus.

Note

Users will need to initially pull the CS pin low, to enable the SPI communication on the Qwiic Human Presence/Motion Sensor boards.

Troubleshooting Tips

Need Help?

If you need technical assistance or more information on a product that is not working as you expected, we recommend heading on over to the SparkFun Technical Assistance page for some initial troubleshooting.

SparkFun Technical Assistance Page

If you can't find what you need there, the SparkFun Forums is a great place to search product forums and ask questions.

Account Registration Required

If this is your first visit to our forum, you'll need to create a Forum Account to post questions.

Resources

Product Resources

Additional Resources

🏭 Manufacturer's Resources

ST Microelectronics also provides additional resources for the STHS34PF805:

QR code to the hookup guide