Pages: [1]   Go Down
Author Topic: Using Pins 13 / 0 / 1 as Digital Input to Arduino  (Read 580 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16470
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4538
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:
UCSR0B = 0;

Using pin 13 as an input is more difficult.

Logged

No, I don't answer questions sent in private messages...

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16470
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4538
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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-grin

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

Logged

No, I don't answer questions sent in private messages...

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?.
Logged

United Kingdom
Offline Offline
Tesla Member
***
Karma: 220
Posts: 6587
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

Code:
UCSR0B = 0;

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

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4538
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Let's try it and see...

Code:
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.

Logged

No, I don't answer questions sent in private messages...

Offline Offline
Full Member
***
Karma: 1
Posts: 146
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

http://arduino.cc/en/Reference/Board
Quote
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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: