In this guide, we'll explore how to use the CodeCell's onboard motion sensor to measure step counts and display these counts on an OLED display, making it easy to turn CodeCell into your own Pedometer or even fitness tracker!
CodeCell is equipped with a BNO085 motion sensor that uses fused the data from an accelerometer, gyroscope and magnetometer, to track specific movement patterns and determine if a step was made. Each step is then added to a counter, and the CodeCell library help you easily reads these step counts.
In this example, the CodeCell continuously monitors for steps and updates the count. This count is then displayed on an OLED screen using the Adafruit SSD1306 library.
Below is the example code to get you started. Ensure your CodeCell is properly connected via USB-C and your OLED display is correctly wired to the CodeCell's lower side. There you can use its ground, 3V3 and I2C pins (SDA and SCL).
Follow the comments in the code to understand each step.
#include <CodeCell.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
CodeCell myCodeCell;
/* Configure the OLED Display */
#define SCREEN_WIDTH 64 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C // Address of the OLED display
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
uint16_t step_counter = 0;
void setup() {
Serial.begin(115200); // Set Serial baud rate to 115200. Ensure Tools/USB_CDC_On_Boot is enabled if using Serial.
myCodeCell.Init(MOTION_STEP_COUNTER); // Initializes step counting and activity sensing.
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println("Display Error");
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.display();
delay(2000);
}
void loop() {
if (myCodeCell.Run(10)) { //Run every 10Hz
step_counter = myCodeCell.Motion_StepCounterRead(); //Read step counter
display.clearDisplay();
display.setCursor(32, 16); // Start at top-left corner
display.print(F("Steps: "));
display.print(step_counter);
display.display(); //Update Display
}
}
This project demonstrates how to use the CodeCell’s motion sensor as a pedometer and display the step counts on an OLED screen. Experiment with the code, to create your own wearable fitness device and check out the CodeCell GitHub Repository for more code examples and technical documentation!
Join our Community ~ Be the first to know about new products and get exciting deals!
© 2025 Microbots.