Menu
Microbots
0
  • Learn
    • Getting Started
    • Maker Builds
    • Education
  • Shop
    • ProtoBot
    • Wavelit Display
    • 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
    • Wavelit Display
    • Modules & Parts
    • Tools & Gears
    • Coming Soon
  • About
    • Our Story
    • Reach Out
    • FAQs
  • Language

  • 0 0

CodeCell: Motion State

CodeCell can also detect whether the device is on a table, stationary, or in motion, using its Motion State sensing feature.

Understanding Motion State Detection

The CodeCell's BNO085 sensor provides a built-in algorithm called Motion State, which classifies the device’s movement into simple, easy-to-use states.

Enable Motion State with:

myCodeCell.Init(MOTION_STATE);    // Enable motion state sensing

Read the current state using:

int state = myCodeCell.Motion_StateRead();

Motion State Reference

ID State Description
0 MOTION_STATE_UNKNOWN Not yet classified — sensor is still initializing or calibrating.
1 MOTION_STATE_ONTABLE Device is resting on a solid surface (like a desk or table).
2 MOTION_STATE_STATIONARY Not moving at all — completely still.
3 MOTION_STATE_STABLE Movement has recently stopped; sensor is stabilizing.
4 MOTION_STATE_MOTION Device is actively moving.

Tip:
The difference between Stationary and Stable:

  • Stable = recently stopped but still settling
  • Stationary = fully still for a moment

Example – Serial Motion State Monitor

This example prints the current Motion State every 100 ms.

/*
  Example: Motion State Monitor Demo
  Boards: CodeCell C3 / CodeCell C3 Light / CodeCell C6 / CodeCell C6 Drive

  Overview:
  - Demonstrates the CodeCell's Motion State sensing.
  - Continuously reports whether the device is On-Table, In Motion, Stabilizing, or Stationary.  
*/

#include <CodeCell.h>

CodeCell myCodeCell;

void setup() {
  Serial.begin(115200);           // Start USB serial at 115200 baud
  myCodeCell.Init(MOTION_STATE);  // Enable Motion State sensing
}

void loop() {
  if (myCodeCell.Run(10)) {  // Run at 10 Hz
    Serial.print("State: ");
    switch (myCodeCell.Motion_StateRead()) {
      case MOTION_STATE_STABLE:
        Serial.println("Motion Stopped - Stabilizing");
        break;
      case MOTION_STATE_ONTABLE:
        Serial.println("On Table");
        break;
      case MOTION_STATE_STATIONARY:
        Serial.println("Stationary");
        break;
      case MOTION_STATE_MOTION:
        Serial.println("In Motion");
        break;
      default:
        Serial.println("Unknown");
        break;
    }
  }
}

When to Use Motion State

  • Notify devices when picked up: Detect when a project moves.
  • Trigger actions on motion stop: Start logging or measuring once movement stabilizes.
  • Sleep mode optimization: Enter deep sleep when stationary for better battery life.

Notes

  • Motion State may take a few seconds to stabilize after powering on.
  • Mounting orientation affects sensitivity - fixed, rigid mounting gives the best results.
  • 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

83 reviews
Write a review
87%
(72)
5%
(4)
2%
(2)
2%
(2)
4%
(3)
77
21
G
Experiment in Progress Mug
Gerald Kendrick

I am enjoying my Experiment in Progress coffee mug. It fits in well in the lab.

K
12-in-1 Screwdriver (Pen-Size)
Klaas

Very useful fun little screwdriver for the all tiny stuff

f
ProtoBot
frederic marty

I don't have much time right now to test the micro bot, but it looks good.

f
MotorCell
frederic marty

I don't have much time right now to test it but it looks good.

M
ProtoBot
Mehmed Muslija

ProtoBot has met all my expectations.
Watching one of the videos on YouTube, I thought it would be interesting and educational to make a small project for my 8 year old cousin. ProtoBot has provided a wide range of experiences and encouraged my cousin to take on new projects.

User picture
123