Can an Arduino read it's own pins?

Hi,

This might seem like an odd question.

But for testing purposes I'd like to:
-- Set pin 2 to output
-- Set pin 3 to input pullup
-- Connect pin 2 to pin 3
-- Simulate a sensor by setting pin 2 high/low
-- Read the state of pin 3

Can I connect the pins directly?
Or am I about to fry my Pro Mini because I'm missing something basic?

[EDIT]
I'm mainly wondering/worried if there will be a over-current issue on the pins when connecting them this way
[/EDIT]

Thanks!

arduino_loopback

Yes, of course it can. It doesn't care where the signal comes from, even from another one of its own pins. It matters how you wire things, and how you code things, but as far as the concept of "HI" or "LOW", Arduino is pretty dumb (in a good way).

Ok,

I edited the question, I'm mainly concerned that there might be a current issue.
Would a limiting resistor be advisable or can the internal resistors handle this just fine?

Thanks

For new users, there can be an argument for adding 240R resistors to all the Arduino I/O pins.

This resistor can prevent accidental damage when shorting the pins to other conductors.

The resistors will have no detrimental effects.


In your situation, tying an output to an input is not a problem.

I just went ahead and tested, and it works just fine.

Thanks for the feedback :slight_smile:

In short:

#include <Streaming.h>

void setup() 
{
  ...
  pinMode(2, OUTPUT);                      // Use pins 2, 3 to test reading pins
  digitalWrite(2, 0);
  pinMode(3, INPUT_PULLUP);
}

void loop()
{
   ...
   digitalWrite(2, !digitalRead(2));      // Toggle pin
   Serial << digitalRead(3) << endl;
}

The only problem with connecting two pins directly together is if you goof and set them both as outputs and one HIGH and the other LOW!

That is why I usually use a resistor as a convenient jumper between pins - we all make mistakes. Just have to be aware that the resistor and internal pullup resistor act as a voltage divider.

The static current into an input pin is measured in nanoamperes.

Why?

Oh, my ... you have been deprived:

Streaming - Arduino Libraries

So you're not tempted to

Serial.println( String("Temp= ") + String(temp) + String(" Hum=") + ...