There are devices in the electronic market that combine the accelerometer and the magnetometer, such is the case of the LSM303D. With this device we can measure readings of 16 bits in the three axes of the accelerometer with a sensitivity ranging from ± 2 to ± 16 g. We can also measure 16-bit readings on all three axes of the magnetometer with a sensitivity of ± 2 to ± 12 gauss.
This device also requires a supply voltage of 2.5 V to 5.5 V. It works with I²C and SPI communication protocols. Next we see an image of this device.
As we can see in the image, we can identify the SDA and SCL pins when they join in the I²C mode. When we use it in the SPI mode we use the SPC, SDI, SDO and CS pins.
The process to calibrate the magnetometer consists of the following steps:
1. We make the connections as indicated in the diagram.
2. We load the Arduino board with the file code: "LSM303D_Calibration.ino", which I attach to the download link at the end of this tutorial.
3. We open the serial monitor to see what the Arduino board is working on.
4. We rotate the LSM303D module in relation to the X axis. In this way our LSM303D device will take samples of the magnetic field in relation to the X axis.
5. We perform the same step 4 above, but now we turn the module LSM303D in relation to the Y axis.
6. Finally we the same previous step 4, but now we turn the module LSM303D in relation to the Z axis.
7. Once the previous steps are finished, we turn off and disconnect the LSM303D module and it will already be calibrated so that it will be able to determine more precisely the North and South magnetic poles.
In the next video we can see how we could use the sensor magnetometer LSM303D as a compass.
In the next video we can see how we could use the sensor magnetometer LSM303D to create a device that will help us navigate towards the magnetic north pole.
In the next video we can see how we could use the LSM303D sensor accelerometer to determine an angle of inclination.
In the next video we can see how we could use the LSM303D sensor accelerometer to detect small vibrations produced by a low intensity earthquake or a heavy vehicle that passes through our street and even detect explosions.