ADXL1002 is a 50g single axis accelerometer and I connected it to the analog pin of teensy4.1 which has 12-bits ADC.
When the accelerometer is placed flat , I got maximum of 2119 raw value, when tilt to the left ,I got 2049, tilt to the right ,I got 2049 and when upside down I got 2119.
With the code below , how can I get acceleration in g, and in m/s^2.
When using it for vibration analysis, which unit will be easy to play with when FFT and PSD etc are needed.
#include <ADC.h>
#define ADXL1002_PIN A17
#define ZERO_G_VOLTAGE 1.65 // in volts 0g offset
#define SENSITIVITY 40 // in millivolts/g
#define ADXL1002_SAMPLING_RATE 1 //us --> 1 Msps ??
ADC *adc = new ADC();
int adxl1002_value = 0;
elapsedMicros sinceLastSample; // timer for sampling
const uint32_t samplingIntervalUs = 1; // sampling interval in microseconds
void setup() {
Serial.begin(2000000);
adc->adc0->setAveraging(16); // set number of averages
adc->adc0->setResolution(12); // set bits of resolution
adc->adc0->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_HIGH_SPEED); // change the conversion speed
adc->adc0->setSamplingSpeed(ADC_SAMPLING_SPEED::VERY_HIGH_SPEED); // change the sampling speed
sinceLastSample = 0;
}
void loop() {
//if (sinceLastSample >= samplingIntervalUs) {
//sinceLastSample = 0; // reset the timer
int rawValue = adc->analogRead(ADXL1002_PIN);
Serial.println(rawValue);
delayMicroseconds(100);
// }
}
I have looked at the recommended pages . The output voltage is ratiometeric , since I am using 3.3V the sensitivity is 26mV/g
Take one of the raw values , say 2117, for analysis
Calculate acceleration in g-force:
g = (Raw Value - Zero g Value) / Sensitivity
g = (2117 - 1.65) / (0.026)
g = 80.115 g
Convert acceleration from g to m/s²:
Acceleration in m/s² = g × 9.81
Acceleration in m/s² = 80.115 × 9.81
Acceleration in m/s² ≈ 785.935 m/s²
Calculate voltage:
Voltage Step Size = Reference Voltage / (2^Resolution)
Voltage Step Size = 3.3 V / (2^12)
Voltage Step Size ≈ 0.000805664 V
Voltage = (Raw Value / (2^Resolution)) * Reference Voltage
Voltage = (2117 / (2^12)) * 3.3
Voltage ≈ 1.0142 V
A reading of 2117 is 69 steps above the theoretical zero G 2048 mid point.
69 steps = 55.5mV or approx 2G which seems reasonable as you have a combination of earth's gravity plus noise, vibration and measurement error.
Do you have calibrated test equipment that can be used to calibrate your sensor and Teensy combination?
Is the Teensy rated for a 50G environment? If there is a measurable ambient magnetic field then all conductors including the sensor wires will act as a dynamos generating voltages that will interfere with your millivolt readings. If this is a student project perhaps your supervisor wants you to discover and quantify these measurement errors.