10

I want an I/O pin to return current in a circuit, similarly to the function of ground.

Which of these will achieve what I require?

pinMode(pinnumber, OUTPUT)
digitalWrite(pinnumber, LOW)

or

pinMode(pinnumber, input)
2
  • your second option pinMode(pinnumber,input) is placing the pin in the "third state" of the pin, which is also called "high impedency". It's basically like if the pin was not connected to the circuit, like a ohmmeter does.
    – zmo
    Commented Mar 5, 2014 at 13:31
  • "digitWrite"? Don't you mean "digitalWrite"? Commented Mar 6, 2014 at 20:23

1 Answer 1

9

Your first snippet is the correct solution.

pinMode(pinnumber,OUTPUT)
digitalWrite(pinnumber,LOW)

Be careful though, you can only sink up to 6mA or 9mA per pin (as per the documentation ["Input and Output" section], I never tried more). If you need more current, use a transistor (this looks like a good example, you just need to invert the output pin to HIGH).

When the pin is configured as input it is supposed to be high impedance, not what you want.

11
  • Thanks, the current also comes from the IO pins of Arduino. Therefore, i don't think 40mA limit will be a issue.
    – rajat
    Commented Mar 5, 2014 at 10:30
  • @rajat Doing some sort of LED matrix ? Be careful, assuming you plug (for example) a high current LED between two pins (at least without a proper current limiting resistor), you could still damage the chip. Not even mentioning the case where you create a short circuit.
    – FredP
    Commented Mar 5, 2014 at 10:35
  • It is a pressure sensor matrix, it has 10 16:1 multiplexers. The current only comes from the Arduino USB cable and no external power supply.Therefore, i don't think high current will be a issue. Can you shed some light on what possibly can cause a short circuit?
    – rajat
    Commented Mar 5, 2014 at 10:37
  • @rajat something like that would create a short if pin "1" and "2" are connected : pinMode(pinnumber1,OUTPUT); pinMode(pinnumber2,OUTPUT); digitalWrite(pinnumber1,LOW); digitalWrite(pinnumber2,HIGH); PS : do not try this at home, do not harm innocent arduini, do not sue me, etc...
    – FredP
    Commented Mar 5, 2014 at 10:43
  • 2
    I was a bit surprised by the 6/9mA number. Turns out you’re correct for the Arduino Due, but for the AVR based Arduinos (Uno, etc), which I suspect are still in the vast majority, that number is more like 40mA. Commented Mar 6, 2014 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.