e-San:
And no change for analog nor digital read. What am I doing wrong?
Don't know because we have no idea how you have actually connected it, but it sounds as if you are incredibly lucky that you have not trashed your Arduino by connecting a 12 V source to an input.
Maybe dumb question, but you are using a retro-reflective target? Wiring would have been so much easier with the sinking (NPN) version. With that one you need a voltage divider to drop the 12V output down below 5V.
outsider:
If the sensor's output is 12V, you MUST use a voltage divider.
18k 10k
12V----///--+--///----GND
|
|
A0, 4.3V
Well, in another discussion, according to this application note, ATMEL specifically warrants that it is safe to use the internal protection diodes to clip up to 1 milliamp in either direction, so you do not need the 10k, just use a 47k in series. (Put it right at the Arduino pin to avoid any interference problem.)
1mA might be too susceptible to noise. At least add some capacitance to ground on the inputs, this
will absorb noise spikes picked up by the wiring (47k is a pretty high impedance, enough to be sensitive
to nearby motors and so forth).
MarkT:
47k is a pretty high impedance, enough to be sensitive to nearby motors and so forth.
Which is of course, precisely the reason for my advice to put the resistor right at the Arduino pin.
To pick up interference, you need an antenna, which is the trace between the resistor and the microcontroller. This needs to be as short as possible, the less interference you can pick up, the less you need to consider extra steps to suppress it.
If there is any concern about interference, you need to de-bounce the input in code, and by not using interrupts.
I've switched to Inductive sensor since photoelectric ones was not satisfactory for me.
Just one question: why 47k?
I understand that clamping diodes are designed to be up to 1mA, so they will have to conduct up to 12V@1mA, it gives 12k resistor in series (at least). Ofcourse it is always a good idea to work somehow uder the limitation, so why wont we use, for example, 22k? It would give us 12V/22kohm = 0,55mA..
Because if wired directly at the Arduino pin, there is negligible risk of the pin picking up interference so no expectation it will not respond reliably and without delay.
There is a great concern about voltage surges on automotive systems. Not necessarily at the battery itself, which is one reason why important equipment such as communication radios are generally wired directly to the battery, but there is a lot of wire in a car loom, high voltages on the ignition and funny things can happen.
And because really good engineers are really careful and conservative.
Unfortunately, it didn't work. As I mentioned at the beginning of the topic, I'm going to use it for GRBL.
There are INPUT_PULLUPS set for limiter. So i used NPN transistor and 47k resistor.
C - Collector connected to input,
B - Base --- 47k --- limiter output,
E - Emitter connected to GND.