Using Pins 13 / 0 / 1 as Digital Input to Arduino

Hi There,
I have a requirement where all the Digital Input Pins, apart from 0,1 and 13 are utilized. I have read documentation which indicates that one should steer away from those pins, unless unavoidable. In my case I can't avoid them : I need one more input.

My Input is a from a Set of photo transistors (Which would output either 0 or +5V). When I connect it as it is to Pin13, the values jump to 0 in some cases where I would expect 1(+5). I've connected a 10K Resistor to the Input and grounded it, but it hasnt done much difference.

Can someone advice me on whether the above is the best option in this case ?. Note that I tried to connect Pin 0 and 1 without success...

Thanks in advance
LG

Pin 13 drives a on-board series resistor and led and this may on may not cause a problem with your photo-transistor trying to drive the input pin high due the the current draw of the led and 1k ohm series resistor. If you are using a Uno or Mega Rev3 board then it should work as there is a op-amp driving the led but on other older boards there is just the load of the led/resistor seen on the shield pin 13. Are you using up all your analog input pins, as they can also be used as digital input or output pins?

Lefty

Thanks retrolefty for the prompt reply. My Board is a Uno R2. So I guess that One Option is out...However, Yes All my Analog Pins are free...I'll check that option out. Many Thanks!

You could use pin 13 as an input of you desolder the LED connected to that pin. You should also be able to use pin 1 as an input, but you may have to disconnect the phototransistor (or at least keep it in the dark) when uploading sketches.

Pins 0 and 1 can be used as inputs so long as you disconnect the device when you need to upload a sketches.

But...you have to disable the USART because it overrides the normal pin functions. The code for this is:

UCSR0B = 0;

Using pin 13 as an input is more difficult.

Thanks Fungus!. Although I tried to use Pin 1,0 while unplugging it during uploading sketches it didnt work. I'll try this too...

The OP already stated he is not presently using his analog input pins, so he has no need to utilize pins 0,1, and 13.

Lefty

retrolefty:
The OP already stated he is not presently using his analog input pins, so he has no need to utilize pins 0,1, and 13.

Lefty

Oh, yes! :smiley:

No problem then, he's got another 6 pins...

Thanks Everyone, I've used the Analog Input to work it around and works fine. But I'll try to use the UCSR0B = 0; option too. I assume it's in the setup phase in code ?.

fungus:
Pins 0 and 1 can be used as inputs so long as you disconnect the device when you need to upload a sketches.

But...you have to disable the USART because it overrides the normal pin functions. The code for this is:

UCSR0B = 0;

Shouldn't the USART be disabled already when the sketch starts, assuming no Serial.begin() call is made?

dc42:
Shouldn't the USART be disabled already when the sketch starts, assuming no Serial.begin() call is made?

Let's try it and see...

void setup()
{
  int a = UCSR0B;
  Serial.begin(115200);
  int b = UCSR0B;
  Serial.println(a,HEX);
  Serial.println(b,HEX);
}
void loop()
{
}

That printed "0" and "0x98" so it looks like you're right.

I've could swear I've seen threads where that fixed it though. Maybe they'd called Serial.begin() before they tried to use it.

retrolefty:
Are you using up all your analog input pins, as they can also be used as digital input or output pins?

This is a good suggestion. You can find more information about use analog input pins as digital input pins under

Most of the analog inputs can also be used as digital pins: analog input 0 as digital pin 14 through analog input 5 as digital pin 19.

Thanks Clemens and Everyone Else...Yes I do confirm using the Analog Pins as Digital Input Pins (Addressing Analog Pin0 as Digital Pin 14 ..) and it works fine. I did not have to use Digital Pins 0,1 and 13.