8 releases

0.1.7 Apr 27, 2024
0.1.6 Apr 27, 2024

#573 in Embedded development

Download history 182/week @ 2024-04-03 3/week @ 2024-04-10 171/week @ 2024-04-17 266/week @ 2024-04-24 21/week @ 2024-05-01

461 downloads per month


988 lines


crates.io License Documentation

A Rust crate for ST Microelectronics STHS34PF80 presence and motion detection sensor


The STHS34PF80 sensor detects infrared presence, meaning a warm "body" stationary object. It also does ambient shock temperature detection (excessive heat change) and motion detection.

Many configurable settings for the detection thresholds, data output rates, interrupt pin, low pass filters, sensitivity.


  • updated to use embedded-hal version 1.0.x
  • designed for embedded use (ESP32-C3, -C6 and -S3 and STM32F3DISCOVERY)
  • configurable interrupt pin
  • data ready status based presence, motion and ambient shock measurement reads
  • low pass filter configuration if needed
  • hysteresis getters and setters
  • sensivity getters and setters
  • gain getters and setters
  • data output rate, average trim getters and setters
  • an easy to use Measurements struct
  • an easy to use initialize function
  • easy to use get_measurement_blocking and get_measurement_timeout (with timeout parameter)
  • no_std embedded compatible


This driver is loosly based on Sparkfun Arduino STHS34PF80 driver. A Sparkfun STHS34PF80 https://www.sparkfun.com/products/22494 sensor board was used for this driver development.

Unfortunately the github repository name is not spelled correctly but now stuck with it. The proper device and crate name is sths34pf80 while the mis-spelled repo name is stsh34pf80.

Recent version history

  • 0.1.7 fixed the example below, added Raspberry Pi example
  • 0.1.5 github repo name fixed in links
  • 0.1.4 Documentation improvements.
  • 0.1.0 Initial release.


Add the dependency to Cargo.toml.

version = "0.1"

Create a hardward specific I²C driver interface and delay function Create an Sths34pf80 struct from the I²C interface and a delay function. Configure interrupt pin properties if required.
Initialize Sths34pf80 (initialize() fn sets "standard" trims and ODR paramaters). Set presence, motion or ambient shock threshold only if required for more/less detection range Read the STHS34PF80 status and check if new data is ready, then get_func_status and match the returns FUNC_STATUS enum to see which of the three values changed, then get those values.

Simple Example

A more complete example is in the repository examples path

use sths34pf80::{Sths34pf80};


fn main() -> Result<()> {


  let peripherals = Peripherals::take().unwrap();
  let pins = peripherals.pins;
  let sda = pins.gpio0;
  let scl = pins.gpio1;
  let i2c = peripherals.i2c0;
  let config = I2cConfig::new().baudrate(100.kHz().into());
  let i2c_dev = I2cDriver::new(i2c, sda, scl, &config)?;

  let mut sths34pf80 = Sths34pf80::new(i2c_dev, Ets{});  // Ets is ESP32 IDF delay function


  loop {

    if let Ok(measurements) = sths34pf80.get_measurements_timeout(10) {
      match measurements.presence_value {
        Some(presence_value) => info!("presence detected, value is {}", presence_value),
        _ => (),
      match measurements.motion_value {
        Some(motion_value) => info!("motion detected, value is {}", motion_value),
        _ => (),
      match measurements.ambient_shock_value {
        Some(abmient_shock_value) => info!("ambient shock temp detected, value is {}", abmient_shock_value),
        _ => (),
    } else {
      info!("timeout with get_measurements_timeout call");




You are free to copy, modify, and distribute this application with attribution under the terms of either

at your option.

This project is not affiliated with nor endorsed in any way by STMicroelectronics or Sparkfun.


~15K SLoC