Arduino Forum

Using Arduino => General Electronics => Topic started by: ArturDB on Dec 12, 2018, 08:47 pm

Title: How do I get the boolean code, true or false, for this sensor?
Post by: ArturDB on Dec 12, 2018, 08:47 pm
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.

(https://scontent.ffln1-1.fna.fbcdn.net/v/t1.0-9/48328471_2250105461668651_1116703003177385984_n.jpg?_nc_cat=107&_nc_ht=scontent.ffln1-1.fna&oh=7a4cf93d4479d33948a82c8cfa7a692a&oe=5C94F4E7)

(http://thingiverse-production-new.s3.amazonaws.com/renders/e9/6c/1e/9f/1d/43777b5156cdcda79782868723c2a886_preview_featured.jpg)

(https://opinionbypen.com/wp-content/uploads/2017/07/PINDA-A.jpg)
Title: Re: How do I get the boolean code, true or false, for this sensor?
Post by: dougp on Dec 12, 2018, 10:33 pm
If the sensor output is connected to digital pin, say 6, then just if(digitalRead(6)==0) then a else b.
Title: Re: How do I get the boolean code, true or false, for this sensor?
Post by: Wawa on Dec 12, 2018, 10:43 pm
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..
Title: Re: How do I get the boolean code, true or false, for this sensor?
Post by: ArturDB on Dec 13, 2018, 12:00 am
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!
Title: What's the correct way of reducing this sensor from 12v to 5v?
Post by: ArturDB on Dec 13, 2018, 08:20 am
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?

(https://scontent.ffln1-1.fna.fbcdn.net/v/t1.15752-9/48089028_265764817428941_161144595965542400_n.png?_nc_cat=109&_nc_ht=scontent.ffln1-1.fna&oh=421868d47b4678a83c7aed773663fa58&oe=5CA136AD) (https://i.stack.imgur.com/AXZiT.png)
Title: Re: What's the correct way of reducing this sensor from 12v to 5v?
Post by: Paul__B on Dec 13, 2018, 08:24 am
Sounds plausible, but have you figured the resistor values and you better first explain just what that sensor is?
Title: Re: What's the correct way of reducing this sensor from 12v to 5v?
Post by: BabyGeezer on Dec 13, 2018, 08:27 am
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.
Title: Re: What's the correct way of reducing this sensor from 12v to 5v?
Post by: ArturDB on Dec 13, 2018, 08:28 am
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. :)
Title: Re: What's the correct way of reducing this sensor from 12v to 5v?
Post by: ArturDB on Dec 13, 2018, 08:33 am
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

(https://scontent.ffln1-1.fna.fbcdn.net/v/t1.0-9/47576973_2250127911666406_4501846438900137984_n.jpg?_nc_cat=105&_nc_ht=scontent.ffln1-1.fna&oh=3b04730dfd450d837cbe3ee9431101e9&oe=5C904457)

(https://scontent.ffln1-1.fna.fbcdn.net/v/t1.0-9/48359479_2250128268333037_8895993411757146112_o.jpg?_nc_cat=105&_nc_ht=scontent.ffln1-1.fna&oh=5a839a9f75aab7e81350837c9f363a00&oe=5C93B048)
Title: Re: What's the correct way of reducing this sensor from 12v to 5v?
Post by: Wawa on Dec 13, 2018, 08:46 am
forum.arduino.cc/index.php?topic=584786.0
Title: Re: How do I get the boolean code, true or false, for this sensor?
Post by: Paul__B on Dec 13, 2018, 10:03 am
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!).
Title: Re: What's the correct way of reducing this sensor from 12v to 5v?
Post by: PerryBebbington on Dec 13, 2018, 02:27 pm
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?
Title: Re: What's the correct way of reducing this sensor from 12v to 5v?
Post by: JohnRob on Dec 13, 2018, 06:05 pm
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.






Title: Re: How do I get the boolean code, true or false, for this sensor?
Post by: Coding Badly on Dec 13, 2018, 07:26 pm

Threads merged.

Title: Re: How do I get the boolean code, true or false, for this sensor?
Post by: ardy_guy on Dec 14, 2018, 04:42 am
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:

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.



Title: Re: How do I get the boolean code, true or false, for this sensor?
Post by: JohnRob on Dec 15, 2018, 03:25 am
@ardy_guy


Quote
... 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
Title: Re: How do I get the boolean code, true or false, for this sensor?
Post by: ardy_guy on Dec 15, 2018, 05:07 am
Quote from: JohnRob link=msg=3982086
I need to come up with a better way of stating this.

Quote
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?




Title: Re: How do I get the boolean code, true or false, for this sensor?
Post by: JohnLincoln on Dec 15, 2018, 09:30 am
Looking at the LJ18A3-8-Z/BX Datasheet (http://www.ekt2.com/pdf/14_PROXIMITY_INDUCTIVE_18EX.pdf), 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.
Title: Re: How do I get the boolean code, true or false, for this sensor?
Post by: JohnLincoln on Dec 15, 2018, 10:17 am
ArturDB,
The output is open collector (http://en.wikipedia.org/wiki/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() (http://www.arduino.cc/reference/en/language/functions/digital-io/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.
Title: Re: How do I get the boolean code, true or false, for this sensor?
Post by: TomGeorge on Dec 15, 2018, 11:21 am
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.
(http://forum.arduino.cc/index.php?action=dlattach;topic=584786.0;attach=286011)
And as suggested, use a pullup resistor.

Tom.. :)
Title: How do I get the boolean code, true or false, for this sensor?
Post by: Paul__B on Dec 15, 2018, 12:36 pm
(http://forum.arduino.cc/index.php?action=dlattach;topic=584786.0;attach=286011)

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.