my code is faulty

Hello cgdsdkc

One place to start looking is this part of your code, and what values k takes on as the program runs.

           pos1Array[k]=pos1;
           pos2Array[k]=pos2;
           sensorArray[k]=sensorVal; 
           k=k+1;

In particular, each time you go round the main loop(), what value do you want k to start at? Where in your program are you setting it to this value? How do you make sure that k will not get bigger than the size of the arrays?

Regards

Ray