How do I get the boolean code, true or false, for this sensor?

Hello! I'll try to be brief.

I'm basically building a tool to help me record some cool time-lapses of my 3D prints, where my iPhone will be sitting in front of my printer taking shots every layer. I'll do it using an Arduino where I already figured out how the iPhone will take the pictures and I want to use a spare induction sensor from an old printer to detect whenever the extruder comes close, so that it sends the signal to the iPhone to take a picture at the layer change.

I already have the sensor working, just don't know how to extract the boolean (TRUE or FALSE) for coding, this is all I need to get everything working.

If the sensor output is connected to digital pin, say 6, then just if(digitalRead(6)==0) then a else b.

That circuit (the 2*10k resistors) won't work with the NPN (open collector) sensor you have.

If you're sure the sensor is NPN, then connect the output directly to a digital pin, set to INPUT_PULLUP.

The pin will be normally LOW, and HIGH when metal is near.
Leo..

dougp:
If the sensor output is connected to digital pin, say 6, then just if(digitalRead(6)==0) then a else b.

"digitalRead", that's exactly what I was looking for. Yes, I'm beginner. Thank youu!

Hello, I got this 12v sensor and I want to connect it to my Arduino. But I actually seem to have damaged my board using it cause I didn't know it was 12v, so I want to reduce it to 5V using a resistor divider, but how should I connect the wires?

I'm assuming Vin is the +12v, Vout the -12v and the signal wire keeps the same, is that right?

Sounds plausible, but have you figured the resistor values and you better first explain just what that sensor is?

you have to give more information about that sensor !

what is it ?

it's not just that it's "12V" but that it's "-12V" as well.

i don't think a voltage divider will solve your problem.

It's an induction sensor for metal detection. I read another topic about reducing from 12v to 5v and they were saying to use R1 as a 10k and R2 as a 15k for stable voltages. I just wasn't sure if leaving the signal wire unattended was right, since I'll be buying another Arduino today and I don't want to burn it, LOL

The whole idea btw is to create a time lapse tool to register my 3D prints in a fancy way, where the sensor will detect the extruder every layer change and send a signal to my iPhone to take a picture. :slight_smile:

BabyGeezer:
you have to give more information about that sensor !

what is it ?

it's not just that it's "12V" but that it's "-12V" as well.

i don't think a voltage divider will solve your problem.

I got these info about it, it's from an old 3D printer I had

forum.arduino.cc/index.php?topic=584786.0

Just to make absolutely sure, put a diode with cathode to your sensor and anode to the Arduino input pin. If it is not sufficiently reliable, add an extra pull-up of 4k7 or so from the Arduino input to 5 V (not 12!).

Let me check I have understood correctly, the brown wire connects to +12VDC, the blue wire to -12VDC and the output is the open collector on the black wire. Assuming this is correct then the output needs a load resistor between black and brown and the voltage can, in theory, vary between about +12V and -12V, so it's not a 12V sensor it's one that needs 24V. That being the case I suggest this sensor isn't what you need.

How about either an optical sensor or a Hall effect switch and a small magnet?

I've not seen many sensors require + 12V / -12V.

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

If this is the case then all you need to do is:

  1. Connect the blue to the arduino GND** and the 12V common (return, ground etc)****

  2. Connect the black to any arduino digital input, enable the internal pullup on that input. I would add a 1k in series for saftety in case the two "grounds" are not exactly the same.
    If you want to be really safe you could but a diode (1N4148) in series with the black wire. The banded end (cathode) would connect to the sensor side of the black wire. The other end (anode) would go in series with the 1k.

  3. Connect the brown to +12V

** I use ground here because the boards are marked GND.


So lets talk +12V and -12V.

My car battery is a 12V battery.
The connection posts are marked "+" and "-"
This means the "+" post is 12V higher that the "-" post.
The "-" post is connected to the car frame. This becomes the created circuit "common" (sometimes called the return).

The "common" is often called "ground". While folks understand what ground means in this context it is not a good term to use, because the word "ground" suggests an absolute 0 voltage which is not always the case.

Threads merged.

JohnRob:
My car battery is a 12V battery.
The connection posts are marked "+" and "-"
This means the "+" post is 12V higher that the "-" post.

I too was wondering if the -12V in OP's pix actually meant one side was 24V below the other, or if it just meant the ground side (0V) of a 12V system.

But this:

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

... might not be wise, because it might actually be a 24V thing?

But then why have a +12 V and -12V label with no 3rd wire called ground as the midway between then, for a pair of +ve and -ve voltages?. Might as well label then +24V and 0V or ground in that case.

So while it might be likely that this is a 12V thing and -12V is actually ground zero for the 12V side, it's by no means a cert.

@ardy_guy

... 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.

Thanks

John

JohnRob:
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).

:wink:

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.

ArturDB,
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.

Hi,
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.. :slight_smile: