Go Down

Topic: Problems using a switch on digital pin 0 (without serial monitor) (Read 967 times) previous topic - next topic

adeekay

Firstly, hello! I have been using arduino for a while but have not yet posted anything on this forum despite it being very useful!

I am trying to using a switch as an input to digital pin 0 on my arduino uno. I have a push to make switch connected from +5v to digital pin 0, and an external 10k resistor from the pin to ground. I am not using an serial data commands in my sketch as I am aware this interferes with the digital pin's functioning.

My switch would appear to be held in an ON or HIGH state permanently. I have set the pin to an input using pinMode(switchPin, INPUT).

If I change the pin to different number then my sketch works perfectly. I have also tried different switches, different resistors etc but like I said, it works fine on a different pin. Also, I am using the same setup (external 10K res, +5v to pin) on digital pin 1 with no issues.

What could be the reason for the error?

Thanks,
Alex


taz3m

Hi,

Try to connect a pull down resistor switch type on the digital pin 0 and see what it gives.

----
taz
tz
.....

retrolefty

#2
Oct 04, 2012, 06:18 pm Last Edit: Oct 04, 2012, 06:20 pm by retrolefty Reason: 1
Quote
What could be the reason for the error?


The problem is that pin 0 has external on-board wiring to the on-board USB serial converter and even when not using any serial communications or not even wired to the PCs USB, pin 0 has effectivly a 1k ohm pull up resistor wired to the pin. Adding external pull-down resistor just creates a voltage divider situation and will result in not the proper voltage levels to be seen by the input pin. So to use pin 0 as a switch input you should just be able to wire the switch from ground to the input pin. When switch is pushed your digitalRead() will return a zero and a one when not pushed. Try it and see if that doesn't work better for you.

Lefty

PaulS

Quote
So to use pin 0 as a switch input you should just be able to wire the switch from ground to the input pin. When switch is pushed your digitalRead() will return a zero and a one when not pushed. Try it and see if that doesn't work better for you.

You can wire all your switches this way. For the other pins (besides 0 and 1), turn on the pullup resistor, using digitalWrite(pin, HIGH).

This lets you write code that doesn't matter which pin the switch is attached to.


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy