Go Down

Topic: How do I get the boolean code, true or false, for this sensor? (Read 1 time) previous topic - next topic



... might not be wise, because it might actually be a 24V thing?
Your correct, my purpose was to state the assumptions to my comments.  Expecting if my assumption is not valid then my comment is not valid.

I need to come up with a better way of stating this.


Please do not PM me with thread based messages.  If your thoughts are worth responding,  the group should benefit from your insight.


Quote from: JohnRob link=msg=3982086
I need to come up with a better way of stating this.

I would assume wonder if the reference to -12V is really the 12V common (aka 12V return and unfortunately ground).

It's certainly not clear from the docs the OP gave though, is it?


Looking at the LJ18A3-8-Z/BX Datasheet, reveals that the sensor has has +V (brown), 0V (blue) and an output pin (black).
The supply voltage range is 6V -36V.

It is the fact that ArturDB, the  O.P. has labeled the 0V connection as -12V that has caused some confusion.


The output is open collector, that is it is like a switch connected to 0V that is either open or closed.
The output does not have 12V on it, unless you specifically connect it to 12V through your resistor network or some other means.

You can power the sensor from 12V, and connect the output directly to a n Arduino digital input, with the internal pullup resistor selected.

Use the pinMode() function with the INPUT_PULLUP as the argument
Then use digitalRead() to read the output of the sensor.
No other resistors are necessary

The output will be pulled low (by the sensor) when the target is sensed, and pulled high (by the pullup resistor) when the target moves away.  

You need to ensure that the 0V connection of the 12V power supply, the sensor 0V connection and the Arduino GND (=0V) pin are all connected together.


The choice of colours for that sensor are  very misleading.
An industry standard is    RED = Positive Supply, BLUE = GND Supply,  BLACK = Negative Supply,   WHITE or YELLOW = Signal.

In this case see below.

And as suggested, use a pullup resistor.

Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....


Dec 15, 2018, 12:36 pm Last Edit: Dec 16, 2018, 02:43 am by Paul__B Reason: Link fixed.

Oh, very nice colour!  :smiley-lol:

Too much complete nonsense about semantics.

We have a schematic of the device.  It has three wires.  Two of them are for power; you can call them what you like, I for one do not care but you need to provide between 6 and 36 V to them.  There is an open-collector driver connected between the negative wire and the output wire.

So the negative wire connects to negative of the power source, say 12 V, and the positive to the positive of that power source.  That is all that is needed to do (to supply power).  That power source will also have its negative connected to the Arduino negative or "GND".  The output wire should be connected to an Arduino input but to be absolutely safe, you do so via a diode with cathode to the sensor and anode to the Arduino input.  You may or may not need a pull-up on the Arduino input to its own Vcc (5 V) given that you will use INPUT_PULLUP in pinMode to enable an effective 45k pull-up.

Now, the diode means that the input can only be pulled down and in this configuration, there is no more negative point in the circuit than "ground" so it can never be pulled down below ground.  On the other hand, the diode prevents any positive voltage being conveyed to the Arduino, so it is totally safe.

Go Up