Menu
Microbots
0
  • Learn
  • Shop
    • Maker-Modules
    • Maker-Packs
    • Tools & Gears
    • Robots & Displays
    • All Products
  • Community
    • Education
    • Software
  • About
    • Our Story
    • Reach Out
    • FAQs
  • English
  • Your Cart is Empty
Microbots
  • Learn
  • Shop
    • Maker-Modules
    • Maker-Packs
    • Tools & Gears
    • Robots & Displays
    • All Products
  • Community
    • Education
    • Software
  • About
    • Our Story
    • Reach Out
    • FAQs
  • Language

  • 0 0

CodeCell: Sensing Tap Detection

In this guide, we'll explore how to use the CodeCell's onboard motion sensor to detect taps. This project demonstrates how to use tap detection for interactive controls, making it perfect for creating responsive actions with a simple tap on the device.

How is a tap detected?

CodeCell is is equipped with a  BNO085 motion sensor that fuses the data from an accelerometer, gyroscope and magnetometer, to track specific movement patterns and determine if a tap was made, making it ideal for interactive controls like toggling lights, triggering sound effects, or other actions based on a simple tap gesture.

Example 1: Basic Tap Detection 

In the first example, we setup our CodeCell to continuously check for a tap. When a tap is detected, the onboard LED lights up in yellow for one second. You can expand on this basic functionality to create more complex interactions, such as controlling multiple LEDs, motors, or other connected devices based on tap inputs.

Make sure your CodeCell is properly connected via USB-C, and follow the comments in the code to understand each step.


#include <CodeCell.h>

CodeCell myCodeCell;

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_TAP_DETECTOR); // Initializes tap detection sensing
}

void loop() {
    if (myCodeCell.Run(10)) {
        // Runs every 100ms to check for taps
        if (myCodeCell.Motion_TapRead()) {
            // If a tap is detected, shine the LED yellow for 1 second
            myCodeCell.LED(0xA0, 0x60, 0x00); // Set LED to yellow
            delay(1000); // Keep the LED on for 1 second
        }
    }
}

Example 2: Tap Detection + CoilCell

In this next example, we use a CoilCell to flip its polarity, and actuate a flip-dot. This expands the interactivity by using tap detection to control external devices, creating a more dynamic response.


#include <CoilCell.h>
#include <CodeCell.h>

#define IN1_pin1 5
#define IN1_pin2 6

CoilCell myCoilCell(IN1_pin1, IN1_pin2);
CodeCell myCodeCell;

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_TAP_DETECTOR); // Initializes tap detection sensing.
    myCoilCell.Init(); // Initializes the CoilCell.
    myCoilCell.Tone(); // Plays a tone to confirm initialization.
}

void loop() {
    if (myCodeCell.Run(10)) {
        // Runs every 100ms to check for taps.
        if (myCodeCell.Motion_TapRead()) {
            // If a tap is detected, shine the LED yellow and flip the CoilCell's polarity.
            myCodeCell.LED(0xA0, 0x60, 0x00); // Set LED to yellow.
            myCoilCell.Toggle(100); // Toggle the CoilCell's polarity.
            delay(1000); // Delay to keep the LED on and polarity flipped for 1 second.
        }
    }
}

Tips for Customization

  • Change LED Colors: Experiment with different LED colors and use the taps to increase the LED's brightness.
  • Expand Actions: Use tap detection to trigger other devices, like buzzers, motors, or displays, to add more layers of interactivity.
  • Combine with Other Sensors: Integrate tap detection with other sensors, like proximity or light, to create multi-sensor responsive projects.

Conclusion

Experiment with the code, customize the responses, and check out the CodeCell GitHub Repository for more code examples and technical documentation!

  • Share:


Also in CodeCell

Linking Your CodeCell to the MicroLink App
Linking Your CodeCell to the MicroLink App

Read More

Debugging CodeCell
Debugging CodeCell

Read More

CodeCell: Connecting with BLE
CodeCell: Connecting with BLE

Read More

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!

© 2025 Microbots.