Difference between revisions of "MPU6050"

From Let's Control It
Jump to navigation Jump to search
Line 50: Line 50:
 
* Each second the acceleration values of each axis are read and the minimum and maximum values are noted.
 
* 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 5 seconds the maximum range is updated.
* Every 30 seconds
+
* 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.

Revision as of 18:11, 22 February 2017

WIP.gifYou may hear some construction noise in the background...

Introduction

The plugin for the MPU 6050 can be used as a motion sensor. Apart from singling the home controller when a certain amount of movement is detected, this plugin is also capable of showing the raw values from the dMPU 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 all three axis simultaneously. The sense is fitted with multiple I2C interfaces of which one is used for communicating with a master controller. The chip has one I2C address selection pin so two sensors can be attached to the bus simultaneously. The plugin supports using two sensors.

The chip is available on several breakout boards among which 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.


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. For a non-intrusive connection you can stick/glue two neodymium magnets to the screws and attach the sensor using 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 save the screen may change. Now you are ready to configure the selected function, when you are done select save again.


The plugin lets you read the raw values from the accelerometer and the gyroscope for each axis. You can also select the detected range of acceleration in 30 second intervals. 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 fill 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.