### Accelerometer: transfer the raw data to the real acceleration in m/^2

Leeyt4541 · 2 · 11984

#### Leeyt4541

• Newbie
• Posts: 3

I have a simple question: what is the unit of acceleration in three axes and how can I transfer this value to the actual acceleration in m/s^2? I tried to figure it out but failed. I think transferring the raw data to the actual acceleration needs a scaling factor (like accelerometer ADXL345) but I don't know this specific factor for BMA250. Hope someone can help me figure it out.

Thanks!

#### Jason

• Hero Member
• Posts: 107
• TinyCircuits Employee
You should be able to hold the sensor flat and still, record the number on the axis with the largest magnitude, and then divide each axis with that number after getting the readings. Now you'll have all the readings normalized to gravity, so just multiply the readings by 9.8 after dividing them.

The value I recorded was -261.0 on the z-axis, so I'll divide each axis by its magnitude and then multiply by 9.8
Code: [Select]
`#include <Wire.h>#include "BMA250.h"BMA250 accel_sensor;int x, y, z;#if defined(ARDUINO_ARCH_SAMD) #define SerialMonitorInterface SerialUSB#else #define SerialMonitorInterface Serial#endifvoid setup() {  SerialMonitorInterface.begin(115200);  Wire.begin();  SerialMonitorInterface.print("Initializing BMA...");  // Set up the BMA250 acccelerometer sensor  accel_sensor.begin(BMA250_range_2g, BMA250_update_time_64ms); }void loop() {  accel_sensor.read();//This function gets new data from the acccelerometer  // Get the acceleration values from the sensor and store them into global variables  // (Makes reading the rest of the program easier)  x = accel_sensor.X;  y = accel_sensor.Y;  z = accel_sensor.Z;  if (x == -1 && y == -1 && z == -1) {    SerialMonitorInterface.print("ERROR! NO BMA250 DETECTED!");  }    else {    showSerial();  }  delay(250);}void showSerial() {  SerialMonitorInterface.print("X = ");  SerialMonitorInterface.print((x / 261.0f) * 9.8f);    SerialMonitorInterface.print("  Y = ");  SerialMonitorInterface.print((y / 261.0f) * 9.8f);    SerialMonitorInterface.print("  Z = ");  SerialMonitorInterface.println((z / 261.0f) * 9.8f);}`
You could simplify the conversion math by combining the constant values: 9.8/261.0 =  0.0375. Now I can convert each axis this way:
Code: [Select]
`void showSerial() {  SerialMonitorInterface.print("X = ");  SerialMonitorInterface.print(x * 0.0375f);    SerialMonitorInterface.print("  Y = ");  SerialMonitorInterface.print(y * 0.0375f);    SerialMonitorInterface.print("  Z = ");  SerialMonitorInterface.println(z * 0.0375f);}`
« Last Edit: March 14, 2023, 11:16:22 AM by Jason »

SMF spam blocked by CleanTalk