Electronic – arduino – How to convert a digital signal from 5V to 24V

arduinodrivermicrocontrolleropto-isolatorrelay

I have an industrial application where I have to interface a microcontroller output which gives a digital signal (0V to 5V) on its outputs and I want this signal to control a relay which takes (0V to 24V) on its input.

So I have to convert (0V/5V) digital signal into (0V/24V) to operate the relay. The microcontroller's pin output is 5 V 40mA for that I thinking I will use IC ULN2803 along with PC718 optocoupler to drive this 24 relay. My schematic as per my assumption is..
Schematic

I am new to electronics design. Please check my design and let me know if it is correct or not. If not, then please suggest the best design that is suited to my application.

Best Answer

Converting to a "24 V signal" is missing the point. The real problem is driving a 24 V relay from a 5 V digital signal. Fortunately, that is easy. Here is one way:

You didn't say how much coil current the relay draws at 24 V, so I picked an example part I had in my system (Zettler AZ8-1CH-5DSE).

Figure the B-E drop of Q1 is about 700 mV. This means there will be 1 mA of base current when the left end of R1 is held at 5 V. To guarantee the transistor stays solidly in saturation, let's say we only ask it for a gain of 20. This means it can support up to 20 mA collector current. 13.5 mA is well below that, so no problem.

D1 is not optional, even though it looks like it doesn't do anything. The relay coil has a significant inductive component. When anything tries to shut off the current through it abruptly, the inductor will make whatever voltage it takes to keep the current flowing in the short term. Without the diode, that would require abusing the transistor. The diode gives the inductive kickback current a safe place to go while the current dies down on its own due to the resistance of the coil.

Added in response to your edit

I see you have substantially changed your question while I was writing this answer. Your original question was better, because it simply asked how to do something. That's easier to answer than having to first dispel myths. I might have skipped this question entirely if I had seen it post-edit for the first time.

In any case, my answer above is still valid. Using a opto-isolator is silly, since you don't need isolation nor a unpredictable voltage shift. The ULN drivers are darlingtons, which have unnecessarily high saturation voltage. You are also trying to use it as a high side driver. Again, it's a lot more trouble to explain why a bad circuit is bad than to show a good circuit. I'll therefore stick to my original answer.