24V input output, for a noob

Hi,
I want to use my arduino to read a bunch of 24V Sensors. (currently I need to read at least 12).
In addition I need to switch relays which are already in place and can't be changed. (3)
all is digital.
for the input I designed a circuit

The Zener Diode is 5.1V
R1 is 1kOhm
R2 is 270 Ohm
R3 is 4.7kOhm (pulldown resistor)
I have no clue what LED to choose or how one chooses the right one. Sry I am an advanced noob. :confused:

My first question apart from choosing the LED is would this circuit work?
2. Is there a better way to design a 24V input? (It still needs to be fairly cheap, as I need to build this circuit 12-20 times.
3. For driving the relays I was thinking about optoisolators or mosfets, but I really have no ideo what a good aproachlooks like. I am expecting to drive 200mA per channel, So even the mega can't supply enough current.
I want to expand that in the future to have more outputs so keeping the price down is a priority too.
4. can I use the analog pins of the arduino as digital pins? than I could use the uno for the project otherwise I will need a mega.

For input I would use an optocoupler. You need only 3 components. You can put the LED and the opto LED in series with a single resistor.
The transistor in the opto would ground the digital input with internal pull-up enabled.

the highest rated optocouplers I found were like 1.4V forward voltage. So I would need at least a voltage devider infront of the optocoupler. and as optos are not really cheap especially if you need 20 of them. plus the components in my simple voltage devider it will quickly get expensive.

For the input, just use a simple divider. Aka, no zener or pull down. But go 1 or 2 order of magnitude higher for the values. Something like 130k and 33k.

For the relays, just use a transistor (BJT or MOSFET, current is probably low so a BJT will do) + a flyback diode.

KOR:
the highest rated optocouplers I found were like 1.4V forward voltage.

You are not understanding what you read. That is just the forward volts drop of the IR diode in the opto. Just use a seriese resistor to light the LED from your 24V sensor output.

How to calculate a resistor for a LED
You can use cheap optocouplers.
To drive more relays you can use some driver chip, for example ULN2803A

OK after I got quite a bit of good input and a private lecture which told me I know nothing about electronics I drew up a new sketch. with an optocoupler.
Since I got a little bit of heat that I did not include the sensors and relays I have to switch here they are:
One of the sensors I have to read is an Balluff BRGB2-WCB08-EP-P-L-K Sensor (Output 24V max 50mA)
A second one Balluff BES 516-324-E4-c-01 Sensor (balluff BES)
In addition a ptc thermistor din 44081 (where I haven't read up on so this will be a battle for another day)

The screwterminal is ground (bottom) and when active 24V (top).
The 4N35, is just there because thats the only one I found in autodesk circuits.
A typical 5mm green LED runs at 2.1V I am assuming I will take a 1.4V optocoupler at 20mA this hould give me a value for R1 of 1000 Ohms (0,6W).
For the pull-up resistor, I will use 4.7k Ohms(0,25W).
Why not use a pulldown resistor? With the pullup I will get an inverted signal, it is no problem to correct that in code, but it seems more logical to use a pulldown.

Do you have good suggestions for an optocoupler for me?
I got 2 Siemens Sirius 3RT1016-1BB41 relays which need to be switched, besides two other relays I have to look up.

For the output side, I drew another sketch. I am again assuming 1.4 V for the optocoupler and 2.1V for the green LED and guessed 20mA for those optoelectronics. This should make R3 75 Ohms.
V1 is 24V.
The output needs to supply 200 mA min so for good measure I say 300mA.
Can I drive that just with an optocoupler?
And again do you have a good suggestion for the optocoupler?

thanks to all the people who helped. (Especially for the one who provided me with a private lecture)

The suggestion of a ULN2803A is a good one, as long as the "ON Voltage" [technical term: VCE(sat)] of [worst case] 1.1 to **1.6 (**depending on the Collector current [the current to the relay coil]) doesn't prevent the relay coils from closing the relay contacts. But, good news, at 24V, such saturation voltages are a much lower percentage than at, say 5V, where they can be a deal breaker. The cool things about this IC (a "Darlington Array") is:

  • It has 8 drivers in one inexpensive [$1.95 at SparkFun] package!
  • For an input current of 500µA you can drive an up to a 500mA load [a Beta of 1000]! And 8 x 500µA = 4mA, so not even close to the MAX Arduino VCC current [200mA for the Uno].

The following datasheet has an "Typical Application" that shows how to use this IC to drive Relays (If you see something like this "300 A" in the graphs, it's supposed to be: "300µA"):

[https://cdn.sparkfun.com/datasheets/Components/General%20IC/uln2803a.pdf](http://"http://"https://cdn.sparkfun.com/datasheets/Components/General IC/uln2803a.pdf"")

Why do you feel you need to use Opto Isolators to drive the relays? Unless there is a need to isolate the Arduino circuit from the relays, it would be easier [and probably cheaper] to use something like the **ULN2803A ** suggested by jendalinda.


Again, why the opto?
Do you really need isolation?
Do you really HAVE isolation? (aka, 100% separate 24V supply and another for the Arduino).
Led is for indication?
You don't need R2 if you enable internal pull ups.
R1 is border line. It doesn't need to drive a lot. I would up it to 2k9
You say something about logic and logical, don't look at that :wink: Do what's easy. And you now have an inverted signal. If there is power on J1, digital1 goes LOW.
If you really need an opto and it doesn't need to be fast will almost everything do.


And again, why the opto? If you just use a transistor you can drive the relay directly. An opto alone will NOT be powerful enough to drive those big relays (140mA).
Why the led?

One concern, though, on using that ULN2803A [with it's relatively high saturation voltage]. The datasheet for the Siemens Sirius 3RT1016-1BB41 relay, appears to have no provision for driver voltage loss in the relay coil circuit. It just says 24V, with no tolerance. Thus, no assurance is given that driving the relay coil with a slightly lower voltage, won't impact, say the contact integrity or relay lifetime. I would call the manufacturer and ask about that -- especially if your project has any critical features, or is destined for production.

I did a little Googling for a driver array with MOSFET driver transistors, but only found things like SMD parts that, typically, require a serial interface with the MCU [aka Arduino].

septillion:

You don't need R2 if you enable internal pull ups.

I think you were thinking that R2 is on an Arduino output, and not the Isolator output :wink:

No, it's on an Arduino input. Which had an internal pull up :wink:

And why dodge the questions about WHY you think you need an opto everybody is asking?

And you didn't read the datasheet all that well :wink:
"Operating range factor control supply voltage rated value of magnet coil at DC"
And it tells it's between 0,85 and 1,1. Aka 20,4V and 26,4V :slight_smile:

You could use individual MOSFET transistors to drive those Relays (be sure to include the flyback diode [1N4004] 100 for 3.80USD at All Electronics).

If you can do Surface Mount, All Electronics has a nice Logic Level MOSFET with excellent drive capability at 4 for a USD!

Jameco is having a clearance sale on these little beauties at 19¢US @ Quantity of 10 or more. They aren't as good a fit as the BUK92150 from All Electronics, but they are definitely good enough, and at 600V, they are quite robust AND they're cheaper AND they aren't SMD:

https://www.jameco.com/z/BUZ77A-Siemens-Corporation-SIPMOS-Power-Transistor-BUZ77A_2217852.html

septillion:
No, it's on an Arduino input. Which had an internal pull up :wink:

And why dodge the questions about WHY you think you need an opto everybody is asking?

And you didn't read the datasheet all that well :wink:
"Operating range factor control supply voltage rated value of magnet coil at DC"
And it tells it's between 0,85 and 1,1. Aka 20,4V and 26,4V :slight_smile:

I'm not the OP :wink:

And I'm not very good at reading those weird industrial datasheets. So, I'm glad you were able to fill in that blank. Cool, then the ULN2803A should work just fine!

I don't dodge the question. 1. I was told that professional equipment uses those optocouplers. 2nd I do have a 24V and a 5V powersupply. So I could have it completly isolated, from the arduino.
But there is no must. In my perfect dream world I like to do it as cheaply as possible and as reliable as the pros have it. :slight_smile:

In addition, I like to recycle the pcb for future projects so why go for the bare minimum of protection.

unfortunatly I can't do smd unless its a big 2 pin resistor.

the LED is for indication, makes troubleshooting easier. And I like leds^^

I tried to incorporate as much suggestions as I could. I decided that I will use Optos even though some of you were against it. I wan't to have it as save and reliable as possible.


I got no clue if the Opto I choose is a good one the current seems high with 50mA.
for the output I added a flyback diode.
Should I do the same thing for the input?

Could you guys check my layout it is the second board I design so there are bound to be errors.

one the current seems high with 50mA

No that is the maximum current the LED can take, it is not the current that you have to give it. The current is determined by the seriese resistor, the data sheet should tell you what you need. That 470R is way way too low.
And the 39R from the Arduino will damage the Arduino’s pin.

I calculated those values with the 0,05A in the opto datasheet. Should I just use 25mA? I don't think I understand how to choose the right current when calculating the resistors.

KOR:
I calculated those values with the 0,05A in the opto datasheet. Should I just use 25mA? I don't think I understand how to choose the right current when calculating the resistors.

First, am I looking at the correct datasheet -- your "sensor" is an rotary encoder, is that right?

Assuming I have that right, then, definitely set the current level to a "nominal" current for the optoisolator (also called an "Optocoupler") -- 50mA is the Max current -- no need for it to be that high. For the 4N35, that's anywhere from 2mA to 10mA. How to find that on an optoisolator datasheet can be a bit tricky. You would think the best place would be the IF spec, but the Vishay datasheet for the 4N25 (for example) uses 50mA (the MAX current!) for this spec (so, clearly, this is not always the best indication). Probably the best place is on a Collector Current vs. Collector Emitter Voltage transfer curve -- if the datasheet provides one. Such a diagram (or graph) has multiple plots, one for various different LED currents. With such a diagram, you can set the LED current based on the current on the collector. Another place to look is on the one or more CTR vs LED Current graph(s) (might have slightly different name on different datasheets). CTR is the Current Transfer Ratio [similar to a Bipolar Transistor "Beta"]. On the Vishay 4N35 datasheet, the optimal CTR happens at an IF of around 10mA. When setting LED current, be sure to subtract 3V from the 24V used to power the encoder (as per the datasheet Output voltage VS spec).

But, when choosing an optoisolator, make sure it can respond fast enough. The 4N35 is a relatively slow optoisolator [rise and fall time of 10µS @ an IC of 2mA], BUT, according to the encoder datasheet, the max switching frequency is 1.5kHz (LSB) -- which will be the highest frequency for any of the lines -- and 1.5kHz has a period of 667µS (333µS per half cycle), which is quite a bit greater than 10µS, so no problem. If you needed to speed the optoisolator up a bit, you could use the Switching Time vs. Load Resistance graph. Notice how the toff time gets faster and faster, the lower RL's resistance becomes.
And, optoisolators are a good idea for interfacing these encoders, since they provide an inherent logic voltage shift.

The fact that the outputs on this encoder are "high side drivers" means it's an excellent match for driving an optoisolator, so there's also that ;D.