Analog Inductive sensor working as digital

Hello!!!

I'm doing a small project with my arduino mega, just trying to fix a problem, here we go:

I bought THIS INDUCTIVE SENSOR I wired to my arduino (Black-DATA Blue-GND Bronw-Vcc) and then just changed the reading to a %, the problem is that I'm getting 0% or 80% nothing in beetwen, I wanted to check diferent intensities for magnets but don't know how to get the real analog output from the sensor.

Any ideas? thanks!!!

CodE:

float metal_SI;
int reading_SI;
int metalPin_SI = 8;

void loop.....

reading_SI = analogRead(metalPin_SI);
metal_SI = (float)reading_SI*100/1024.0;
if(reading_SI<100){i++;
Serial.print("DETECTED ");

With this code the sensor works perfect but only ON/OFF readings...

I'm pretty sure that code does not compile... Was it that hard to copy the real code?

But I'm sorry to inform you, you bought the wrong sensor... It just detects metal and gives you a digital signal if it does. So no distance, just a yes or no.

Its not an analog sensor - these inductive 'sensors' have logic output, either PNP or NPN open collector
typically.

inductive proximity switches have a distance spec on them such as 2mm at which point it switches state better suited as end stops and adjusted by physically adjusting to one distance. If you wish to measure distance use an ultrasonic or laser type sensors

Yea agree these are made to detect metal door or arm in lot of machinery or excavator ect