finding speed of vehicle using MPU6050

Here is my code which measures speed along “y” axis (where y-axis is aligned along the direction of vehicle).
offsets are already found and I got :ax=-1143;ay=1843;az=1339

// I2Cdev and MPU6050 must be installed as libraries
#include "I2Cdev.h"
#include "MPU6050.h"
#include "Wire.h"
#include <XBee.h>
#include <Wire.h>
XBee xbee = XBee();
ZBRxResponse zbRx = ZBRxResponse();
XBeeAddress64 addr64 = XBeeAddress64(0x00000000,0x00000000);
///////////////////////////////////   CONFIGURATION   /////////////////////////////
//Change this 3 variables if you want to fine tune the skecth to your needs.
int buffersize=1000;     //Amount of readings used to average, make it higher to get more precision but sketch will be slower  (default:1000)
int acel_deadzone=8;     //Acelerometer error allowed, make it lower to get more precision, but sketch may not converge  (default:8)
int giro_deadzone=1;     //Giro error allowed, make it lower to get more precision, but sketch may not converge  (default:1)

// default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
//MPU6050 accelgyro;
MPU6050 accelgyro(0x68); // <-- use for AD0 high

int16_t ax, ay, az,gx, gy, gz;

int mean_ax,mean_ay,mean_az,mean_gx,mean_gy,mean_gz,state=0;
int ax_offset,ay_offset,az_offset,gx_offset,gy_offset,gz_offset;

///////////////////////////////////   SETUP   ////////////////////////////////////
void setup() {
  // join I2C bus (I2Cdev library doesn't do this automatically)
  Wire.begin();
  // COMMENT NEXT LINE IF YOU ARE USING ARDUINO DUE
  TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz). Leonardo measured 250kHz.

  // initialize serial communication
  Serial.begin(9600);

  // initialize device
  accelgyro.initialize();

 
  delay(1000);
  //  offsets
  accelgyro.setXAccelOffset(-1143);
  accelgyro.setYAccelOffset(1843);
  accelgyro.setZAccelOffset(1339);
}
unsigned long time1=0,time2=0;
///////////////////////////////////   LOOP   ////////////////////////////////////
void loop() 
{
    time1=millis();
     meansensors();   //get accelerometers and gyro values
 //    Serial.println(mean_ax);   //x-axis accelerometer value
    float accel=mean_ay/16384.0f; //dividing by sensistivity as per datasheet
  time2=millis();
long int  timed=time2-time1;
     float velocity1 =timed*accel*0.001*3.6;  //in kmph 3.6 is the constant from m/s  //using 16384.0
    Serial.println(velocity1); 
    delay(1000);
}

///////////////////////////////////   FUNCTIONS   ////////////////////////////////////
void meansensors()
{
  long i=0,buff_ax=0,buff_ay=0,buff_az=0,buff_gx=0,buff_gy=0,buff_gz=0;
 while (i<(buffersize+101)){
    // read raw accel/gyro measurements from device
    accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    
    if (i>100 && i<=(buffersize+100)){ //First 100 measures are discarded
      buff_ax=buff_ax+ax;
      buff_ay=buff_ay+ay;
      buff_az=buff_az+az;
      buff_gx=buff_gx+gx;
      buff_gy=buff_gy+gy;
      buff_gz=buff_gz+gz;
    }
    if (i==(buffersize+100)){
      mean_ax=buff_ax/buffersize;
      mean_ay=buff_ay/buffersize;
      mean_az=buff_az/buffersize;
      mean_gx=buff_gx/buffersize;
      mean_gy=buff_gy/buffersize;
      mean_gz=buff_gz/buffersize;
    }
    i++;
    delay(2); //Needed so we don't get repeated measures
  }
  state=0;
}

So the problem is when not riding no matter it’s giving 0.00,0.15,0.17…but less than 1 kmph but,though if we ride at 20kmph(accelerating not constant speed) it’s giving just 10kmoh sometimes 11.2,3.14,5etc…
but,never went beyond 15kmph… Is my code correct?

v = old speed + at. You will never get this correct with this accelerometer sampling once/sec. A GPS can do this much better