Home » Connect a KX134 Triple Axis Accelerometer to an ESP32 example

Connect a KX134 Triple Axis Accelerometer to an ESP32 example

by shedboy71

In this article we look at another Triple-axis Magnetometer, the KX134 Triple Axis Accelerometer, and connect it to an ESP32 board

This is very similar to the KX132 we wrote about previously in an article

Sensor Information

This KX134 is a digital accelerometer from Kionix. We will use the KX134 breakout from Sparkfun

The KX134 is a low-power, 16-bit resolution three-axis accelerometer capable of measuring ±8g/16g/32g/64g (user-selectable) and has up to a 10kHz output data rate making it ideal for high-g measurements as well as high-speed applications such as vibration sensing

The KX134 includes a host of features including Freefall detection, Directional Tap™ and Double-Tap™ detection, tilt orientation detection and more. The Qwiic KX134 can interface with controllers using both I2C and SPI at high speeds so you can use it in an existing Qwiic chain or on an SPI bus.

This is what the breakout looks like


  • Measurement Range: ±8g, ±16g, ±32g, ±64g (User Selectable)
  • High Resolution (8 or 16-bit)
  • User-Configurable Output Data Rate (ODR) up to 25600Hz
  • User-Configurable 3-stage Advanced Data Path featuring low-pass filter, low-pass/high-pass filter and RMS calculation engine
  • Wide range of built-in sensing functions
    • Free Fall
    • Directional-Tap / Double-Tap
    • Device Orientation & Activity Algorithms
  • Low Noise: 130µg/√Hz (varies based on ODR, power mode & other settings)
  • High-Resolution Wake-Up & Back-to-Sleep Detection with a configurable threshold as low as 3.9mg
  • 512-byte FIFO buffer that continues recording data while being read
  • Selectable Low-Power or High-Performance operating modes
  • Low Power with Integrated Voltage Regulator
    • High-Performance Operating Current Consumption (400Hz ODR + Wake-Up Detection): 148µA
    • Low Power Operating Current Consumption (0.781Hz ODR + Wake-Up Detection): 0.53µA
    • Standby Current Consumption: 0.5µA
  • Self-Test Functionality
  • Digital I2C up to 3.4MHz and Digital SPI up to 10MHz
  • 2x Qwiic Connectors
  • SPI available on PTH Header Pins
  • I2C Address: 0x1E (0x1F can be used as an alternate but requires soldering abridge across 2 pads on the underside of the board)

Parts Required

You can connect to the sensor using DuPont style jumper wire.


Name Link
Connecting cables



I used 3.3v from the ESP32

I also used a Qwiic cable, but if you do not have one, there is an unpopulated set of pins you can solder a header to. This is how you would wire this up


Code Example

I installed the Sparkfun library using the Arduino ide

Click the Manage Libraries … menu item, search for KX134, and select the Sparkfun KX13x library like this

This is one of the examples that gets installed with the library, with a  few comments and unused lines removed.

#include <Wire.h>
#include <SparkFun_KX13X.h>

SparkFun_KX134 kxAccel;

outputData myData; // Struct for the accelerometer's data

void setup()


  // Wait for the Serial monitor to be opened.
  while (!Serial)

  if (!kxAccel.begin())
    Serial.println("Could not communicate with the the KX13X");
    while (1)

  if (kxAccel.softwareReset())

  // Give some time for the accelerometer to reset.
  // It needs two, but give it five for good measure.

  // Many settings for KX13X can only be
  // applied when the accelerometer is powered down.
  // However there are many that can be changed "on-the-fly"
  // check datasheet for more info, or the comments in the
  // "...regs.h" file which specify which can be changed when.

  kxAccel.setRange(SFE_KX134_RANGE16G);         // 16g for the KX134

  kxAccel.enableDataEngine(); // Enables the bit that indicates data is ready.
  // kxAccel.setOutputDataRate(); // Default is 50Hz

void loop()
  // Check if data is ready.
  if (kxAccel.dataReady())
    Serial.print("X: ");
    Serial.print(myData.xData, 4);
    Serial.print(" Y: ");
    Serial.print(myData.yData, 4);
    Serial.print(" Z: ");
    Serial.print(myData.zData, 4);
  delay(500); // Delay should be 1/ODR (Output Data Rate), default is 1/50ODR



When run and the sensor was moved around

X: 0.3035 Y: -0.0088 Z: -0.9189
X: -0.0044 Y: 0.6022 Z: -1.2317
X: -1.3576 Y: -0.2172 Z: -0.2381
X: -0.0693 Y: -0.0176 Z: 0.6759



You may also like

Leave a Comment

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.