Using signal from 12VDC sensor for 5VDC arduino

Hello everyone,

I have a question regarding an inductive sensor of the type "LJ12A3-4-Z/BY", with an input range of 6-36 volts DC.

My build only has a 5VDC and 12VDC power supply, so I figured I'd most easily power to sensor from the 12V supply. However this causes the returning signal to be 12V as well, and the arduino that is supposed to read the signal runs at 5V, which I guess will cause problems.

I made a small schematic drawing of a part of the circuit for easier understanding.

My guess is that I will need something to reduce the voltage from 12V to 5V. I already tried making a voltage divider using resistors, but that arduino died from either that or something else, so I'd like to ask for advice before headlessly trying that again.

Thank you guys in advance, I hope I find the help I'm seeking.

Was your voltage divider configured as per your drawing or similar to what is shown here?

Please post full information on each sensor - that means the datasheet or product page link.

Unless you explain in full detail what you did, we won't be able to figure anything out - details are everything.

Hello ninora,

Yes, this is exactly the way I did it, except that I used different resistor values since I needed to go from 12V to 5V.

I used the formula:
Vout = Vin * (R2 / (R1 + R2))

And isolated R2 from it, assuming that R1 was 10 kohm:
5V = 12V * (R2 / (10kohm + R2)), thus resulting in R2 = 7123 ohms.

Then I added a 10kohm resistor to ground and a wire to the input channel on the Vout side.

Sad that you got the wrong sensor. The LJ12A3-4-Z/BX interfaces directly with open-collector to logic.

I know some people don't recommend this connection method.

You can get one schottky diode, connect the cathode to the output of the sensor, connect the anode to the input of the Arduino, and set it to INPUT_PULLUP like a normal push button to make it work.

And it does not need to be a Schottky.

Yep, the Vf of a common silicon diode is low enough for a 5V Arduino to recognize Low. :wink:

Hi, a low cost 4.7v zener diode and resistor (say 1k) could meet your need. That will cap the 12v from the sensor to a max of 4.7v into the arduino. The resistor value should be big enough to prevent the zener diode hitting it's power limit. if the zener is rated at 100mw then the max current will be max 20mA. to drop the 7V a 1K resistor will be fine.
Connect the 1K to the 12v signal, the zener (in reverse polarity ) to the other end of the resistor and GND, then tap of the 4.7V signal off the zener/diode connection. This might cost you as much as 3 pennies.

Product description

DIYmall LJ12A3-4-Z/BY Proximity Switch DC 10-30V PNP 3-wire 300MA 4mm Cylindrical Inductive Sensor Approach Positive Voltage Regulator L7805CV for 3D Printer Ramps
Proximity Switch Description:
Product Name: Proximity Switch
Model: LJ12A3-4-Z / BX
Voltage: 10-30V DC
Current: 300MA
Sensing distance: 4mm
Output Type: PNPnormally open
Cable length: about 140cm
L7805CV Description:
Output voltage: 4.75-5.25V
Maximum input voltage: 35V
Quiescent Current: 4.2-8mA
Output voltage noise: 40uV
Ripple rejection ratio: 78dB
Output resistance: 17mΩ
Output voltage temperature coefficient -1.1mV /degree
Package Included:
1 X Proximity Switch
2 X Gasket
2 X Screws
1 X L7805CV

As stated, since it is open collector, the output voltage is whatever you pull it up to.
You could simply use a 4,7k pullup to 5V and get your arduino input signal directly
from the sensor output pin. It cannot possibly be 12V if it is pulled up to 5.
(or, as shown, use Input Pullup)
pinMode Input Pullup

Hi, @raschemmel

BUT it is PNP.
The output is switching to sensor supply, NOT gnd.

@Ritmann
The solution in post#6 should work with a PULLDOWN resistor on the sensor output.

Post #2 also has a good solution.

Tom... :smiley: :+1: :coffee: :australia:

That is why it is the wrong choice of sensor as I mentioned.

Also why this will not work

unless you provide some sort of pull-down load to the sensor.

Hi, @Paul_B

I agree.. @chrisknightley needs a pulldown on the sensor output.

Tom... :smiley: :+1: :coffee: :australia:

@Paul_B @TomGeorge

I thought the OP sensor had NPN output.

Voltage divider or zener approach is fine for if PNP
If have an opto-coupler like the PC817, it's fine to use it.

By the way, this type of sensor has a 10kΩ pull-down resistor inside the sensor.
(The NPN output type is also pull-up to VDD via 10kΩ, so can't be directly interfaced...)
However, pulling the INPUT_PULLUP to LOW is not possible with that pull-down, so in the case of PNP the circuit I presented doesn't work.