This sample reads the value of the accelerometer on the 4-Sensors Leaf and displays it on a serial monitor.

Leaf to use

Use the following leaves.

Type Name Q’ty
AZ62 Connector Cover 1
AI01 4-Sensors 1
AZ01 USB 1
AP03 STM32 MCU 1
AV01 CR2032 1
CR2032 coin cell battery 1
M2*15mm screw 2


Let’s assemble leaves as shown in the figure below.


Source code

Write the following program1 in the Arduino IDE.

In order to make this sketch work, you need to install the libraries. If you haven’t installed it yet, refer to Environment to install it.

//  Accelerometer
//    (c) 2020 Trillion-Node Study Group
//    Released under the MIT license
//      Rev.00 2020/05/05  First release
#include <Adafruit_LIS3DH.h>

#define LIS3DH_ADDRESS 0x19

Adafruit_LIS3DH accel = Adafruit_LIS3DH();

void setup() {
  // initialize serial communication at 115200 second per second:
  // initialize i2c communication with LIS3DH:

  accel.setClick(0, 0);                      // Disable Interrupt
  accel.setRange(LIS3DH_RANGE_2_G);          // Full scale +/- 2G
  accel.setDataRate(LIS3DH_DATARATE_10_HZ);  // Data rate = 10Hz


void loop() {;

    Serial.print("X [g] = " + String(accel.x_g));
    Serial.print(", ");
    Serial.print("Y [g] = " + String(accel.y_g));
    Serial.print(", ");
    Serial.print("Z [g] = " + String(accel.z_g));



Execution Results

Open the serial monitor of the Arduino IDE and set the baud rate to 115200 bps and you will see the acceleration and tilt.

Back to previous page

  1. The program is the same as AVR MCU Leaf. ↩︎

Last modified 15.03.2021