Sharp GP2Y0A710K0F IR sensor behaving strangely

I have just purchased a new Sharp GP2Y0A710K0F IR sensor online. As a sanity check, I wrote this simple code to check if the sensor is working correctly. The code is expected to print output voltage from the sensor, which is based on the distance

    int sensorpin = A5;     
    int val = 0;    

    void setup()
    void loop()
    val = analogRead(sensorpin);

Now the output is quite strange. The output values start from zero and keep on increasing until they reach 1023, and then gradually decrease down to zero and this keeps on happening, even if something is kept in front of the sensor.

Is my sensor a faulty one? or is it supposed to give out similar outputs. If it has to, how do I convert these values to meter or centimeters.

The product description on the manufacturer's website said that it has a 3 pin interface, however it has a 5 pin one, the wires being Red, Black, Yellow, White, Green if seen from the left side. I guessed from the datasheet that Red and Black are for power and Yellow for signal output and hence I have connected only these 3 wires. The Green and White wires are unconnected. Also, pin numbers aren't marked.

Datasheet: Microsoft OneDrive - Access files anywhere. Create docs with free Office Online.

// you should map the sensor from 0 t 1023 to 0 to 255
//here's the code
int sens = 0;
int sensp = 0;
void setup() {
void loop() {
sens = analogRead(A0); //let the sensor be coonected there
sensp = map(sens, 0,1023, 0,255);

pin 1 and 5 => GND
pin 2 and 3 => 5V
pin 4 => analog input

Test ?
Ground 1 and 5, power to pin 3
Try reading the "uncertain" one.. 2 / 4

another look at the datasheet: pin 1 nearest edge

@Zahran_Sajid Can you please explain the reason why you are mapping 0 to 1023 to 0 to 255 ?
Thanks in advance.