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

  • 0 0

CodeCell: Reading the Gyroscope

CodeCell Gyroscope

CodeCell includes a built-in BNO085 3-axis gyroscope that measures angular velocity - how fast CodeCell is rotating around each axis. This lets you detect turning, spinning, or orientation changes.

How It Works

The gyroscope measures rotation speed in degrees per second (°/s) along three axes:

  • X-axis → Tilt forward/backward
  • Y-axis → Tilt left/right
  • Z-axis → Twist or spin

You can enable and read gyroscope data using two simple functions:

myCodeCell.Init(MOTION_GYRO);             // Enable gyroscope sensing
myCodeCell.Motion_GyroRead(x, y, z);      // Read angular velocity on all axes

Each reading gives the current rotation speed on the X, Y, and Z axes in °/s.

Example 1 – Read Gyroscope Data

This example prints live angular velocity readings to the Serial Monitor, showing how fast CodeCell is rotating around each axis.


#include <CodeCell.h>

CodeCell myCodeCell;

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

void setup() {
  Serial.begin(115200);
  myCodeCell.Init(MOTION_GYRO);  // Initialize gyroscope
}

void loop() {
  if (myCodeCell.Run(10)) {      // Run at 10 Hz
    myCodeCell.Motion_GyroRead(x, y, z);  // Read gyro data

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

What You’ll Notice:

  • When still, values are close to 0.
  • Tilting forward/backward changes X.
  • Tilting left/right changes Y.
  • Rotating like a steering wheel changes Z.

Example 2 – Detect Rotation and Change LED Color

This example changes CodeCell’s onboard LED color based on rotation direction, red when turning left, green when turning right.


#include <CodeCell.h>

CodeCell myCodeCell;

float x = 0.0, y = 0.0, z = 0.0;
const float ROTATION_THRESHOLD = 3.0;  // Rotation speed threshold (°/s)

void setup() {
  Serial.begin(115200);
  myCodeCell.Init(MOTION_GYRO);  // Enable gyroscope
}

void loop() {
  if (myCodeCell.Run(10)) {      // Run at 10 Hz
    myCodeCell.Motion_GyroRead(x, y, z);  // Read angular velocity

    Serial.print("Gyro Z: ");
    Serial.println(z);

    if (z > ROTATION_THRESHOLD) {          // Rotating right
      myCodeCell.LED(0, 255, 0);           // Green LED
    } 
    else if (z < -ROTATION_THRESHOLD) {    // Rotating left
      myCodeCell.LED(255, 0, 0);           // Red LED
    } 
    else {
      myCodeCell.LED(0, 0, 0);             // LED off
    }
  }
}

How It Works:

  • Z > 3 → Rotating right → LED turns green.
  • Z < -3 → Rotating left → LED turns red.

Adjust ROTATION_THRESHOLD to control sensitivity:

  • Higher → Detects only fast rotations.
  • Lower → Detects even small movements.

Customization Tips

  • Try different axes: Visualize pitch (X) or roll (Y) using other LED colors.
  • Detect flicks: Use short bursts of rotation for gesture input.
  • Combine with other sensors: Merge with accelerometer or magnetometer data for full motion tracking.
  • 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

53 reviews
Write a review
85%
(45)
4%
(2)
2%
(1)
4%
(2)
6%
(3)
21
49
G
CodeCell C6 Drive
Gerhard Weidenauer

Great board with many funktions in small space

User picture
L
MotorCell
Lennart Lange

Nice packaging, good follow up on the delivery, need to look up some online resources now for my first actual project wiht the cell

B
CodeCell C6 Drive
Brandon

Awesome product with great tutorials and example code

G
MotorCell
Gerald Kendrick

Very happy with my MotorCell. I'm incorporating it into a prototype project that will hopefully result in me needing a few more!

User picture
A
CodeCell C6 Drive
Anonymous

Great product! Having the IMU, motor driver, and battery management directly on the board is incredibly handy for quick prototyping. Love it!

Improvement ideas:
- using an ESP32 other than the C6 to get more cores. On a single-core chip, WiFi tasks often interfere with real-time applications.
- adding two more motor drivers (with a slightly higher current rating) would be awesome for drone projects!
- I know the compactness of the board is a huge selling point and really optimised, but exposing a few more pins would be great. With the motor drivers already occupying 4 pins, having only 4 GPIOs left can be tight for complex projects (though I’m nitpicking, I’m really pushing this board to its limits!).

123