# How to connect an industrial 24V sensor to a 3.3V input Raspberry Pi pin?

Background

I want to read how efficient an industrial manufacturing line is without tampering with the PLC code. The simplest solution I can think of is using a Raspberry Pi, thus creating an isolated OEE information gatherer. I know this is not meant for industrial environments, but it is only for proof of concept.

Question

I have a 24V SICK WTE11-2P2432 industrial sensor with the following connection diagram. Datasheet here.

I need to connect the output from pin 4 to a Raspberry Pi 3 Model B. Given that I am using the standard I/O pins for the Raspberry Pi, what is the best way to do so? Maximum voltage on an input GPIO pin is 3.3V.

I am trying to detect 1 part per second.

I am trying to avoid voltage dividers and building PCB's.

• The datasheet of the sensor is unclear regarding the electrical specifications. There's a small diagram drawn on the sensor itself which is also of little help. I would just connect 24 V to it and measure the voltages. Sep 4, 2018 at 8:18
• What have you got against voltage dividers? Sep 4, 2018 at 8:24
• What kind of switching speeds are we talking about here?
– pipe
Sep 4, 2018 at 12:27
• Btw, you're very quick when accepting an answer. Unless you're 100% certain that this is the best and only solution you're interested in, I suggest to wait at least 24 hours so that everyone around the world has a chance to offer their inputs.
– pipe
Sep 4, 2018 at 12:30
• I agree, why not a voltage divider? Using E48 series resistors, a 78.7K + a 10.5K resistor will give you ~3.2V at the divide (plenty to register a logic high), and if I'm doing my math correctly will only allow ~0.3mA to the divide. Sep 4, 2018 at 17:51

I am trying to avoid voltage dividers and building PCB's.

Then, I would go for a relay and a 3.3V power supply, as shown in the schematic below.

simulate this circuit – Schematic created using CircuitLab

By doing so, you are effectively getting 3.3V to your input pin only when the sensor output goes to high.

Now that you mentioned that this is an industrial setting, I would use an industrial relay, like for example, this one.

Note: The schematic is intended only to give a general overview of what needs to be done. If you are looking to limit the power consumption a MOSFET or an opto-isolater would be better, as suggested by ratchet freak. Such solutions also allow for faster switching.

However, even though other solutions provide faster switching capabilities than the proposed circuitry, I have seen Omron relays being used to detect moving parts on some of the fastest assembly lines in Europe producing over 2000 parts per minute.

As the other answer by Michael suggests, you may need to:

provide necessary signal conditioning external to your MCU board.

• A opto-isolator or mosfet would switch faster though and consume less power Sep 4, 2018 at 9:52
• True, I tried to give the OP what he was asking for in terms of simplicity, since he did not mention power consumption to be an issue. I will edit to make it clearer.
– rrz0
Sep 4, 2018 at 9:58
• It's an industrial sensor, not an industrial environment. Raspberries are unfit for industrial environments.
– Mast
Sep 4, 2018 at 11:52
• Pins 1 and 17 on the GPIO connector can provide the necessary 3.3V source, no need for an external source there. The 24V can't be drawn from the RPi, of course. Sep 4, 2018 at 13:05
• @DoktorJ, you are right, but since the OP did not mention switching capabilities I went along with the simplest and most effective solution. I did mention that other components provide faster switching times. I have seen Omron relays being used to detect moving parts on some of the fastest assembly lines in Europe producing over 2000 ppm.
– rrz0
Sep 4, 2018 at 18:13

From the online data sheet for your sensor the outputs are described as follows:

A PNP output from a sensor means that the output will have an active switch element that will pull the output signal toward the supply voltage when in the "high" logic state. When in the other state the active switch output will shut off and the output will either become open circuit or will be passively pulled down via some internal resistance. (In my experience it is typical that the output will not have any internal pulldown resistance at all and it is up to the user application to supply any such required circuitry).

You will require some interface circuitry to be able to connect this to your MCU inputs. There are a number of options for doing so:

1. Two resistor voltage divider from output to GND to divide the active high output of the sensor from 22V -> 24V down to ~ 3V.
2. Use an NPN transistor with a resistor from its base to the sensor output. Emitter connected to GND and collector to MCU input and pullup resistor to MCU supply voltage.
3. One resistor from sensor output to the anode input of an optocoupler. Cathode of optocoupler to GND.

Note that the MCU board that you are using is not one directly designed for use in an industrial type application and as such does not come with inputs conditioned for typical industrial device outputs. If you were using a commercial device such as a small PLC (programmable logic controller) it would have inputs that could directly interface to the sensor output with just wires. In your case you will have to provide the necessary signal conditioning external to your MCU board. In addition to the signal interface options I described above your circuitry will also have to deal with protection of the MCU inputs against ESD and possible common mode voltage difference in GND levels between MCU location and sensor location if they are wired far apart.