I am quite new to electronics and am attempting to build my first project with an Arduino Diecimila board. So far, so good. I have an LED running connected to a pot, and I am able to control the intensity of said LED by rotating the dial. What power I wield!
The next step is to throw a bit of logic into the mix. I have a switch wired from the 5V (through the switch) to digital pin #2. Sampling this pin and sending it’s value back to the computer via the Serial.println statement shows that in one position, the board is reading “1”. In the other position, it reads “1” or “0”… basically just fluctuating between the two. If I hook it up to an analog pin, I get a full “1023” in one position, and fluctuating between 300 and 500 in the other.
From what I gather, I need to put a resistor in there to fix this. I think that what I am looking for is a pull-down resistor (this is based off of the wiki page: http://en.wikipedia.org/wiki/Pull-up_resistor). Basically, this resistor should force the pin to 0 volts when the switch is closed. My questions are as follows:
Am I right? Do I need a pull-down resistor?
If so, how many Ohms (and is that even the right way to describe it)?
Do I put this resistor between ground and one of the leads on the switch?
If so, does it matter which lead?
I’ve read that the Arduino has a pull-up resistor for its input pins, but:
a) I don’t think a pull up resistor would work for me, right?
b) Just for kicks, I tried setting that pull-up resistor for that pin to HIGH,
but now it just always returns “1” regardless of how the switch is set
(which makes sense to me, but then what is the purpose of the built
in pull-up resistor?)
How, exactly, does the pull-down work (links to “pull-down resistors for dummies” would be welcome)
Any suggestions for general electronics reading material for newbies?
I know that is a lot of questions… so thanks to all who read through this!
If so, how many Ohms (and is that even the right way to describe it)?
People generally use 10K, though 4.7 through 100k usually works just fine. More can be used in battery sensitive applications.
Do I put this resistor between ground and one of the leads on the switch?
See below.
If so, does it matter which lead?
Always in between the micro and the switch, otherwise its not doing anything
I’ve read that the Arduino has a pull-up resistor for its input pins, but:
a) I don’t think a pull up resistor would work for me, right?
It depends. A pull-up resistor will bias the microcontroller input to “1” when the switch is not closed. You would connect up the switch as follows:
Micro ------- Switch ------ Gnd
|
|
10k
|
Vcc
This would be equivalent to turning on the internal pullup resistor in the AVR. With the switch open, the AVR sees a 1. Current is flowing through the 10K resistor through the AVR and then ground (conventional flow).
With the switch closed, Vcc conducts to Gnd over the 10k resistor (5V / 10000 = 0.5mA worth), but the GND line connected to the AVR input via the switch has a much lower resistance (effectively 0 for this illustration purpose), bringing the input pin to ground (0) as well. No more current is flowing/no more gates have a charge, and the AVR reads this as 0.
If you want the switch to actually report “1” when its closed, you can’t use the internal pullup resistors: just swap Vcc and Gnd in the above diagram with an external resistor.
Any suggestions for general electronics reading material for newbies?