I am having a digital output of 24VDC and 0.5A from ABB IRC5 controller. I need to feed this digital output to the digital input of Arduino uno. How can I do that?
One common misconceptions is that the current limit of a GPIO pin applies to inputs. It does not.
The 40mA "maximum sink" is only applicable when the pin is set to OUTPUT and is driven LOW - at which point the pin is connected to ground through a MOSFET.
However, when the pin is in INPUT mode it is high impedance. This means that it neither sinks nor sources current (apart from a very tiny leakage current). The only thing that matters is the voltage. That must:
- Never go higher than 0.3V above VCC (5.3V if powered from 5V)
- Never go lower than -0.3V
- Have logic levels that are within the thresholds of the input:
- Below 0.3 × VCC for LOW
- Above 0.6 × VCC for HIGH
You can connect the input to a signal that is 5V and 1,000,000 giga-amps and all will be well.
However, if you inadvertently set the pin to OUTPUT and drive it LOW there will instantly be smoke. For this reason it is common to add a small inline resistor (maybe 100Ω-470Ω) in order to limit any current through the circuit should the pin ever be set to OUTPUT and LOW.
Another "However", though: If you are using a voltage divider to reduce your incoming voltage to conform to the values above (as shown by @user43648 and suitable values given by @EdgarBonet) the inline resistor is pointless. The voltage divider itself will have a very high output impedance which massively limits the current. This impedance is like having a resistance equivalent to both the provided resistors in parallel inline with your input.
You have 2 different questions here. First one can be answered by google search, it is literally the first result.
The Arduino Uno uses the atMEGA328 microcontroller, which has an absolute maximum rating of 40 mA source or sink per GPIO. Also, the total current through the supply or ground rails (i.e. the total of all current OP wants the GPIO pins to sink, or source) is rated to a maximum of 150 200 mA.
And you should not apply more than 5V.
Regarding second question, Google can help again.
Vin is your 24V from controller, Vout is your Arduino digital 5V input. With that established, use voltage divider formula to calculate R1 and R2 values. I hope you can do that? That being said, I am disappointed, because I feel like you have put 0 effort into researching this.
As a complement to user43648's answer, it is worth noting that:
- According to the datasheet, the 40 mA limit “is a stress rating only and functional operation of the device [...] is not implied” beyond the maximum tested current which is 20 mA.
- The input voltage should be at least 3 V for the pin to be guaranteed to read high.
- When sensing voltage through a voltage divider, 10 kΩ is a somewhat typical order of magnitude for the resistors.
Given the above, I would suggest using 47 kΩ for the top resistor
and 10 kΩ for the bottom one. This should give about 4.2 V on
the input pin, which is near the middle of the appropriate range for the
pin to read
In addition to the potential divider I would be tempted to strap the input pin to ground with a zener diode between 4V7 and 5V1 in case the lower resistor or its solder joints fail. even with a relatively high value series resistor 24V has plenty of potential to destroy the input pin if not the entire chip. The safest method though is use an opto-isolator and keep the nasty high voltages isolated from the delicate digital level components.