The Ardunio gets its power from a 9V power source through the Vin pin.
When i measure the voltage between the two yellow marked locations, I get -0,043 V when there is no object in front of the sensor but when the sensor is triggered, I get +8.13 V.
From my understanding, I should get 5V when the sensor is triggered. I do not understand where the 8.13 V come from.
So without the Arduino and the 5 V supply, I get 12,35 V between the black sensor connector and GND when there is an object in front of the sensor. This would indicate it is a PNP instead of a NPN right?
I am new to those sensors, so I apologize if my questions are dumb.
The common emitter configuration would mean that I am not able to separate the 12v from the sensor from the 5v for the Arduino, correct? Could you explain how I would need to wire the sensor for that configuration?
The reason I chose an NPN NC sensor was because I thought that way I could separate the two voltages without letting the 12 V fry my Arduino. I thought an NPN sensor had the advantage that I would not need an opto coupler. For me it looks like this sensor behaves more like what I would expect from an PNP NO sensor.
That is the right basic idea, but you need an open collector version to protect the Arduino. The best way to completely isolate that sensor and its power supply from the Arduino is an optocoupler, for example:
R2 is not needed, if you use pinMode(input_pin, INPUT_PULLUP);
and the grounds shown in the schematic above do not need to be connected together.
Thanks for the explaining, I might just get another sensor that is open collector. It seems like that would make it much simpler.
The reason I got that sensor was because I wanted to keep it as simple as possible without the need to use an opto coupler.
How can you tell wether a sensor is open collector if that isn’t stated explicitly in the description?
If the details are not made perfectly clear on the sales page, do not buy the sensor.
Most sensors of that type come in a variety of configurations, and the sensor data sheet will connect the configuration with a model number (one or more characters in an option field of the model number).
Post the complete model number of your sensor and forum members can check.