Problems with Digital pin 0 and 1

I’ve been working on a program for a toy that I’m making for my little boy. Apart from my poor programing skills there is one problem I can’t seem to figure out.

I have some push buttons connected to the digital pins as inputs. The work correctly on every pin with the exception of Digital Pin 0 and 1.

Below is how i’m declaring the set up of my Pins. If I change my constants to 0, 1, 2 only buttonPinC works.

const int buttonPinA = 2; // pin number of the pushbutton pin
const int buttonPinB = 3;
const int buttonPinC = 4;

void setup() {
// initialize the pushbutton pin as an input:
pinMode(buttonPinA, INPUT);
pinMode(buttonPinB, INPUT);
pinMode(buttonPinC, INPUT);

Any ideas? I know that 0 and 1 can be set up as serial inputs but I’m assuming I would have to declare that in my sketch (which I am not).


Can you first describe in detail how you are wiring up your switches. I see in your code there is no attempt to enable the internal pin pull-up resistors. That means there needs to be external pull-up or pull-down resistors. After that we can deal with pins 0 and 1. Also you might want to post your complete sketch to see how you are determining that the switches are working properly or not.


Pin 0 and 1 are the hardware Serial port, maybe this interferes a bit ....

Thank you for showing interest in my project.

My switches (push buttons, actually) are wire to provide 5v (high) to the connected pin when pushed. There is a pulldown resistor connected to ground to prevent false tripping.

Like I stated before, everything works correctly if I use any pins other then 0 or 1.

I understand that I could use pins other than 0 or 1 but i plan to use all of my I/O.

Port 0 and 1 pull up with 1 kOhm on the board. If you change wiring, resistors between +5V and input, consequently button input-gnd, they will works. By enabling internal pull up resistors on others ports you'd not need any of them(resistors) at all.

As already suggested below, if you change your switching logic to active low, I think you will fine you will be able to utilize all the digital pins including 0 and 1. Use no external resistors, wire each switch between ground and it’s IO pin, enable internal pull-up resistors on all I/O pins being used. Reading the pin, a low will mean the switch is being pressed and reading a high will mean it’s not being pressed.


Thanks Lefty,

my concern with that is power consumption. I plan to run this on batteries. With 13 resistors connected internally between 5v and ground, i would expect power consumption to increase. Would you agree?

Let me give you a better idea of what my project is.

My little boy loves plugs, buttons and knobs. I have build a box that has 4 high output LEDs, 3 pushbuttons, 3 1/4inch head for jacks, a 1/4 male connector attached to a wire, and a variable resistor with a big knob on it.

depending on which plug the wire is plugged into the buttons will have a different functions (games). Currently plug 1 is simple, a button pushed will light up the matching LED. Plug 2 is a matching game. An LED lights up and a tone is played, the user needs to press the correct button. Plug 3 is a memory game where a sequence of lights and sounds gets longer with each correct answer. (Like old school Simon Says).

My primary goal is to not need to replace the batteries every 6 hours ;) Other parts of the sketch i am still working on; - basic sleep after a period of no activity - reducing the clockspeed from 16hz to something lower ( heard this really reduce power consumption) - using interrupts when a button is pushed instead of polling them constantly.

Issues that are much lower in my list - Start up time after sleep (no need for it to be instant) - brownouts caused by too low of a battery voltage.

I'm not sure if i'm giving you too much information on not enough as i'm starting to deviate from my original question. If you'd like to take a look at the sketch, please let me know. It's nothing fantastic but I'm sure you could find a lot of ways to clean it up.

Thanks Spark

reducing the clockspeed from 16hz

I hope you meant MHz.

With 13 resistors connected internally between 5v and ground, i would expect power consumption to increase. Would you agree?

No, not really. The internal pull-up resistors will be connected between +5vdc and the input pin which is very high impedance and virtually no current will flow. Only when you actively press a switch button wired from ground to the input pin would current flow and then it would be just .1ma or so per pin, and only for how long one holds the switch button down. I don't think using internal pull-ups will have a significant effect on your battery duration. Now running at lower clock speed and using sleep mode may indeed be worth looking into if indeed battery duration becomes an issue. I would suggest you first develop the application software and wiring to get it all working and then measure actual current consumption and calculate battery duration. After that you can modify your sketch using lower clock speed and/or sleep mode if you feel it's justified.