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

  • 0 0

CodeCell

CodeCell: Sensing Tap Detection

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!

Read More

CodeCell: Proximity Sensing

CodeCell: Proximity Sensing

In this guide, we'll explore how to use the CodeCell's onboard proximity sensor to detect objects. and also depth gestures.

How does it sense Proximity?

In its tiny package CodeCell packs a VCNL4040 that uses infrared light to detect objects within its range. It measures the reflection of emitted IR light to approximate how close an object is, allowing you to create responsive behaviors based on proximity. This feature is particularly useful for creating interactive lighting, robotics, touchless switches, or other proximity-based actions.

The onboard sensor can measure proximity up to 20 cm away, and uses I2C communication which is automatically handled by our CodeCell library. 

Example 1 - Proximity threshold

In this example, the CodeCell continuously monitors proximity data and turns on a red LED when an object is detected within its proximity threshold.

Ensure 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(LIGHT); // Initializes light sensing, including proximity
}

void loop() {
    if (myCodeCell.Run(10)) {
        // Runs every 100ms to check proximity
        uint16_t proximity = myCodeCell.Light_ProximityRead();
        
        // Check if an object is within range
        if (proximity > 100) {
            myCodeCell.LED(0xFF, 0, 0); // Set LED to Red when proximity is detected
            delay(1000); // Keep the LED on for 1 second
        } else {
            // No action if the object is out of range
        }
    }
}

Tips for Customization

  • Adjust Proximity Threshold: Modify the threshold value (100 in the example) to adjust the sensitivity of proximity detection based on your application.
  • Change LED Colors: Experiment with different LED colors using the myCodeCell.LED() function to create multi-colored responses to proximity.
  • Add More: Consider adding a buzzer or  motor to provide audio or motion feedback when objects are detected within range.
  • Use Proximity with Light Sensing: Combine proximity and light sensing to create more complex behaviors, such as adjusting lights based on both distance and ambient light levels.

Example 2 - Depth gestures

By moving your hand or other objects closer or further from the sensor, you can create dynamic inputs that drive various actions. In this example, the proximity data is used to control the angle of two FlatFlaps, which are connected to two DriveCells (H-bridge drivers). 

 The Pulse width modulation (PWM) duty cycle of two FlatFlaps is therefore adjusted based on how close the object is. As the object moves closer or further, the angle of the FlatFlaps changes, demonstrating a simple yet effective method for depth gesture-based control. Follow the comments in the code to understand each step:

#include <CodeCell.h>
#include <DriveCell.h>

#define IN1_pin1 2
#define IN1_pin2 3
#define IN2_pin1 5
#define IN2_pin2 6

DriveCell FlatFlap1(IN1_pin1, IN1_pin2);
DriveCell FlatFlap2(IN2_pin1, IN2_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(LIGHT); // Initializes Light Sensing

    FlatFlap1.Init();
    FlatFlap2.Init();

    FlatFlap1.Tone();
    FlatFlap2.Tone();
}

void loop() {
    if (myCodeCell.Run(10)) {
        // Runs every 100ms
        uint16_t proximity = myCodeCell.Light_ProximityRead();
        Serial.println(proximity);
        if (proximity < 100) {
            // If proximity is not detected, the FlatFlaps flap
            FlatFlap1.Run(1, 100, 400);
            FlatFlap2.Run(1, 100, 400);
        } else {
            // Adjust FlatFlap angle based on proximity
            proximity = proximity - 100;
            proximity = proximity / 10;
            if (proximity > 100) {
                proximity = 100;
            }
            FlatFlap1.Drive(0, proximity);
            FlatFlap2.Drive(0, proximity);
        }
    }
}

Tips for Customization 

  • Adjust Thresholds: Modify the proximity thresholds and scaling factors in the code to fine-tune the responsiveness of the FlatFlaps based on your preference.
  • Expand Functionality: Consider adding more CodeCell sensing functions, like motion tap detection or light sensing to add more functionality to your project!

Conclusion

This project introduces the basics of using proximity sensing with CodeCell, opening up a range of interactive possibilities. Experiment with the code, tweak the settings, and check out the CodeCell GitHub Repository for more code examples and technical documentation!

Read More

CodeCell: Brightness Detection

CodeCell: Brightness Detection

In this guide, we'll explore how to use the CodeCell to sense white light and automatically adjust the brightness of an LED or create other responsive lighting effects to adapt to light conditions.

How it detects light?

In its tiny package, CodeCell packs a VCNL4040 that can precisely measure ambient light levels using its built-in photodiode. This allows it to detect changes in brightness, enabling automatic adjustments for energy-saving lighting systems, or ambient-aware interactions.

The onboard sensor offers high-resolution light sensing across a wide dynamic range and communicates via I2C, which is seamlessly managed by our CodeCell library.

Ambient Light Sensing vs. White Light Sensing

The VCNL4040 sensor on the CodeCell is capable of both ambient light sensing and white light sensing, each serving distinct purposes:

  • Ambient Light Sensing: This mode measures the overall light intensity from all sources in the environment, including natural and artificial light. It's ideal for applications that require a general understanding of the light levels in a space, such as adjusting screen brightness or activating night mode in devices.
  • White Light Sensing: This mode specifically measures the intensity of white light, which is particularly useful when the goal is to assess light sources that resemble daylight or LED lighting. White light sensing is beneficial in scenarios where you want to distinguish between different lighting conditions, such as separating white light from other colored lights or in situations where accurate color temperature is important.

Example Code

In this example, we're using the white light sensing to directly influence the brightness of the CodeCell's on-board LED. This is based on the detected white light levels, creating a more targeted response compared to general ambient light sensing. As the room gets darker, the LED will dim, providing a smooth transition that you can tweak and customize for your own lighting projects.

Make sure your CodeCell is connected properly, 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(LIGHT); // Initializes light sensing.
}

void loop() {
    delay(100); // Small delay - You can adjust it accordingly
    
    // Read white light from the sensor and adjust brightness for 8-bit
    uint16_t brightness = (myCodeCell.Light_WhiteRead()) >> 3; 
    Serial.println(brightness); // Print the brightness value to the serial monitor for debugging.

    // Limit the sensor values to the LED's brightness range (1 to 254)
    if (brightness == 0U) {
        brightness = 1U; // Set a minimum brightness to avoid turning off the LED completely
    } else if (brightness > 254U) {
        brightness = 254U; // Cap the brightness to the LED's maximum level
    }

    brightness = 255U - brightness; // Invert the brightness so the LED dims as it gets brighter
    myCodeCell.LED(0, 0, brightness); // Shine the onboard blue RGB LED with the new adjusted brightness
}

Tips for Customization 

  • Adjust Brightness Sensitivity: Adjust the brightness limits based on your room's light levels.
  • Change LED Colors: The myCodeCell.LED() function allows you to specify RGB values. Try experimenting with different colors based on light levels.
  • Add More LEDs: Connect more LEDs or even NeoPixels for more lighting effects and adjust their brightness with the same technique. 
  • Add Proximity Control: Add the proximity sensor to add more interactive effects, like depth gestures to act like a switching.

Conclusion

This example is just the starting point for utilizing the CodeCell's light-sensing capabilities. Dive into the code, make it your own, and check out the CodeCell GitHub Repository for more code examples and technical documentation!

Read More


« Previous 1 2 3
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.