Using a NPN Proximity sensor with an arduino uno

I am following this tutorial to make a automatic "bed levling" addition to my 3dprinter.
I have everything hooked up correctly (as shown in that video, around Monoprice Maker Select | Auto Bed Leveling w Stock Board - YouTube )

The script code is:

int sensorVal;

void setup() {
  // put your setup code here, to run once:
  pinMode(10, INPUT_PULLUP);
  pinMode(2, INPUT);
  pinMode(3, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  
  // read sensor's current state
  sensorVal = digitalRead(10);
  Serial.println(sensorVal);
  if(sensorVal == LOW)
  { 
    digitalWrite(3, digitalRead(2));
  } else {
    digitalWrite(3, LOW);
  }
  sensorVal = LOW;
}

I modified it to show some debugging info.

The sensor I am using is a NPN 6-36v 300ma output.

The sensor is underpowered, I know, but it has a light that does light up when metal gets close.

The problem seems to be the arduino never detects this change and the output in the serial monitor is always 1. (its a normally open inductive sensor).

I know the script works because if I ground the sensor pin (pin in 10) the script is triggered properly so I think this must be the issue.

Any input as what might be going wrong or what might improve the problem?

I'm not into chasing down videos. Do you have a wiring diagram maybe, and a datasheet for the sensor? One thing for sure, if you try to pump 300mA into Arduino, Arduino won't be happy (probably you not also).

DKWatson:
I'm not into chasing down videos. Do you have a wiring diagram maybe, and a datasheet for the sensor? One thing for sure, if you try to pump 300mA into Arduino, Arduino won't be happy (probably you not also).

Sensor is GLE2016 Approach Sensor Inductive Proximity Switch DC 6-36V Normal Open Type (4mm) https://www.amazon.com/dp/B01MXLH7TF/ref=cm_sw_r_cp_apa_JZzABb7864504

If the Uno is powered via the power jack (not the USB) you could connect the brown sensor wire to the Vin pin to get more with in the operating voltage range. The sensor output is NPN open collector so it should not be a risk to the Uno.

You need to use INPUT_PULLUP, or an external pullup resistor to Arduino Vcc, in order to read an open collector NPN output. Be sure to connect the grounds.

6v6gt:
If the Uno is powered via the power jack (not the USB) you could connect the brown sensor wire to the Vin pin to get more with in the operating voltage range. The sensor output is NPN open collector so it should not be a risk to the Uno.

I hooked the sensor up to a 12v battery and it still didn't trigger

jremington:
You need to use INPUT_PULLUP, or an external pullup resistor to Arduino Vcc, in order to read an open collector NPN output. Be sure to connect the grounds.

Pin 10 is set to input pullup

dmratcliffe:
I hooked the sensor up to a 12v battery and it still didn't trigger

and did you connect the ground of the 12v battery to the ground on the sensor AND the Arduino?
They need to have a common ground.

Can you measure the voltage between the 0 volt rail and pin 10 when the sensor detects something ?
It should be below 1.5 volts on a 5v device.

If the detector performs poorly and does not bring the pin down far enough to be recognised as a LOW, there is a number of things you can try:

  1. move the detector to an interrupt pin, again with the internal pullup resistor active, and detect a falling edge. You'll probably need some sort of de-bouncing.

  2. move the detector to an analog pin with an external pullup resistor. Look for a significant drop away from 1023.

1 requires no additional hardware. 2 needs a 10K resistor. There are probably many other tricks as well.