I'm using push buttons to control CR servos (button1=turn CW; button2=turn CCW). How do I pull up D1-D6 and what does that do exactly? I can't find a tutorial that explains it well enough how to use the resistors.
Typical Atmel AVR inputs can “float” when left open, that is, may drift high or low. The idea of a pullup or pulldown resistor is to give an otherwise-open input a definite value – high if pulled up, low if pulled down.
The values of pullup and pulldown resistor values are a tradeoff: You can use high values to minimize the current that a sensor device must overcome when it switches values, and to minimize power loss in a battery-powered device. Or you can use low values to get faster switching when you release the input.
There are built-in pullup resistors on most AVR inputs. (But A6 and A7 on some models of ATmega328's don't have pullups.) To use a built-in pullup, initialize the input pin with (for example)
pinMode(mypin, INPUT_PULLUP) instead of
To sense the state of a simple normally-open switch, you would connect one side of the switch to an input, and the other side to ground. Initialize the pin to be a pulled-up input: eg,
pinMode(mypin, INPUT_PULLUP). Regard the switch as not-pushed when
HIGH, and pushed when it shows
If you really want to use external pullup resistors, connect the switch as above – one side to ground, one side to a pin – and connect a resistor between +5 V and the pin. That is, one end of a resistor and one side of a switch will connect to the input pin. In this case, use either
INPUT_PULLUP as the
pinMode setting; it makes no big difference because the internal pullup resistor has a fairly high value, eg 40 KΩ.