0

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.

  • Why do you need to pull up six inputs if you only have two buttons? – Mark Smith Jun 16 '17 at 22:14
  • 2
    use pinMode(D1, INPUT_PULLUP) and save your resistors for something else. – dandavis Jun 17 '17 at 1:03
  • @MarkSmith I've got multiple servos. – mkpappu Jun 18 '17 at 16:55
2

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 pinMode(mypin, INPUT).

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 digitalRead() shows HIGH, and pushed when it shows LOW.

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 or INPUT_PULLUP as the pinMode setting; it makes no big difference because the internal pullup resistor has a fairly high value, eg 40 KΩ.

  • Do you think for this Thing - thingiverse.com/thing:239105 - I can use internal pull-up resistors? It's telling me to use external, but I don't understand why. Thanks for your help! – mkpappu Jun 19 '17 at 16:44
  • I don't know what D2-D6 (which that page refers to as having pull-ups) are used for in that project. If it's switch or rotary encoder inputs, internal pullups should be fine. If it's I2C, maybe not. Anyhow, I didn't find a link to a circuit diagram that might reveal how D2-D6 are used. Do you have a circuit diagram or a link? – James Waldby - jwpat7 Jun 19 '17 at 20:53
  • The trouble is that there isn't a circuit diagram. D2-D6 are going to the buttons and joystick on a shield (sparkfun.com/products/9760). When you press those buttons or move the joystick CRservos will move clockwise or counter-clockwise. – mkpappu Jun 19 '17 at 20:57
  • That sparkfun.com/products/9760 page says internal pullups are ok: “The momentary push buttons are connected to Arduino digital pins 2-6; when pressed they will pull the pin low (utilizing the internal pull-ups of the Arduino)” – James Waldby - jwpat7 Jun 19 '17 at 21:05
  • That's great! Did not see that. There doesn't seem to be any benefit to using external pullups. – mkpappu Jun 19 '17 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.