Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    motion detection

    motion detection

    arvin837
    Occasional Visitor

    Hi engineers. I'm working on an animal motion detection IoT project and I want to use a sensor that by measuring the specific value of the acceleration (which is defined by me), it turns on and sends an interrupt to MCU. As it's working on battery, power consumption is very important so do you have any suggestion?

    Do you think any_motion/no_motion INT in BMI160 is useful ? If yes how can I define my thresholds?

    By your experience, do have any suggestion for battery?

    Thank you in advance

    3 REPLIES 3

    BSTRobin
    Community Moderator
    Community Moderator

    Hi arvin837,

    For your requirement "I want to use a sensor that by measuring the specific value of the acceleration (which is defined by me)", do yo mean send an interrupt to MCU as long as the acceleration exceeds the threshold value?
    If yes, you only need to use acceleration products to meet the requirements. There are any_motion/no_motion example on github.
    https://github.com/BoschSensortec/BMA456-Sensor-API/blob/master/bma456mm_examples/motion/motion.c

    Hello Guys, im begineer in this topic and still learning about Microconrollers. I also want to achieve similar goals to wake up MCU using BMI160. I want to know how and where can I run the above code you provided in the link ? 

    /**\
    * Copyright (c) 2022 Bosch Sensortec GmbH. All rights reserved.
    *
    * SPDX-License-Identifier: BSD-3-Clause
    **/

    #include <stdio.h>
    #include "bma456mm.h"
    #include "common.h"

    /*****************************************************************************/
    /*! Global variable */

    /*! Structure to define any/no-motion configurations */
    struct bma456mm_any_no_mot_config any_no_mot = { 0 };

    /******************************************************************************/
    /*! Static Function Declaration */

    /*!
    * @brief This internal API is used to get any/no-motion configurations.
    *
    * @param[in] bma : Structure instance of bma4_dev.
    *
    * @return Status of execution.
    */
    static int8_t get_any_no_mot_config(struct bma4_dev *bma);

    /******************************************************************************/
    /*! Functions */

    /* This function starts the execution of program. */
    int main(void)
    {
    /* Variable to store the status of API */
    int8_t rslt;

    /* Sensor initialization configuration */
    struct bma4_dev bma = { 0 };

    /* Variable to store any/no-motion interrupt status */
    uint16_t int_status = 0;

    uint8_t iteration = 20;

    /* Interface reference is given as a parameter
    * For I2C : BMA4_I2C_INTF
    * For SPI : BMA4_SPI_INTF
    * Variant information given as parameter - BMA45X_VARIANT
    */
    rslt = bma4_interface_init(&bma, BMA4_I2C_INTF, BMA45X_VARIANT);
    bma4_error_codes_print_result("bma4_interface_init", rslt);

    /* Sensor initialization */
    rslt = bma456mm_init(&bma);
    bma4_error_codes_print_result("bma456mm_init status", rslt);

    /* Upload the configuration file to enable the features of the sensor. */
    rslt = bma456mm_write_config_file(&bma);
    bma4_error_codes_print_result("bma456mm_write_config status", rslt);

    /* Enable the accelerometer */
    rslt = bma4_set_accel_enable(BMA4_ENABLE, &bma);
    bma4_error_codes_print_result("bma4_set_accel_enable status", rslt);

    /* Map the interrupt pin 1 for any/no-motion */
    rslt = bma456mm_map_interrupt(BMA4_INTR1_MAP, (BMA456MM_ANY_MOT_INT | BMA456MM_NO_MOT_INT), BMA4_ENABLE, &bma);
    bma4_error_codes_print_result("bma456mm_map_interrupt status", rslt);

    /* Get any-motion and no-motion configurations */
    rslt = get_any_no_mot_config(&bma);
    bma4_error_codes_print_result("get_any_no_mot_config status", rslt);

    printf("Shake the board for any-motion interrupt whereas do not shake the board for no-motion interrupt\n");

    if (rslt == BMA4_OK)
    {
    for (;;)
    {
    /* Read interrupt status */
    rslt = bma456mm_read_int_status(&int_status, &bma);
    bma4_error_codes_print_result("bma456mm_read_int_status", rslt);

    if (rslt == BMA4_OK)
    {
    /* Enters only if the obtained interrupt is any-motion */
    if (int_status & BMA456MM_ANY_MOT_INT)
    {
    printf("Any-motion interrupt occurred\n");
    iteration--;
    }

    /* Enters only if the obtained interrupt is no-motion */
    else if (int_status & BMA456MM_NO_MOT_INT)
    {
    printf("No-motion interrupt occurred\n");
    iteration--;
    }

    int_status = 0;

    /* Break out of the loop when iteration has reached zero */
    if (iteration == 0)
    {
    printf("Iterations are done. Exiting !\n\n");
    break;
    }
    }
    }
    }

    bma4_coines_deinit();

    return rslt;
    }

    /*!
    * @brief This internal API is used to get any/no-motion configurations.
    */
    static int8_t get_any_no_mot_config(struct bma4_dev *bma)
    {
    /* Variable to store the status of API */
    int8_t rslt;

    /* Getting any-motion configuration to get default configuration */
    rslt = bma456mm_get_any_mot_config(&any_no_mot, bma);
    bma4_error_codes_print_result("bma456mm_get_any_mot_config status", rslt);

    if (rslt == BMA4_OK)
    {
    /* Select the axis for which any/no motion interrupt should be generated */
    any_no_mot.axes_en = BMA456MM_EN_ALL_AXIS;

    /*
    * Set the slope threshold:
    * Interrupt will be generated if the slope of all the axis exceeds the threshold (1 bit = 0.48mG)
    */
    any_no_mot.threshold = 10;

    /*
    * Set the duration for any-motion interrupt:
    * Duration defines the number of consecutive data points for which threshold condition must be true(1
    * bit =
    * 20ms)
    */
    any_no_mot.duration = 4;

    /* Like threshold and duration, we can also change the config of int_bhvr and slope */

    /* Set the threshold and duration configuration */
    rslt = bma456mm_set_any_mot_config(&any_no_mot, bma);
    bma4_error_codes_print_result("bma456mm_set_any_mot_config status", rslt);

    if (rslt == BMA4_OK)
    {
    /* Getting no-motion configuration to get default configuration */
    rslt = bma456mm_get_no_mot_config(&any_no_mot, bma);
    bma4_error_codes_print_result("bma456mm_get_no_mot_config status", rslt);

    if (rslt == BMA4_OK)
    {
    /* Select the axis for which any/no motion interrupt should be generated */
    any_no_mot.axes_en = BMA456MM_EN_ALL_AXIS;

    /*
    * Set the slope threshold:
    * Interrupt will be generated if the slope of all the axis exceeds the threshold (1 bit = 0.48mG)
    */
    any_no_mot.threshold = 10;

    /*
    * Set the duration for no-motion interrupt:
    * Duration defines the number of consecutive data points for which threshold condition must be
    * true(1 bit = 20ms)
    */
    any_no_mot.duration = 4;

    /* Like threshold and duration, we can also change the config of int_bhvr */

    /* Set the threshold and duration configuration */
    rslt = bma456mm_set_no_mot_config(&any_no_mot, bma);
    bma4_error_codes_print_result("bma456mm_set_no_mot_config status", rslt);
    }
    }
    }

    return rslt;
    }

    FAE_CA1
    Community Moderator
    Community Moderator

    Hi,

    Thanks for your inquiry.

    In your case BMA400 ultra-low power accelerometer can do the job instead of using BMI160 which is end of life recently.

    BMA400 has built-in auto-wakeup and auto-low power feature. This means that when there is no motion, BMA400 stays in low power mode consuming 0.85uA with fixed 25Hz sampling rate. At this moment BMA400 is always monitoring external motion. Once external motion is detected beyond the threshold for certain amount of time, BMA400 will automatically wake up and enter normal mode consuming 3.5uA with optional sampling rate from 12.5Hz to 800Hz. BMA400 can also generate an interrupt signal to the host processor indicating motion detected. When there is no motion again for certain amount of time, BMA400 will automatically go to low power mode again and send an interrupt signal to the hose processor indicating no-motion for a while.

    Please see the attached "How to test BMA400 shuttle board for auto-wakeup and auto-lowpower featurev1.pdf" for more information.

    Thanks.

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist