You need to check the documentation for the accelerometer.
It will give a sensitivity value, expressed in "mV/g" (for an analogue device) or "counts/g" (for a digital device).
You then simply do the arithmetic for the value you are seeing.
Don't forget the 0g offset.
thought there is some mathematical formulate that allows you tp derive the acceleration.
And there probably is, but without knowing what real-world values to plug into it, a formula isn't much use.
Because you still haven't told us what device the accelerometer is, we can't even begin to guess what the formula might be.
What does that code do that you don't want? What does it not do that you want? We can't help you fix the code if we have no idea what needs to be fixed.
int _x = analogRead(analogInPin1);
int _y = analogRead(analogInPin2);
int _z = analogRead(analogInPin3);
float _Acc = sqrt(_x^2+_y^2+_z^2);
Ordinarily, you only square and take a root if there is a negative value you want to ignore, but analogRead cannot return a negative value, so I think that's a fairly expensive operation for little gain.
You've forgotten to offset the analogue reading by half the supply voltage.
You've forgotten to offset the analogue reading by half the supply voltage.
About what I want is
I am not good at maths but I thought If the code gives me a value that tells me the difference in acceleration because of some motion .So if i shake my accelerometer it shows a good deflection in the diff variable.
I might seem to be stupid but I am trying to understand how accelerometer work.
The accelerometer measures acceleration, but the rest (zero acceleration) reading for each axis is offset by half the supply voltage to ensure only positive output voltages.
If we assume that the supply for the accelerometer is 3.3V, and the analogue reference is 5V, then you need to subtract about (3.3/5 * 1024) / 2 = 338 from each reading.