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