Pages: [1]   Go Down
Author Topic: Problems using a switch on digital pin 0 (without serial monitor)  (Read 787 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Mauritius
Offline Offline
Jr. Member
**
Karma: 2
Posts: 95
Learning Never Ends . . .
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

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

----
taz
Logged


tz
.....

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

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
« Last Edit: October 04, 2012, 11:20:07 am by retrolefty » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 601
Posts: 48567
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Thanks for your replies! I will try this next week.
Logged

Pages: [1]   Go Up
Jump to: