Menu
Microbots
0
  • Learn
    • Getting Started
    • Maker Builds
    • Education
  • Shop
    • ProtoBot
    • Modules & Parts
    • Tools & Gears
    • Coming Soon
  • About
    • Our Story
    • Reach Out
    • FAQs
  • Sign in
  • English
  • Your Cart is Empty
Microbots
  • Learn
    • Getting Started
    • Maker Builds
    • Education
  • Shop
    • ProtoBot
    • Modules & Parts
    • Tools & Gears
    • Coming Soon
  • About
    • Our Story
    • Reach Out
    • FAQs
  • Language

  • 0 0

CodeCell: Reading Acceleration & Shaking Detection

CodeCell Accelerometer

CodeCell includes a BNO085 3-axis accelerometer that measures movement and orientation in space. In this guide, you’ll learn how to read acceleration values and detect shaking — triggering the onboard LED whenever motion is detected.

How It Works

An accelerometer measures changes in speed and direction (acceleration) across three axes:

  • X-axis → Left and right
  • Y-axis → Forward and backward
  • Z-axis → Up and down (gravity)

Even when still, CodeCell feels gravity, the Z-axis will show about 9.81 m/s², Earth’s gravitational acceleration.

To start reading motion data, initialize and call:

myCodeCell.Init(MOTION_ACCELEROMETER);          // Enable accelerometer
myCodeCell.Motion_AccelerometerRead(x, y, z);   // Read acceleration values

Example 1 – Read Real-Time Motion

This example prints live acceleration data for each axis. Try moving or tilting CodeCell to see how values change.


#include <CodeCell.h>

CodeCell myCodeCell;
float x = 0.0, y = 0.0, z = 0.0;

void setup() {
  Serial.begin(115200);
  myCodeCell.Init(MOTION_ACCELEROMETER);  // Initialize accelerometer
}

void loop() {
  if (myCodeCell.Run(10)) {               // Run loop at 10 Hz
    myCodeCell.Motion_AccelerometerRead(x, y, z);

    Serial.print("X: "); Serial.print(x);
    Serial.print("  Y: "); Serial.print(y);
    Serial.print("  Z: "); Serial.println(z);
  }
}

Example 2 – Detect Shaking

This example calculates total acceleration and turns the LED red when CodeCell is shaken above a set threshold.


#include <CodeCell.h>
#include <math.h>  // For sqrt()

CodeCell myCodeCell;
float x = 0.0, y = 0.0, z = 0.0;

const float SHAKE_THRESHOLD = 15.0;  // Adjust for sensitivity

void setup() {
  Serial.begin(115200);
  myCodeCell.Init(MOTION_ACCELEROMETER);  // Enable accelerometer
}

void loop() {
  if (myCodeCell.Run(10)) {               // Run at 10 Hz
    myCodeCell.Motion_AccelerometerRead(x, y, z);

    // Calculate total acceleration magnitude
    float totalAcceleration = sqrt(x * x + y * y + z * z);
    Serial.print("Total Acceleration: ");
    Serial.println(totalAcceleration);

    if (totalAcceleration > SHAKE_THRESHOLD) {
      Serial.println("Shake detected!");
      myCodeCell.LED(255, 0, 0);          // Red LED for shake
      delay(500);
    }
  }
}

By combining all three axes into a single totalAcceleration value, you can easily detect shakes in any direction. If it exceeds 15.0 m/s², the onboard LED lights up red for 0.5 seconds.

Customization Tips

  • Change LED behavior: Use color or brightness to indicate motion strength.
  • Detect tilts or knocks: Use X/Y/Z thresholds to create gesture-based actions.
  • Track movement: Attach CodeCell to a wearable to measure motion patterns.

 

  • Share:

Follow

Github

  • About
  • Software
  • Education
  • Contact
  • FAQs
  • Terms
  • Refund Policy
  • Privacy Policy

Join our Community ~ Be the first to know about new products and get exciting deals!

© 2026 Microbots.

★ Reviews

Let customers speak for us

67 reviews
Write a review
85%
(57)
6%
(4)
1%
(1)
3%
(2)
4%
(3)
62
21
C
CodeCell C3
Cloke74

Great piece of kit, had just what i needed to complete the project i had in mind. Shame shipping to the UK is so expensive, but appreciate this isn’t necessarily in the hands of MicroBots

A
CodeCell C6
Anonymous

I had an issue, got a red light, I used too much flux. Support said clean it, then the one sensor worked fine. I got the help and answer same day I provided a foto.

A
CodeCell C6 Drive
Anonymous

I think this is the best of the ESP offered, most versatile.

User picture
P
CodeCell C6
Prudhvi tej Chinimilli

Been testing the Microbots CodeCell C6 and honestly impressed with how much functionality they packed into such a tiny module. Great form factor for rapid prototyping wearable/embedded sensing applications. ESP32-C6 + IMU integration makes development much easier compared to building everything from scratch.

Still exploring battery optimization and compact LiPo options for our use case, but overall the platform is promising for low-cost real-time sensing systems. Excited to keep building with it.

F
CodeCell C6
Francisco Estivallet

Amazing hardware, my go to for compact projects.

User picture
123