[solved]24v Input from sensor to 5v Arduino digital I

Hello.

I would like to make a circuit using a 4n35 Octocoupler, I need to read the High/low status of a industrial sensor that uses 24v logic,.

thanks for help.

Are you actually asking a question?- it’s more like a statement 8)

Put the input on the LED with a resistor to limit the current- check the datasheet for the forward voltage and maximum current and calculate the resistance to suit.

Then put the transistor emitter to ground and the collector to the Arduino input pin with the pullup enabled.

See schematic here for a 4n25.

Note that for total isolation, those grounds don’t even need to be connected.

Max corrent for 4n35 seems to be 60mA acording to http://www.vishay.com/docs/83717/4n35x.pdf

so to limit the corrent using a 24v Imput the Resistor needs to be 400ohms?

24v = R * 0,06A R= 24v/0,06A R=400ohms

is this right?

What kind of sensor you have? I'm asking because you may need to amplify the sensor signal. Can the sensor source 60mA of current?

helderferreira: Max corrent for 4n35 seems to be 60mA acording to http://www.vishay.com/docs/83717/4n35x.pdf

so to limit the corrent using a 24v Imput the Resistor needs to be 400ohms?

24v = R * 0,06A R= 24v/0,06A R=400ohms

is this right?

NO !!!!! that is threadhold maximum just before you burn it out.

try 10ma ! the internal sensor can be thought of as an ordinary LED. in fact, you can put an LED in series to get a visual confirmation that you are getting a signal.

1.2k to 2.4k for 20mA to 10mA

all you are looking for is a high/low signal.

Would something like in the attachment works, or I need to get a 5v VCC on the transistor side of the octocoupler?

Would be better to use pull-up resistor. (Add ~ 10k from ATmega pin to Vcc)

helderferreira: Would something like in the attachment works, or I need to get a 5v VCC on the transistor side of the octocoupler?

My understanding of an optocoupler is that you use as input, whatever you have- that's the whole idea. You need to check that your resistor on the input consumes enough voltage to get down to what's acceptable to the LED inside there, that's all. The data sheet will show it's characteristics, but it's just an LED.

Budvar10: Would be better to use pull-up resistor. (Add ~ 10k from ATmega pin to Vcc)

You mean on the Arduino input? Agreed, and the link I posted earlier showed that. My first response said to use the internal pullup, it's much easier. I have that exact configuration running on my bench breadboard as we speak, but not with 24V input.

I revised it to this using a 10k resistor between 5v VCC and transistor colector pin

is it correct now?

Yes.

JimboZA

My first response said to use the internal pullup, it's much easier...

It's also solution but 10k ensure higher current and better signal/noise. Internal pull-up may vary according the datasheet is 20-50kohm.

Thanks everyone, got it working.

Its normal for the signal to be HIGH when there is no imput, and LOW for when there is? Anyway to make it the reverse?

helderferreira:
Thanks everyone, got it working.

Its normal for the signal to be HIGH when there is no imput, and LOW for when there is? Anyway to make it the reverse?

Yep that’s what the pullup does, keeping the pin at 5v under normal circumstances. Then when your signal goes high it activates the transistor, grounding the pin.

To change that logic you would need to use an external pulldown, since there aren’t any internal ones, only internal pullups. But this so-called “active low” approach is seemingly quite common. If you search the forum you may fine a thread or two on the reasoning. But it’s easy enough to cater for in code, as you obviously found out.

ok I can fix that on the code, thanks everyone for the help.

Its now solved.

suggest me the circuit for providing 24v output from plc to arduino uno input

patilnikhil80: suggest me the circuit for providing 24v output from plc to arduino uno input

I did that here:- https://forum.arduino.cc/index.php?topic=537366.msg3662323#msg3662323

Now:- DO NOT cross post.

DO NOT resurrect 4 year old threads.