Using an arduino to control a signal on a model railway

Aren't unused pins INPUT LOW at startup? That's zero-state, no voltage level at all. They are electrically neutral if you don't read them!

And if you do read, it takes ~1 micro-amp per read. I have used that to roughly read the charge on wires to sense force put on piezo disks.

INPUTS only read small samples... but you can read a million samples per second easily.

Since most of our newbies trip over a floating input, with an unpressed button giving random 0 and 1 values, how could this be? I don't follow you. Sounds like one of those "if a tree falls in the forest.." type arguments.

I'm not going to regurgitate the relevant sections of the datasheet, except to quote an example. Section 1.1.6, {added by me}:

Port D is an 8-bit bi-directional I/O port with internal pull-up resistors ({can be}selected for each bit). The port D output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, port D pins that are externally pulled low will source current if the pull-up resistors are activated. The port D pins are tri-stated when a reset condition becomes active, even if the clock is not running.

There's more for us to chew on, possibly, in section 9.10.6, Where the document states

When entering a sleep mode, all port pins should be configured to use minimum power. The most important is then to ensure that no pins drive resistive loads. In sleep modes where both the I/O clock (clkI/O) and the ADC clock (clkADC) are stopped, the input buffers of the device will be disabled. This ensures that no power is consumed by the input logic when not needed. In some cases, the input logic is needed for detecting wake-up conditions, and it will then be enabled. Refer to the Section 13.2.5 “Digital Input Enable and Sleep Modes” on page 62 for details on which pins are enabled. If the input buffer is enabled and the input signal is left floating or have an analog signal level close to VCC/2, the input buffer will use excessive power. For analog input pins, the digital input buffer should be disabled at all times. An analog signal level close to VCC/2 on an input pin can cause significant current even in active mode. Digital input buffers can be disabled by writing to the digital input disable registers (DIDR1 and DIDR0). Refer to Section 22.3.3 “DIDR1 – Digital Input Disable Register 1” on page 204 and Section 23.9.5 “DIDR0 – Digital Input Disable Register 0” on page 220 for details.

But that section is discussing conditions for deep sleep, so I'm not sure much of it is relevant.
Ultimately, either someone who knows the device better than I (wouldn't take much), or someone who's done the experiment under controlled conditions(more in a minute), would help us.
To test this, I think the thing to do is set up something like a Nano with a decent power monitoring device, and run a herd of inputs through a test circuit, checking consumed current with several pins driven simultaneously output high, output low, and input, with the desired resistor-LED combination on each pin. See what the blessed thing does. My suspicion is, it will be fine, but hey, it's a free opinion, for what that's worth.

Data sheet says 20 mA, go with that. But, be careful. Read the datasheet further, you'll want to do the math on maximums for ports, as well as the maximum for the device:

Although each I/O port can source more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady
state conditions (non-transient), the following must be observed:
ATmega328P:
1] The sum of all IOH, for ports C0 - C5, D0- D4, should not exceed 150mA.
2] The sum of all IOH, for ports B0 - B5, D5 - D7, XTAL1, XTAL2 should not exceed 150mA

DC current VCC and GND pins - 200 mA

More later, gotta run!

Are you sure that's the case with AVR's? Is recommended or actual?

I didn't find my ATmega328P datasheet but I knew the limits since 2012.

Checked every reference to current in my copy of the datasheet (document 7810D-AVR-01/15) - 25 mA is quoted nowhere(that I could find. "25" appears 194 times, I did not check every occurrence). However, the 20 mA I quoted, upon rereading, is the test current the manufacturer uses in order to measure other pin characteristics, but it is not stated as any form of "maximum". So I guess one could use 25 if one wished. Probably, you'd be fine as long as you also respected the port limits I quoted previously.

For me, the telling 20 mA "limit" is that their output voltage charts (Figure 29.8) indicate an output voltage of 0.65V at a 20 mA current, the maximum shown; they don't test any higher current.

Definitely a valid warning. If I remember correctly, any input pin in a floating or undefined level has the potential to cause an excessive power draw. With the pair of resistors creating the VCC/2 condition, the input pin will be held within the undefined region and the warning is applicable.

This warning identifies an unexpected additional power draw that can cause the controller to consume more battery power than expected. If this additional power draw is not significant (IE wall adapter or model trail power source) to the entire system, it may be ignored (no damage will occur). Circuit designers are encouraged to always address this in their designs. This is just in case other system changes suddenly make this issue significant to the system power draw.

The unexpected power draw flows through the input pin sense circuit when that circuit transitions between the high and low states. Because the input voltage is undefined, these transitions will occur erratically. This voltage is unique to the specific characteristics of the MOSFET pair sensing the input and varies from pin-to-pin and from microcontroller-to-microcontroller.

If the input voltage is left floating, it will float through the transition point without any logical pattern. When the input voltage is fixed within the undefined range, these transitions will only occur when the input voltage is close enough to the transition point that the minute voltage fluctuations are repeatedly causing the transition. The resulting additional energy usage will be so unpredictable that anyone attempting to characterize the device power consumption will fail to produce trustworthy results.

