can I use pin 13 as an input

should this work if I put an LED and resistor on pin 2 and put 0v from the 0v pin on pin 13 to test pin 13?

void setup()
{
  pinMode(2,OUTPUT);
  pinMode (13,INPUT_PULLUP);
}
    
void loop()
{
  int buttonState = digitalRead(13);
  if (buttonState == 0)
  {
    digitalWrite (2,HIGH);
  }
  else
  {
    digitalWrite (2,LOW);
  }
}

You can use any pin as an input or an output.

Mark

What happened when you tried?

It depends on what you have connected to it and which version of arduino board you are using. Sometimes that built in LED messes things up so it's best to keep it as an output if you can. I'm sure someone else has more information on when it causes problems and when it doesn't.

the onboard LED (connected to pin 13) glows dimly and the LED on pin 2 stays on regardless

Make sure the LED is not swapped anode & cathode.

No, if I remove the led lead from pin 2 and touch it to +5v it lights.

On the official Uno, the pin13 LED is buffered with an opamp, so you can use pin13 freely. On many boards though, the LED is just connected directly to the pin, and the load from the LED prevents it from being a useful input.

The symptom of this would be with it set as INPUT_PULLUP, the LED would light very dimly, and digitalRead() would always look low.

So add a 1K pullup from 13 to +5, help out the internal one if needed.

DrAzzy:
On the official Uno, the pin13 LED is buffered with an opamp, so you can use pin13 freely. On many boards though, the LED is just connected directly to the pin, and the load from the LED prevents it from being a useful input.

The symptom of this would be with it set as INPUT_PULLUP, the LED would light very dimly, and digitalRead() would always look low.

Good answer @DrAzzy

What brand board are you using?