using sensors >5v input/output (industrial sensors)

I am trying to tie an uno in with an industrial photo electric sensor. I was advised by the vendor to use a PNP setup (sinking). NPN seems simpler, though - but i can't get any tests to prove anything in that configuration using my multimeter.

Sensor: http://www.automationdirect.com/static/specs/peminirectqm.pdf

I tested it using a voltmeter with the following pinout:
Black --> Signal
Blue -> neutral
Brown-> Supply voltage

Supply is a wall-wart (but i have a place i can add capacitors...) for 12v outputting 15v.

I tested the circuit with the black probe on the signal and the red probe on the 15v supply. Output reads 0 or 15v.

I think that for the final circuit i will add a 12v regulator and capacitors just to make a more consistent input and therefore output power - rather than relying on the wart.

Now, i know i can reduce the voltage down using a divider, but what i dont know is how/where to measure the voltage. In my head i can't replicate how i am using the voltmeter. I also am not totally clear on what ratio to use to make the divider. Im also not sure if i should use an input_pullup. Im sure that at several points i have had more confused than less.

AFAIK NPN is sinking (switching to ground), and PNP is sourcing.

NPN would have been easier. No extra parts needed.
Just enabe the internal pullup, nothing else.

Since you have a sourcing PNP sensor (outputting voltage), you have to use a 2-resistor voltage divider.
If you use a 15volt supply, the resistor ratio should be 1:2 for a 5volt Arduino.
e.g. 10k to ground and 20k (2x10k in series) to the sensor.
No pullup. Just read the digital pin.
Leo..

Im wondering now if i misunderstood him because from what i was reading NPN would be sinking...

Anyway, if i use NPN, then it would just be hot,neutral,signal. I tried that, using an internal_pullup, and it didnt seem able to read the sensor. I also wasn't able to understand how the arduino would know when the signal went high or low without being able to measure against anything?

Looking at the data sheet it does seem like it can be wired either way?

I'll experiment again this weekend with both configuration - i have an arduino with a bad digital pin anyway, i think...

A NPN sensor has a transistor that switches an externally supplied voltage/load to ground.

If you enable the internal pullup resistors on a pin, the pin becomes default "HIGH".
The NPN transistor in the sensor switches the pin to ground (LOW) when the sensor is activated.
Leo..

So i've tried a few times now to get this to work... so far, no luck. The current state of my setup is attached as a PNG (How do i embed?).

I tested the regulator on its own, and then the output on its own (to make sure it would be less than 5 (4.86v)) before trying the arduino. i tried both pullup and without pullup. I did not try an external pullup resistor.

I've also tried combining the two grounds from the sensors power and the usb, and while that settles out the monitor in non pullup mode, it does not register a high or low - but does register a change between a connected ground or not... (in pullup - it is a solid LOW to HIGH change. in non pullup, it just goes back to garbage).

Thanks for the help thus far

void setup() {
pinMode (5, INPUT);
Serial.begin (115200);
}

void loop() {
if ((digitalRead (5)) == LOW)
{
  Serial.println ("LOW");
}
if ((digitalRead(5)) == HIGH)
{
  Serial.println ("      HIGH");
}

}

(How do i embed?).

Post it somewhere and add a link using the "Insert a link" button (next to the x2 button).
I prefer attached files, no worries about spam/virus/worms whatever laden picture hosting sites, most of which are blocked at work.

Did you use the NPN or the PNP sensor in post#5

Why the 12volt supply.
Sensor (NPN) will work between 10 and 30volt.
Leo..

So i definitely messed myself up a little thinking these could be wired either way (a big part of my confusion - since i have seen sensors that can go either way). Looking a bit more discerningly, this is an NPN sensor. Doh...

12v supply was to deal with two different power supplies between my test setup and what is still at the plant.

edit:

so if im reading this right: https://cdn.sparkfun.com/assets/f/1/4/a/b/511568b7ce395f613f000004.jpg

then i need to connect:

VCC of Sensor --> R1
R1 = 40k --> Digital Pin (INPUT_PULLUP - R2 = 20k)
Signal Sensor --> R1 & GND

I want to ask before i even try this... I dont want to kill a sensor and an arduino!

Read the first lines.!!!
Test program without sensor by shorting/tapping pin5 to ground.
Leo..

// sinking NPN sensor only!!!
// connecting a sourcing PNP sensor to a pin will kill the Arduino.
// measure the sensor output first with a voltmeter
// there should be _no_ voltage on the sensor output in both states
// Arduino provides the switch voltage for an NPN sensor
// no other parts needed

int NPNsensor = 5; // pin the sensor output is connected to

void setup() {
  pinMode (NPNsensor, INPUT_PULLUP); // enable internal pullup resistor
  Serial.begin (115200); // set monitor to this speed
}

void loop() {
  if (!digitalRead(NPNsensor)) { // if the pin is LOW
    // do something here
    Serial.println ("ON");
  }
  else {
    // do something else here
    Serial.println ("OFF");
  }
}

i tried that earlier and i couldn't get it to register.

Today i tried using a 4.7k resistor from 5v on the arduino to signal/input. This got it working with an INPUT_PULLUP and connecting the two power source grounds.

So, one side of the resistor has the 5v, and the otherside has 5v. Unfortunately it doesnt sink all the way to 0, but, i think im ok with that. It sinks 1.4v, which is below the 3.2v that the arduino needs to register. HIGH = 4.87v, LOW = 1.4.

Something fishy going on.
You should not need any resistor with that sketch and the NPN sensor.
Maybe you have laready damaged pin5.
Try another one.

Ofcourse Arduino ground has to be connected to sensor ground.
Leo..