The Galaxy Watch has a built-in accelerometer sensor that measures motion or acceleration forces in three dimensions (X,Y, and Z axes). This knowledge is usually used for monitoring motion, detecting gestures, and enabling fitness-related options like sleep monitoring, fall detection, step counting, operating, and exercise monitoring.
The accelerometer measures acceleration alongside three axes:
X-axis: Aspect-to-side motion.
Y-axis: Ahead-and-backward motion.
Z-axis: Up-and-down motion.
Determine 1: Axis instructions for the accelerometer sensor
Acceleration is often measured in meters per second squared (m/s²) or gravity items (g), the place 1g = 9.81 m/s².
This text describes find out how to learn accelerometer sensor knowledge from a Galaxy Watch operating Put on OS powered by Samsung and likewise exhibits the conversion process for the uncooked knowledge.
Surroundings Setup
Android Studio IDE is used for creating Put on OS functions. The examples on this article use Java, however Kotlin may also be used. Going ahead, this text assumes you’ve got already put in the newest Android Studio model in your PC.
Learn Accelerometer Information from Galaxy Watch
To get accelerometer knowledge, we have to use Android Sensor APIs from the SensorManager library.
To retrieve accelerometer knowledge out of your Galaxy Watch:
-
Create a brand new Put on OS mission in Android Studio by deciding on File > New Venture > Put on OS > Empty Exercise > End. Set the minimal SDK model to API 30 or larger.
-
Add permission to entry the sensor into the manifest file (AndroidManifest.xml):
You do not want to manually set the runtime permission to entry the accelerometer. This permission is granted by default.
- Design your most popular structure (.xml file) to point out accelerometer knowledge on the Galaxy Watch display. This instance makes use of three TextViews in a Constraint Format to point out the output of the three axes of the sensor. You can too examine the end result within the Logcat window in Android Studio.
For extra detailed code, examine the pattern utility.
- Use the SensorManager library and
SensorEventListenerto learn accelerometer knowledge. To implement them:- Initialize the SensorManager library globally:
personal SensorManager sensorManager;
- To retrieve
android.{hardware}.SensorManagerfor accessing sensors, you need to usegetSystemService().
sensorManager = SensorManager.getSystemService(Context.SENSOR_SERVICE);
-
As our goal is the accelerometer sensor particularly, it’s set because the default sensor right here. It is suggested to all the time examine the sensor availability earlier than utilizing it within the code. The process to take action is defined on this information.
-
To make the accelerometer the default sensor:
Sensor sensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
- To get steady knowledge out of your Galaxy Watch, you could register a listener to inform you if there’s new knowledge. That is accomplished utilizing a
SensorEeventListenerin Android’s Sensor API.
sensorManager.registerListener(listener, sensor, SensorManager.SENSOR_DELAY_NORMAL);
- The listener methodology
onSensorChanged()is known as each time new knowledge is on the market. The brand new knowledge is processed within the listener.
personal SensorEventListener listener = new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
// for absolute values
X = Math.abs(sensorEvent.values[0]); //0 -> X Axis 1-> Y Axis 2 -> Z Axis
Y = Math.abs(sensorEvent.values[1]);
Z = Math.abs(sensorEvent.values[2]);
Log.e("--MainActivityTag--", "X: " + X + "n" + "Y: " + Y + "n" + "Z: " + Z);
// do no matter you wish to do with the information
}
@Override
public void onAccuracyChanged(Sensor sensor, int i) {
}
};
Right here, onAccuracyChanged(Sensor sensor, int i) is part of the SensorEventListener interface. It’s triggered when the accuracy of a sensor modifications. Nevertheless, for the accelerometer, it’s referred to as hardly ever, because the accelerometer knowledge accuracy often stays fixed.
- Unregister the listener when the information assortment is over. In any other case, it could possibly trigger uncommon battery consumption.
Check the Code Pattern
You’ll be able to take a look at the pattern app (obtain it utilizing the hyperlink beneath) and check out it out in your Galaxy Watch 4 and later.
Run the pattern mission in your Galaxy Watch. You will notice the next display.
Determine 2: Output of the pattern mission (accelerometer knowledge on Galaxy Watch)
Accelerometer Information Items and Conversion for Galaxy Watch
Within the utility finish, uncooked accelerometer knowledge from Galaxy Watch is transformed into meters per second squared (m/s²).
Equation
uncooked knowledge * 9.80665 (gravity power) / 4096 (8g rescale)
Instance
Assume,
raw_x = uncooked knowledge obtained from the sensor
acc_x = accelerometer knowledge in utility finish
if raw_x = 100
acc_x = 100 * 9.80665 / 4096
After this, acc_x is obtained by the appliance, containing the Acceleration worth in m/s².
Convert the Information into G-Power Items
The conversion from m/s² to g is: 1 / 9.80665
So 1 m/s² =0.10197g
Details about the Accelerometer Sensor
- The accelerometer supplies the three axis values individually.
- The sampling charge of the accelerometer is often a a number of of fifty Hz, however 100 Hz can be supported.
- The vary of the accelerometer is +- 8G.
- Sampling charge:
#Most Delay: https://developer.android.com/reference/android/{hardware}/Sensor#getMaxDelay() // 160 msec
#Minimal Delay: https://developer.android.com/reference/android/{hardware}/Sensor#getMinDelay() // 10 msec - It’s all the time really helpful to learn calibrated knowledge to keep away from pointless noise.
- To get the end in g-force items, you could divide the accelerometer values by 4096 (alongside each axis).
- It is suggested to make use of a filter whereas studying any sensor knowledge.
- Ensure to all the time unregister the listener and cease all of the providers after utilizing. Failure to take action could cause extreme battery drain.
- There are some restrictions of utilizing background providers for Galaxy Watch.
Conclusion
For a Galaxy Watch operating Put on OS powered by Samsung, accelerometer knowledge is extensively utilized in health monitoring, fall detection, gesture recognition and movement evaluation. Furthermore, knowledge conversion permits exact monitoring for functions.
On this article, we’ve seen one of many methods of studying accelerometer sensor knowledge on a Galaxy Watch operating Put on OS powered by Samsung. You can too learn sensor knowledge utilizing the Samsung Well being Sensor SDK. For extra particulars on Samsung Well being, examine right here.
In case you have any questions on or need assistance with the data on this article, you may attain out to us on the Samsung Builders Discussion board or contact us via Developer Assist.

