MPU6050

From Let's Control It
Jump to navigation Jump to search

Introduction

The plugin for the MPU 6050 can be used as a motion sensor. Apart from signalling the home controller when a certain amount of movement is detected, this plugin is also capable of showing the raw values from the MPU 6050 device.

Hardware

Mpu-6050.jpg

The MPU 6050 is made by InvenSense and contains a accelerometer and gyroscope in one package for all three dimensional axis. Fitted with a build-in 16 bit analog to digital convertor per channel, it is capable of capturing data from all three axis simultaneously. The sensor is fitted with multiple I2C interfaces of which only one is used for communicating with a master controller. The chip has one I2C address selection pin so up to two sensors can be attached to the bus simultaneously. This plugin supports using both sensors simultaneously and can be used to detect multiple levels of motion per sensor.

The chip is available on several breakout boards such as the GY-25, GY-521 (shown) and the SEN-11028 by SparkFun.

Connections

The commonly used breakout board GY-521 has 8 pins of which only 4 (or 5 with two devices on one bus) are used.

  • Connect Vcc to a 5V supply (the GY-521 has its own 3V3 regulator)
  • Connect Gnd to Ground
  • Connect SCL and SDA to two GPIO pins and configure those pins in the hardware tab.


The board will default to address 0x68. Ground pin AD0 for the alternate address of 0x69 (on the GY-521 the address pin has a pull-up resistor to Vcc).


The pins XCL, XDA and INT are not used and can be left unconnected.


You can connect the board to the machine under investigation/detection using two screws. Victor Takacs has found a nice non-intrusive way to connect the breakout board to your appliance: you can stick/glue two neodymium magnets to the screws and attach the sensor by magnetism.

Software

Custom sketch

ESP Easy

Under devices add the MPU6050 device. After the device is added, select the desired function and select the device address. After you select the function, click save. The screen may change reflecting the selected function. Now you are ready to configure the instance. When you are done, select save again.


The plugin lets you read the raw values from the accelerometer, the gyroscope and a "accelerometer range" for each axis. The "accelerometer range" is the maximum range the sensor has measured during a 5 seconds interval. If you plot these ranges you can get a good baseline to select later threshold values.

P118 Ax.png


When you know the ranges needed to determine if the machine or device under investigation/detection is moving, you can configure the motion detection instance.

P118 Motion.png


You can set the range thresholds with the determined values from your plots. If you want to exclude a axis from detection, just give it a threshold value of zero.


The system works as follows:

  • Each second the acceleration values of each axis are read and the minimum and maximum values are noted.
  • Every 5 seconds the maximum range is updated.
  • Every 30 seconds the values are send to the home controller, if configured to do so.
  • Every 30 seconds the counter for the detection window is increased.
  • Every 30 seconds the counter for detection is increased if all enabled axis exceeded there thresholds.
  • Every time the detection window counter matches the detection window parameter the output is set high if the detection counter matches or is higher then the set minimal detection count. If this criteria is not met the output is set low.


You can add multiple movement detection instances if you want to be alerted of different stages of movement.