In this case, I believe that the input pin pull-up resistor will be adequate to hold the controller pin at a defined level and therefore minimize the quantity of waste energy used.

Residual question, what is the "transition point"? Do we know? Or is it an undefined characteristic of the input design, possibly even unique to each input instance due to other design factors(like the other functions some pins can optionally perform)?

I'm guessing this is so far away from typical use cases, it's simply not specified, and although I wouldn't do what I've proposed in a commercial design, I'd be highly tempted to use the trick on my model layout, if I had those two-pin tricolor LEDs in mind for panels or what have you.

There is no clearly defined “transition point” and my memory of the input circuit transition (and my posted description of it) was not accurate.

The input circuit has a CMOS ( Complementary metal–oxide–semiconductor) type logic gate input that gives the high-impedance input characteristics. The defined voltage ranges are guaranteed to behave as the definition describes when given the correct (as described in the datasheet) transition edge.

During the transition phase, there are two MOS devices conflicting against each other and attempting to drive the output to opposing binary values. This means the output of the pair will be unsettled until a MOS device wins control over the output and the other MOS device. The duration and conclusion of this process has no expected behavior whatsoever when the input voltage stays within the undefined region. The CMOS behavior observed depends on the specific MOS device characteristics, temperature, VCC voltage, CMOS wear, and CMOS mood at the time.

For good circuit design, minimizing the time involved with the CMOS transition conflict will minimize energy waste and be more gentle on the CMOS circuit. Worth noting. Also, for a single device like described above, I would likely ignore the warning and do it anyway like you.

20 is plenty! But facts are designer gold!

At 30mA the pin won't live as long as at ... less, but still work a good many hours. the forum has had long discussion threads on the matter.

25mA is the limit for common leds, yah?

It's all about the heat, of course. Run one output at 30 mA, you'll probably not see an issue ever. But run 5 in a row at 30 mA, the one in the middle is likely getting toasty. For LEDs, Voh and Vol aren't of any concern, an output voltage that's way out of wack is probably going to actually reduce current in the LED. Then of course there's always the "what are the ambient conditions", to add complexity to the considerations. Run the Arduino wrapped in insulation with no cooling, results are different from the same Arduino in open air.
I came late to Arduino-world, so missed most of these discussions. No doubt, much more was said, and debated. But amazingly, every day we still have newbies on the Forum, and they're not likely to discover those old threads any time soon.
All YMMV, of course.

We have archives going a ways back, the search sees those.

5 leds in a row.... series? The forward voltages add up. 12V will light 3 blue, green or white leds in series. 5V won't light 2 unless you have low Vf greens but can do 3 red leds.
In parallel the full current gets divided across them all, if any quit the most one alone would see would be 30 mA.

I don't count thermally insulated systems any more than operating on fire!

I believe that @camsysca was very clear on their intended meaning and you got it confused.

To me, this obviously refers to the output pins on the microcontroller. The “5 in a row” means 5 output pins grouped together as in pins 2 through 6. In this arrangement, the microcontroller hardware controlling pin 4 will have heat from the other 4 output circuits flowing into it as well as heat from its own operation. This is excellent recipe for blue smoke.

Adding a heat sink on top of the AVR like it's a Darlington Array running a stepper won't solve that?

It can be done when soldering. But finding ways to run is not the goal in that example and the idea of concentrated heat through badly chosen pins is a very good example of what can happen through ignorance. If you don't think about such a problem, you won't think it needs solving.

5 at 30mA is 150mA on a board that maxes at 200mA.

Hi,
If you read the manufacturers data spec in any micro controller, there will be a max current per output pin AND a max total current per output PORT.

Sometimes this means you can only have three or four outputs operating at near max current to exceed the total port current spec.

Tom.. :smiley: :+1: :coffee: :australia:

With an output shift register with 40mA max total, when you limit the suppy on the + pin, you can't get more than 5mA per pin when all 8 pins are outputting. There was at least one thread where that was part of the multiple leds discussion.

Burning the chip up by not limiting the current flow is to me like pointing out that a led without a resistor will shine brightly once.

But really, this discussion with pin/port uses and exceptions seems really useful for a hobby electronics forum! I am very happy for the clear explanations for this info as pertains on limiting current yet I will state that it doesn't change what a pin can take.

These are ALL matters to take in designing circuits. Multiple requirements apply at the same time!

RL has been a real beotch lately. I missed that Big Time!

Bummer. That makes everything more difficult and focusing on the small details of other things nearly impossible. Hope RL improves for you soon.

So many things went right today I feel paranoid of the other shoe!

I have to line up an eye doctor, cataracts gotta come out!
Other than that, with department of aging help I was able to get paperwork unsnarled to clear the path to clear vision.

I have the forum in dark theme but the datasheet is thin black on blazing white! I lower the backlight which does help but still over minutes it wears my eyes out. But this year it's a priority.