Can someone explain me how this sensor works? I can't make a function for the arduino that returns the distrance that the sensor gets but it's totally wrong and i can't understand the charts on the datasheet
In the data sheet is a graph showing distance against reading. You will notice it is only correct over a certain range. If you are outside this range, that is too close the reading will be totally wrong.
You can only use these sensors if your range is greater than the minimum distance. That distance is where the peak is on the graph.