This is the build for a cheap DIY underwater inclinometer and accelerometer which logs to an SD card.
This project was derived from a need to have a cheap sensor which would measure and log the angle of an grid on a commercial fish trawl. This system is based on the Adafruit Feather 32u4 Adalogger and the LSM303 triple-axis accelerometer and magnetometer board. The adalogger is a tremendously useful little Arduino compatible micro-controller with a built-in SD card for easy data logging.
Adafruit Feather 32u4 Adalogger ($21.95)
Li-ion battery (3.7V 100mAh, $5.95)
Underwater housing (I used an old GoPro housing)
The wiring on this system is fairly simple. The adalogger can be powered via the USB or a battery. The battery is connected to the adalogger via a JST connector. The adalogger has a builtin Li-Ion battery charging circuit which will charge the battery when plugged into the USB. The accelerometer chip can be powered by either 3.3V or 5V. Since the adalogger runs on 3.3V, connect the 3V pin on the adalogger to the 3v3 pin on the accelerometer. The GND pin on the accelerometer can be connected to the GND pin on the adalogger. Finally, connect the SCL and SDA pins on the accelerometer to the corresponding pins on the adalogger (labeled SCL and SDA).
Next you need to set-up the Arduino IDE. If you don't have the Arduino IDE software, it can be downloaded
here. Follow the instructions (here and here) provided by Adafruit to setup the Arduino IDE for use with the adalogger. Note: there is also
another adalogger which uses an M0 chip. If you are using that board then adapt these instruction by using a slightly different set-up (here). Don't get these two confused, like I
did, you'll spend a couple hours trying to figure out why it's not working.
Download the LSM303 drivers (here) and the adafruit sensor library (here). These libraries need to be placed in the sketchbook location listed for the Arduino IDE. This location can be found, or
changed, by opening the Arduino IDE, then selecting File > Preferences. At the top of the Settings window will be a field called Sketchbook location. This is where Arduino will
look for the respective libraries and where it will also save your scripts.
Next download and open the arduino project scripts (above). Plug the adalogger into your computer via a USB cable. The script labeled Accel_degrees.ino will allow you to see the sensor output on the arduino serial monitor. Once open, flash it to the adalogger by first verifying the script (the check icon in the upper left corner) and then upload by clicking the arrow pointing to the right (next to the verify icon). You can now test if the system is working by opening the serial monitor (Tools > Serial Monitor). If the adalogger is not plugged into a computer via USB then the script will not run because it cannot establish a serial connection. To run the system autonomously you can either comment out all the serial lines in the code, or download the Accel_degrees_no_serial.ino script.
This script will output the acceleration and angle on the X and Y planes as well as the
time and battery voltage. Time is in milliseconds and is relative to the boot-up of the adalogger. A real-time clock can be added if required. The current version of the script
logs these variables to a text file on the adalogger approximately every second. This can be adjusted in the last line of the script in the delay field. This system will automatically start
logging and a new text file will be created every time the adalogger is restarted. Currently there is no filtering of the sensor data, with the exception of very high values ( > 9.8
m/s^2 being automatically downgraded to 9.8 m/s^2). This was required for the acceleration to degree conversion math to work. This script can be adapted to filter the data on the
adalogger or this can be done post capture if the sensor samples fast enough. The current set-up uses ~10 mA/hr. With the existing battery my system runs for approximately 10 hours
and this was relatively irrespective of sampling rate. A larger battery could easily substituted if needed.
The generic output of the sensor is in acceleration (m/s^2). If the sensor is held steady then the acceleration sensed by the sensor will be determined by it's orientation relative to the gravitational force of the earth. If the sensor is horizontal to the earth then it will read 0 m/s^2. When one of the axis is perpendicular to the gravitational field then it will feel the full effect of the gravitational field and read ~9.8 m/s^2. The relationship between angle and gravity follows a sine wave (see opposite graph). This means that the accuracy is not great when the sensor approaches 90 or -90 degrees, or perpendicular to the earth. Each sensor should have a maximum acceleration of ~ +-9.8 m/s^2 however this can be confirmed by examining the serial monitor and adjusted in the script in lines 23 and 24. My sensor, and that in the script, was around 9.89 m/s^2. If the sensor is not held steady then the accelerometer will be measuring the acceleration due to movement and not the gravitational acceleration. This should be accounted for when thinking about deploying this system.
To package the system I used a piece of HDPE to mount the sensor, making sure it was flat. The adalogger was then mounted above the sensor and battery using a couple standoffs and some 2-56 plastic machine screw. I cut the HDPE so that it would snugly fit into the back part of a GoPro housing. This should make it waterproof to ~200' (60m). This isn't the best fit but it works. In the future I would like to create a custom delrin or aluminum housing to reduce the footprint.
In the future I would like to create some on-board filtering of the data and utilize the magnetometer to derive compass heading. However I think that this would need to be tilt compensated. A real-time clock would also be helpful.
I hope this is helpful to somebody. Feel free to leave comments below. Enjoy.