# How to convert a digital signal from 5V to 24V?

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..

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.

• Please turn off the grid to improve clarity of text before taking screengrabs. Apr 5, 2018 at 17:06
• Have you tried an amplifier intended for LED strips? They are designed to take 12-24V DC power input and three channels RGB as a signal input and switch three channels of output in time with the input signal. The same unit can use 12 or 24v unmodified so they clearly have internal flexibility, not sure if it can take input as low as 5v. Apr 5, 2018 at 22:47
• Voting to close since the asker admits in comments that the output load may not actually be a relay. Without knowing what is to be driven it is not possible to design a suitable circuit - for example, a relay can work with just a low-side switch of suitable current capacity, but some other load may need something else, a high side driver or potentially even a bidirectional half-bridge of either "logic" or "power" output capability. Apr 6, 2018 at 13:40

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.

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.

• Thanks for your answer. Actually, I am not sure what will be there. it may be a relay or not but it sure that I have to provide a (0volt to 24volt) digital signal. I have assumed that there might have a relay. As per requirement, The control circuit(microcontroller side) should be isolated. so please suggest me how I will proceed. Apr 6, 2018 at 4:26
• Your 2nd sentence seems to be missing some words? Apr 6, 2018 at 6:45
• @Pray: Relays are inherently isolated between their driving side and the switched contacts. Apr 6, 2018 at 10:43
• @graw: Fixed. - Apr 6, 2018 at 10:43

The circuit in your schematic will work fine except that the relay coil should be connected to the output and to +24, not the output and GND. Pin 9 is not shown on your schematic and must, of course, be grounded.

The optoisolator is not doing much since the grounds are common- it does prevent ground bounce from getting into the MCU if your layout is bad. I would suggest a series resistor (eg. 1K) going directly into the ULN2803 and leave out the optoisolator. Or connect directly to the ULN2803 if you have good layout such as a ground plane and are sure the ULN2803 ground can't bounce more than a couple hundred mV below MCU ground.

The ULN2803 and the cheaper 7-output ULN2003A are probably the best way to switch or or a few small 24V relay(s), since they have good gain, are fairly robust and have the catch diodes built in. Take care as to the current ratings if you are using multiple channels, particularly with the smaller surface mount packages- read the fine print and charts on the datasheets and not just the headline claims. It's too bad there is not a compatible MOSFET array that was of comparable cost, but the existing parts are just too cheap and work well enough.

The big question here is what are your constraints?

• Do you have free choice over what both sides of the relay coil are connected to? or does third party equipment connect one side of the relay to some form of common connection?
• Does the 5V supply to your Arduino share a common ground with the 24V supply to the relay?

If you have free choice of how the relay coil is connected and your power supplies have a common ground then a simple low-side transistor switch as described in Olin's answer makes sense.

If not then more complex designs may be justified.

Your design will not work, the ULN2803 is a NPN array, so it's only suitable for low-side switching. Your use of the optoisolator is also rather pointless given that you have your 5V supply on both sides of the barrier.

Actually I am not sure what will be there. it may be a relay or not but it sure that I have to provide a (0volt to 24volt) digital signal. I have assumed that there might have a relay. Yes, 5V supply and 24V supply will be sharing a common ground.

Personally in that case I would look at "motor drive" chips. They can swing a signal high or low across a 24V range, are desgined to deal with inductive loads like motors and relays, can drive a fair bit of current and usually handle the level shifting problem for you.

I have used the L298n driver chip in the past, it would almost certainly have enough current drive for your task and it has four outputs, each of which could be used to boost a seperate logic signal up to 24V. Only issue I see with it is it's an older bipolar design and has relatively high voltage drop.

• Actually I am not sure what will be there. it may be a relay or not but it sure that I have to provide a (0volt to 24volt) digital signal. I have assumed that there might have a relay. Yes, 5V supply and 24V supply will be sharing a common ground. Apr 6, 2018 at 4:18

You may want to look at opto22 modules. They are pricey but easily reconfigured for multi-voltage digital i/o on 5v micro-controllers. old tech, but robust, mine are mostly salvage.