Trains.com

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

pull-up vs pull-down inputs and outputs

978 views
1 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    July 2009
  • From: lavale, md
  • 4,677 posts
pull-up vs pull-down inputs and outputs
Posted by gregc on Sunday, November 13, 2016 7:43 AM

Figure-5 (pg 45) in the Arduino article in the December 2016 MR shows a input to the Arduino with a switch connected to 5V driving the input.  I'd like to suggest that using a pull-up and connecting the switch between the input and ground is both more convenient and flexible.

While I'm not familiar with the processors used in Arduinos, it is common practice for GPIOs to have internal pull-up resistors which pull the signal high without anything driving, such as the case of an open switch or an open-collector output from an electronic device.  If an internal pull-up is not available an external pull-up (typically 10k) can be connected between the input and the supply voltage of the Arduino.

One big advantage of using a pulled-up input is that the input voltage is the same as the input device.   This also allows the circuit driving the input to operate at a different voltage (e.g. 20V, 3V) than the input device (i.e. arduino in this case) or no voltage (e.g. a switch or photo transistor).  This avoids the possibility of damaging the input with a higher voltage than the input device.

It also avoids the need to provide a supply voltage to the signal source when there is usually a ground wire nearby and makes it easy to test the circuit at any point by simply grounding the input.

It's never obvious whether a signal being high (e.g. 5V) or low (0V) respresents an active signal (e.g. block occupied, mainline or diverging turnout position).   It's easy for firmware to handle an active high or low signal.  So there is no "right way".   The best way is the simplest, least expensive and easiest to maintain.

 

 

Figure-6 in the same article shows two ways of driving an LED.   The top circuit is similar to what I describe above.   The Arduino drives the output low (i.e. ground) to turn on an LED connected to a supply voltage.

While convenient, the other approach, where the LED is connected between the output and ground requires the Arduino to supply current to the LED.   While this is typically not a problem, it may be if there are several LEDs all that need to be on at the same time.

greg - Philadelphia & Reading / Reading

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Sunday, November 13, 2016 12:08 PM

 I thought the same things. Plus I wondered why he didn;t just use a 10 pin IDC cable to connect to the BOD-8, instead opting for individual wires to each pin. Would have made the wiring neater.

  Notice that in Fig 7, with the transistor driver, it is being used as an open collector sink to ground.

 The ATMega micros used in Arduinos do have internal pullups you can enable. Even the little 8 pin ATTiny I am using for my servo control has internal pullups. My preference is still to use external pullup resistors though, that way you can't blow anything up if the code is wrong (like declaring the line digital input without enabling the pullup).

 As for the outputs - I don;t recall there being any difference on the data sheet as far as current per pin, however using the pin as the switch to ground is almost always far more efficient than using it as a current source, so for a given amount of current, the chip should run cooler as a sink. It can be a little more complicated when dealing with a micro because each pin can do 5 or 6 different things so internally there are a whole lot of gates and switching logic connected. The data sheets have a typical pin schematic for those interested.

                        --Randy

 


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Users Online

There are no community member online

Search the Community

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
Model Railroader Newsletter See all
Sign up for our FREE e-newsletter and get model railroad news in your inbox!