I'm trying to connect this proximity sensor GX-H8A to interface with my microcontroller STM32L4R5. I just want to make sure if my design will work and will not damage the micro.

enter image description here

I'm planning to connect the Brown wire to 24VDC, Blue wire to Ground, and the Black wire to the input signal on my microcontroller, and a 3.3V pull up with a 10K resistor on the Black wire as well. So when the sensor detects the object, it will get pulled to ground and the micro will receive a 0 signal.

Is this configuration and theory correct? I'm scared that somehow the 24V will got connected to the microcontroller and damage it, and I'm not sure why they connected the Output node with the 24V node in the circuit diagram.


  • 2
    \$\begingroup\$ The schematic they show is, effectively, just an open-collector output. As long as the +24 V power supply safely shares the same ground with your +3.3 V supply (they have a common reference point), then you probably can get away with the use of a "pull up" resistor to +3.3 V. You could at least try it out on a protoboard and use a voltmeter to be sure before hooking it up to your MCU. You could, however, add more components if you wanted and do things still safer against fumble-fingered screwdrivers, I suppose, with an opto. But it's probably not necessary. \$\endgroup\$
    – jonk
    Apr 28, 2021 at 19:24

2 Answers 2


The GX-H8A has NPN type open-collector output, so it should work exactly as you described.

The 10k pull-up can make the signal rise quite slowly, but it should not matter much, I just mention it so you can change to stronger pull-up if it is a problem. If the rise time is not important and the internal weak pull-up of the MCU is enough, you can also try without external pull-up.


Your plan sounds good to me. The datasheet circuit is drawn like that because it assumes that whatever you're switching with the NPN output is also powered by the same 12-24V input source. This would be the case if the load were a relay coil, for instance. But you don't have to do that, and tying the output to an MCU pin with a pull-up resistor is just fine.

As long as the MCU and the sensor are connected to a common ground, there should be no danger of the 24V reaching the MCU.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.