According to the ATmega328P datasheet, the total current from all I/O pins must not exceed 200mA.
Let's say that an Output pin sources 30mA and an Input pin sinks 10mA. The total current should be 30+10=40mA or 30-10=20mA?
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It only takes a minute to sign up.
Sign up to join this communityAccording to the ATmega328P datasheet, the total current from all I/O pins must not exceed 200mA.
Let's say that an Output pin sources 30mA and an Input pin sinks 10mA. The total current should be 30+10=40mA or 30-10=20mA?
Neither. First, inputs don't draw current. Whether you're sourcing current or draining it, it will always be an output pin.
The 200 mA rule is probably determined by the bonding wires for the Vcc and ground pins on the die. That means that all outputs which are sourcing current shouldn't source more than 200 mA combined, as this current will have to enter the device through the Vcc pin.
Likewise all outputs sinking current shouldn't sink more than 200 mA combined, as this current will drain through the ground pin.
Usually you sum the magnitudes of the currents - so
|+30| + |-10| = 30 + 10 = 40 mA in your example.
Predictably but unfortunately. the principle of TANSTAAFL usually applies in such matters :-).
Such limitations are often (but not solely) dissipation based.
A low level output pin is dissipating ~= (Vo_low) x I low and
a high level pin dissipates (Vdd-Vo_high) x I_high.
For low currents versus I_pin_max, Voutlow is ~= 0 and Vouthigh is ~= Vdd.
As currents approach design capacities Voutlow starts to rise and Vouthigh starts to fall (due to the internal 'switch' not being able to handle the current) and dissipation rises.
IF you pulled a high pin fully low or a low pin fully high then
at 5V and 200 mA IC dissipation = 1 Watt.
Under that sort of abuse other bad things may happen.
There MAY be some specialist cases where you can treat SOME high and low currents as semi independent but this would need a good understanding of the IC and probably still lies outside specification.