Using Accelerometer

I have an elgoo arduino and adxl345 accelerometer. I have a project of measuring a horizontal distance of 2-6 foot using accelerometer . It can be done by calculating acceleration and doing twice the integration. But I donot know how to do its programming.

It can’t be done that simply… integrating twice the acceleration will amplify the error and your result will be very approximative

Integrating over time is the sum of sampling accceleration say Ax, and assuming its constant for a short while, say deltaT (in ideal conditions)

If you know the previous speed Sx0 and previous position X0 then your next position is
X1 = 1/2Ax deltaT2 + Sx0 deltaT + X0
and new speed SX1 = Ax deltaT + Sx0
Then repeat (deltaT is the time between two consecutive sampling and can vary depending what your code does, so remember the last time if was before measuring and new time for the next meausre and the difference gives you deltaT)