How to enable Motion Detection Interrupt on MPU6050.

The MPU6050 data sheet has a nice “marketing” section, claiming it has a DMP unit, and a couple of useful interrupts, among them a accelerometer event interrupt.

However, how to actually use these features is not documented there. And I want to use the Motion Detection Interrupt (so I can put the host MCU to sleep and wake it up when the MPU6050 senses motion – quite probably there’s a cheaper and better documented chip that can do this too, but I already bought a few MPU6050’s… “gy521” breakout board).

http://www.i2cdevlib.com/devices/mpu6050#registers is a in progress development to reverse engineer how to use the DMP. It also has a very useful register map (Thanks!), that fills the gaps in the “RM-MPU-6000A-00” document. With that register map, and a slightly older data sheet that actually has the section 8.3 that’s referred to elsewhere (found at https://dlnmh9ip6v2uc.cloudfront.net/datasheets/Components/General%20IC/PS-MPU-6000A.pdf , but that URL seems like it might not stay.), I could figure out how to enable the Motion Detection Interrupt.

After power on (0x00 to register (decimal) 107), the Motion Detection Interrupt can be enabled as follows:

  • (optionally?) Reset all internal signal paths in the MPU-6050 by writing 0x07 to register 0x68;
  • write register 0x37 to select how to use the interrupt pin. For an active high, push-pull signal that stays until register (decimal) 58 is read, write 0x20.
  • Write register 28 (==0x1C) to set the Digital High Pass Filter, bits 3:0. For example set it to 0x01 for 5Hz. (These 3 bits are grey in the data sheet, but they are used! Leaving them 0 means the filter always outputs 0.)
  • Write the desired Motion threshold to register 0x1F (For example, write decimal 20).
  • To register 0x20 (hex), write the desired motion duration, for example 40ms.
  • to register 0x69, write the motion detection decrement and a few other settings (for example write 0x15 to set both free-fall and motion decrements to 1 and accelerometer start-up delay to 5ms total by adding 1ms. )
  • write register 0x38, bit 6 (0x40), to enable motion detection interrupt.

Translate the above into code for your favourite micro controller. (Or, maybe, the existing Arduino library for MPU6050 already supports this. I don’t know, I’m using STM32 this time. But it could be translated to AVR/PIC/MSP430 etc… as long as it has I2C/TWI)

Now, INT pin should go high when MPU6050 is moved/shaken/dropped. Play with threshold, duration and filter to set sensitivity.

Relevant excerpt from the linked older data sheet (PS-MPU-6000A-00 Revision: 3.1) above:

8.3 Motion Interrupt
The MPU-60X0 provides Motion detection capability with similar functionality to Free Fall detection. Accelerometer measurements are passed through a configurable digital high pass filter (DHPF) in order to eliminate bias due to gravity. A qualifying motion sample is one where the high passed sample from any axis has an absolute value exceeding a user-programmable threshold. A counter increments for each qualifying sample, and decrements for each non-qualifying sample. Once the counter reaches a user-programmable counter threshold, a motion interrupt is triggered. The axis and polarity which caused the interrupt to be triggered is flagged in the MOT_DETECT_STATUS register.

Like Free Fall detection, Motion detection has a configurable acceleration threshold MOT_THR specified in 1mg increments. The counter threshold MOT_DUR is specified in 1 ms increments. The decrement rate has the same options as Free Fall detection, and is specified in the MOT_DETECT_CTRL register.

Comments

13 responses to “How to enable Motion Detection Interrupt on MPU6050.”

  1.  Avatar
    Anonymous

    Hi! I love u men, this save me from leave the project of the pedometer with the mpu6050 because I was unable to take Interrupts on the INT pin in the correct mode when I detected movement.
    Thank u so much

    1. dheeraj_harikant Avatar

      Hiii Im not able to get interrupt pin high when motion is detected

      1. lukelectro Avatar

        It’s a while ago I worked with this chip…

        The interrupt pin can be set active High or active Low, how did you set it?
        Can you post a link to your code? (Github gist, or on your blog)

        1. dheeraj_harikant Avatar

          Same code available in github.if possible please share your code written for STM microcontroller.

  2. Osman Avatar
    Osman

    Hi, is it possible to wake up mpu6050 from sleep when certain accelerometer threshold is reached? Or is it possible to even measure accelerometer or gyro data when mpu6050 is in sleep mode?

    Thanks
    Osman

    1. lukelectro Avatar

      The short answer would be: please refer to the data sheet. It’s a while ago since I worked with that chip so I don’t know from the top of my head.

      The motion detection interrupt is used to wake the host MCU, the acelerometer itself needs to be working to detect motion. But the host cpu could reduce the sensors’ sample rate to save power.

      I changed to ADXL345 for my project, since I only needed accelerometer and it is lower power. ADXL345 has a AUTO_SLEEP mode and a low power mode that more or less does what you describe: it can be set to a low-power low sample rate, and automatically wake up under certain conditions to sample at a higher rate (which uses more power). But that is accelerometer only.

  3. Ryan Avatar
    Ryan

    Hi, Anoniem
    I’m working on a senior project that I need to count the numbers of walking steps, can you guide me through how you get your pedometer working ?

    Thank you,

  4. VGS Avatar
    VGS

    Can’t make it work on a simple Arduino sketch. Wondering to know if someone made it. Not sure what I’m doing wrong. Thanks.

  5.  Avatar
    Anonymous

    good

  6. Remco Avatar
    Remco

    Is this definitly working with the MPU6050? because in the datasheet of the MPU6050 i cant fine some of the registers used in this example. I think you meant to use the MPU6500. In the datasheet of the MPU6500 i can find the registers you used.

    1. lukelectro Avatar

      You might be right. It is to long ago for me to still know from the top of my head. It is also possible both chips share some register names.

  7. […] einzurichten sind. Das Problem ist nur, dass sie nicht funktioniert. Beim Nachforschen stieß ich auf diese Seite, die erklärt, wie man es richtig macht. Dabei werden sowohl im Datenblatt nicht dokumentierte […]

  8. Dan Avatar
    Dan

    Man i was having alot of issues and you really helped me out. Danke schone!

Leave a Reply

Your email address will not be published. Required fields are marked *