How MEMS Accelerometer Gyroscope Magnetometer Work & Arduino Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello dan the dog here from how to mechatronics comm in this tutorial we will learn how the MEMS accelerometer gyroscope and magnetometer work and how to use them with your Dino board also with the processing development environment we will make some practical applications using the sensors first let's briefly explain how each of these micro electromechanical systems or MEMS sensor work we will start with the accelerometer it measures acceleration by measuring change in capacitance its microstructure looks something like this it has a mass attached to a screen which is confined to move along one direction and fixed outer plates so when an acceleration in the particular direction will be applied the mass will move and the capacitance between the plates and the mass will change this change in capacitance will be measured process and it will correspond to a particular acceleration value next is the gyroscope which measures angular rate using the Coriolis effect when a mass is moving in a particular direction with a particular velocity and when an external angular rate will be applied as shown with the green arrow a force will occur as shown with the blue arrow which will cause perpendicular displacement of the mass so similar to the accelerometer this displacement will cause change in capacitance which will be measured process and it will correspond to a particular angular rate the microstructure of the gyroscope looks something like this a mass that is constantly moving or oscillating and when an external angular rate will be applied a flexible part of the mass would move and make the perpendicular displacement okay now let's explain how the magnetometer works it measures the earth magnetic field by using Hall FA or magnet or resistive effect actually almost 90 percent of the sensors on the market use the Hall effect and here's how it works if we have a conductive plate like this and we set current to flow to it the electrons would flow straight from one to the other side of the plate now if we bring some magnetic field near the play we will disturb the straight flow and the electrons will deflect to one side of the plate and positive poles to the other side of the plate this means that if we put a mirror now between these two sides we will get some voltage which depends from the magnetic field strength and its direction the other ten percents of the sensors on the market use the magnet or resistive effect these sensors use materials that are sensitive to magnetic field usually composed of iron and nickel so when these materials are exposed to magnetic field they change their resistance okay now let's connect these scissors to the Arduino board and make some use of them as an example I will use the G Yad breakout board which has the following sensors a DXL 345 Q axis accelerometer LG g4 200 D 3-axis gyroscope MC 588 3 L 3 axis magnetometer and also a barometer and a thermometer which we won't use in this tutorial first let's hook up the board to the Arduino this board used the I Square C communication protocol which means that we can use all the sensors with just 2 wires so in order to make the communication between the Arduino and the sensors we need to know their unique device addresses and their internal register addresses for getting the data out of them these addresses can be found from the datasheet of the sensor and I have attached links to each of them on my website for more details how this communication works you can check my I square C communication tutorial ok now let's see the code for getting the data from the sensors we will start with the accelerometer first we need to include the arduino wire library and define the registers addresses of the sensor in the setup section we need to initiate the wire library and start the serial communication as we will use the serial monitor for showing the results also here we need to activate the sensor or enable the measurement by sending appropriate bye to the power control register and here's how we do that using the wire dot begin transmission function we leg two which sensor we will talk the three axis accelerometer in this case then using the wire dot write function we tale to which internal register we will talk after this we will send the appropriate by for enabling the measurement using the wire dot in transmission function we will end the transmission and that will transmit the data to the registers now in the loop section we need to read the data for each axis we will start with the x-axis so first we will select which registers we will talk the two x-axis internal registers in this case then using the wire dot request from function we will request the transmitted data or the two bytes from the two registers the wire dot available function will return the number of bytes available for retrieval and if that number match with our requested bytes in our case two bytes using the wired dot read function we will read the bytes from the two registers of the x axis the output data from the two registers is two's complement with x0 as the least significant byte and x1 as the most significant byte using this expressions here we can convert these bytes in to float values from minus one to plus one depending on the direction of the x axis relative to the earth acceleration or the gravity we will repeat this procedure for the two other axis and at the end we will print these values on the serial monitor here is how they appear okay now for getting the data from the gyroscope we will have a similar code as the previous one so first we have to define the register addresses and sign variables for the data in the setup section we have to wake up and put the sensor in normal mode using the control register one and also select the sensitivity of the sensor for this example I will select the 2000 DPS or degrees per second sensitivity mode in the loop section similar to the accelerometer we will read the data for the x y&z axis now the raw data has to be converted into angle values from the data sheet of the sensor we can see that for the 2000 DPS or degrees per second sensitivity mode corresponds a 70 mil it agrees per second or digit unit this means that we have to multiply the row output data by zero point zero seven in order to get the angular rate in degrees per second now if we multiply the angular rate by time it will give us the angle value so we need to calculate the time interval of each loop section and we can do that by using the moolies function at the top and the bottom of the loop section and we will store it value into this DT variable so for each executed loop we will calculate the angle and add it to the final angle value we will do the same for the two other axes and at the end we will print the results on the serial monitor here is how they appear the pen shows the x-axis of the sensor so if I rotate the sensor around that axis we can see the change of the angle on the serial monitor keep in mind that the gyro result are not stable because they drift as the time goes so in order to get accurate angles we have to combine it with the accelerometer here's an example of that combining the gyro and the accelerometer data as well as the complimentary filter for smoothing the results so the data from the sensors and the Arduino board are sent to the processing development and they are used for controlling the orientation of the 3d object you can find more details and the source codes for this example on my website what's left now is to see how to get the data from the magnetometer again we will use a similar technique to the previous one first we need to define the registers addresses and in the setup section set the sensor in continuous measurement mode in the loop section we will get the raw data for each axis with the same method as for the previous sensors now we need to convert the raw data into magnetic field value or gauss units from the data sheet of the sensor we can see that the default sensitivity mode is 0.92 milli Gauss per digit this means that we need to multiply the row data by zero point zero zero zero 92 in order to get the earth magnetic field in Gauss units at the end we will print the values on the serial monitor here I have marked the North Pole on the paper and pen shows the y-axis of the sensor now if I point the y-axis to the North Pole and fill the sensor around 45 degrees I will get the maximum value of around zero point six cows the tilt angle depends on your location for example if you are at the equator you don't have to tilt the sensor because the inclination at that location is zero or if you are at the North Pole you will have to tell the sensor 90 degrees here is a cool looking application of the sensor a digital compost made using the processing developing environment you can find more details and the source code of this example on my website thanks for watching and for more tutorials visit my official website how to mechatronics calm
Info
Channel: How To Mechatronics
Views: 622,883
Rating: undefined out of 5
Keywords: Accelerometer (Measuring Instrument), Microelectromechanical Systems (Field Of Study), Magnetometer (Invention), Gyroscope (Invention), Electrical Engineering (Industry)
Id: eqZgxR6eRjo
Channel Id: undefined
Length: 9min 57sec (597 seconds)
Published: Wed Nov 18 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.