# Can I use a MOSFET switching circuit to trigger a digital input (that reads +24 V as high) with an Arduino Mega 2560 R3?

Its my first time posting.

I need to trigger a digital input pin on an industrial KUKA robot with an arduino. The pin reads +24 V as high. I'm using the circuit below. It consists of an IRL520 N-channel MOSFET and a 1K resistor. I'm using an Arduino Mega 2560 R3, however I'm aware the arduino digital pins output max 40 mA and +5 V. So my idea was to use the +24 V power supply (located in the electrical cabinet of the KUKA robot controller) and connect that to the drain of the MOSFET, then use my arduino's 0-5 V digital signal (from pin D11) to "switch" the MOSFET on/off and, subsequently, "switch" the digital input on/off on the robots IO module. So technically, I'm using the robots own power to trigger its own input. My questions are: 1. Is this a viable way to do it? 2. Is the resistor necessary to draw the current towards the pin? 3. Besides a relay is there any other way to do it with a MOSFET, specifically? Thanks

• step 1: check if the 24v plc logic input is intended for "p-type" or "n-type" driver. . . // also consider an opto or ssr Jan 22, 2021 at 16:38
• How far within the cabinet is the Arduino from the Kuka? How will they be connected? And should the level translation invert, or no? Jan 22, 2021 at 19:12
• Also what is the max expected frequency from the Arduino signal? Jan 22, 2021 at 19:14
• Finally, what is the input impedance of the Kuka pin? Jan 22, 2021 at 19:15
• The arduino isn't actually in the cabinet. It's about 1,2 m away. Well the arduino should switch the logic level once every 2 or 3 mins. So it's likely going to stay high for a while and only go low when the process is complete. As for input impedance I'm not sure, but it draws 15 mA. The levels shouldn't invert. Jan 22, 2021 at 19:50

1. Is this a viable way to do it?

Yes. The KUKA digital input is, most likely, an opto-isolate type so it will require about 5 to 10 mA to drive the opto-LED. Your R1, 1k resistor will drop 5 to 10 V when powering the input so check the KUKA input specifications for that. When Q1 is on R1 will dissipate P = I^2R so check that you've got a comfortable resistor rating for that.

Note that the logic is inverted with this configuration. GPIO on = KUKA input off.

1. Is the resistor necessary to draw the current towards the pin?

The KUKA input requires current to operate. R1 provides it. (The input draws current from the supply via R1. The resistor doesn't "draw current".)

1. Besides a relay is there any other way to do it with a MOSFET, specifically?

Yes.

1. Use a high-side switch. That will get rid of R1 and give full 24 V to the KUKA input.
2. Use an opto-isolator but then there is no need for the MOSFET.

KUKA robots are expensive. KUKA robots are industrial. The right way to do this is use an industrial opto-isolator between your microcontroller and the robot. This keeps the supplies isolated and makes it very unlikely that one will damage the other.

Photo 1. A selection of DIN rail opto-isolators.

You'll be looking for one with 5 V input. The outputs are usually transistors and, since they are floating, can be used for PNP or NPN inputs. These are also DIN rail mounting which will suit most control panels.

Using a cheap microcontroller to control an expensive robot seems a bit strange. Using a PLC would give a more robust and industrially hardened solution with the benefit that it would have much longer term support than your microcontroller code.

• There is more to it than I've initially explained. I'm not trying to control the robot with the arduino. My arduino runs a small three-dimensional linear actuator platform used in laser metal deposition. The laser head is an end-effector of the robot and the robot controller is connected to the lasers controller, hence the robot can switch the laser on and off. Now I'm actually trying to switch the laser on and off with my arduino, bypassing the robots control. That's why I need a circuit that can switch a 24V logic level on using a 5V logic level. Jan 22, 2021 at 20:23
• Also, it's not viable to go straight through the lasers controller, because of layers and layers of safety protocols. Jan 22, 2021 at 20:27
• Glad to hear you're taking safety seriously. Thank you for accepting my answer. Jan 22, 2021 at 20:30

Yes, this is fine. You also have to connect the ground ( negative supply pin) on the Arduino to the ground on the controller board. Because Mosfets are so fast, it is always a good idea to put a 100 ohm resistor in series with the gate, very close physically to the Mosfet. This prevents high frequency oscillation.

Of course, this circuit inverts the logic.

Yes, the 1k resistor is needed.

• what if it's a type 3 compatible sinking input - turn on spec is 11V and 2mA ... will 1k pull up produce that? Jan 22, 2021 at 18:08
• Hi, Pete: good point, I assumed it would be driving CMOS. Jan 23, 2021 at 4:24

I will not use direct mosfet to Arduino Input, but put optocoupler between , if gate-drain junction of your mosfet fails, it will burn the input of your Arduino.

Potentially in addition to an isolation stage, given that you have 1.2m of wire, you need noise immunity. Since my hobby on this site is suggesting Schmitt triggers: you could use one here. It's easy enough to find a comparator that will be supplied by 24V and output 24V directly, such as the LM311. It can output 50mA which should be well more than the 15mA that your next stage sinks.

For threshold voltages of 1V and 4V, in non-inverting mode, here is one solution:

simulate this circuit – Schematic created using CircuitLab

Given that the logic level only changes every 1-2m, you can greatly increase that capacitor.

Please be careful. It is important that you have the polarity correct, so that the mosfet, or whatever type of switch, is turning the input on, and the resistor is turning it off. If you do it the other way, it might turn on unintentionally when the input to the mosfet / switch disconnects, micro resets, etc. Some input types turn on with just 2mA of current.

I also strongly recommend an opto-isolator or solid state relay, such as shown in the other answer. You can implement the equivalent on your end, if you prefer, but the principle is the same. Eliminating the direct connection to your system will avoid many issues to do with grounding, disconnection, power-down, and so forth.