# Do I need a capacitor for an ATtiny85?

I have a small LED strip light, which I want to power by a power bank. It is active for 6 hours, and then sleeps for 18 hours. It takes almost no power while sleeping, and the power bank detects this and shuts off. To defeat it, I built a small "device" which sleeps for 8 seconds and then draws 50 mA for 250 ms. This is enough to keep the power bank awake.

The whole setup seems to work fine, and it is running for over 24 hours now.

I am an amateur, and was told by an engineer, that I need a capacitor for the IC (to buffer some spikes that occur while switch in the IC while switching or something like that).

I looked for some schematics of ATtiny85 projects online, and not a single one used a capacitor.

I tried looking in the datasheet, but I have no clue how to read one. It is over 200 pages long, and I don't know what to look for.

Do I really need a capacitor? If yes, what kind and where?

• It's generally good practice to always add a capacitor to decouple any IC, but especially ones that involve logic. Feb 27, 2022 at 21:33
• Wait, wait, wait! Did you connect PB1 directly to the base of transistor? Don't do this. Put a resistor between PB1 and the base. Feb 28, 2022 at 2:47
• Is this neccessary? If I understand the datasheet of 2N2222 correctly, it should be able to handle 5V. How many ohm would you suggest?
– Flo
Feb 28, 2022 at 21:17
• @flo the base of a NPN is essentially just a diode. Diodes with unchecked current and voltage can burn out. A resistor for probably 5mA would be good for your 50 mA load, so (5v - 0.7V) / 0.005 = 860 ohms. Choose the next smaller size so 800 ohms is good enough. Feb 28, 2022 at 21:26

Local decoupling capacitors of 0.1µF are such an engineering convention that they are often ignored in datasheets because they are expected. Larger power capacitors like 100µF are always mentioned. That said I didn't go through the complete datasheet but they have an App Note AN2519 - AVR Microcontroller Hardware Design Considerations which is short you can read. First section details local decoupling on the digital power supply.

That said, your power bank may have some on its board that's enough for your specific project, especially if the wires are pretty short (or your board plugs right into the USB connector).

The capacitance of your board or other things may also be providing the local capacitance needed. Or the led strip controller has one. Or if you are using an ATTiny85 module like a Digispark or clone then it already has one.

Frankly 0.1µF caps are dirt cheap and board space is rarely so tight you can't throw one on. Worst case you can solder a cap on top of your ATtiny.

• I indeed bought digisparks. But even with watchdog sleep and removing the 78m05 and the power led, it still drew >5ma in idle. So i just removed the ATtiny85 from the board. Idle was down to 3.2uA. You wrote 0.1uF, the answer of bobflux says 10-100uF for regular capacitors. I would guess, that all of those would work, but which one is preferable?
– Flo
Feb 27, 2022 at 22:28
• @flo the 0.1ųF is local to the ATtiny while a 10-100ųF would be for the board. They serve similar but different purposes. Feb 28, 2022 at 0:11
• @flo by board I mean any average sized pcb/veroboard/stripboard. The 0.1uF decoupler cap is probably more important than the other. If you experience any odd behavior then you can add the 100uF. Feb 28, 2022 at 21:25
• +1 for helping a new guy out. Mar 1, 2022 at 19:26
• Just to add that if you do miss out the capacitor, you may find your whole circuit works perfectly fine - until one day it doesn't (but you won't find a problem when you try to debug it). I once had a circuit that worked perfectly well on the desk, but not "in the field". Then perfectly well on the desk again, but not in the field. I added a 0.1uF cap, and suddenly it worked everywhere. Putting them in almost never causes any problems, but saves a lot of head-scratching later. Mar 2, 2022 at 11:30

Yes, you do need a capacitor. Don't replicate mistakes of other beginners and leave them out just because they leave them out.

It may not be mentioned in the datasheet, because a datasheet may only concern the electrical parameters of the chip, it may not have information that is common to all microcontrollers or all digital chips in general.

For AVRs specifically, there is a hardware design guide AN2519 which does mention the use of bypass caps.

To expand the issue further, the capacitor is not needed due to average DC current consumption. The AVR is a digital chip and let's assume it runs at 1 MHz frequency, so logic circuitry that is made with CMOS transistors are operating at that frequency. So on each clock cycle there could be hundreds (or thousands?) of transistors switching state, and each transition takes energy.

So even if the average DC consumption is only about 1mA, you might have short durations of 50mA spikes that happen one million times per second, and the voltage at the ATTiny must be held high enough even during the short 50mA current spike when current is required fast.

If the wiring is long, it adds resistance which limits the peak DC current that is available, but wiring also adds inductance, which limits how quickly the current is available, before voltage drops too much. Therefore each and any chip, digital or analog, typically has bypassing near it for local energy storage so current is quickly available when needed. For hobby purposes a single 100nF ceramic capacitor should work fine, as long as it's there.

Without a decoupling capacitor, supply voltage of your micro depends on ohm's law: it will drop by the current drawn by the micro multiplied by the impedance of the power supply, wires included. Digital chips tend to draw current spikes, with a generous amount of high frequency harmonics. Combined with the inductance of the wires to the power bank, this can result in transient voltage drops that can trigger the brownout detector (if configured) or result in random crashes.

So the usual fix is to put a capacitor between VCC and GND. This lowers the supply's high frequency impedance, because the cap is close, so its wiring is short, so it has low inductance.

It's absolutely possible that it'll "work" without it, but then every chip is slightly different and their characteristics also change a lot with temperature... so "it works right now without a decoupling cap" doesn't guarantee that it will work with another attiny chip, or on a cold or very hot day, or that it won't crash after a few hours.

For an AtTiny there's no need to overdo it, it's not that fast and it's not using a large amount of current anyway, so a 0.1µF or above capacitor is fine.

The usual would be a ceramic cap, because these have low ESR and they're cheap. If you don't have any, you can use a film cap of same value, or an electrolytic cap of higher value, say 10-100µF (because general purpose low-value electrolytics have high ESR, so you need a higher value to get lower ESR, and they cost the same anyway).

• You wrote 10-100uF for general purpose capacitors, but i also often find values like 0.1uF (other answer and more source on the internet after searching for "decoupling capacitor). Is there a prefered one? Also you write, that the VCC may drop. I think the ATTiny does not draw much current, because it is only switching the transistor. The Voltage for the ATTiny is 1.8-5.5V. The powerbank is giving me slightly above 5V. I will add a capacitor anyway, but is there really a chance, that the voltage will drop so much in my case?
– Flo
Feb 27, 2022 at 23:24
• preferred would be a 0.1uF ceramic cap, placed close to the chip. The ATTiny does not draw much current on average, but often the current is mostly drawn in very brief spikes. it's a CMOS chip, so any time a transistor in it is switched on, its gate has to be charged up like a capacitor, resulting in a very short high current pulse. since it's all synchronized by a clock, you could have thousands of transistors all switching simultaneously depending on the code the chip is running. you won't see the voltage dip on a meter but it can still glitch down for a few microseconds and cause problems Feb 28, 2022 at 9:06
• a ceramic is recommended because ceramic caps have a lower ESR (equivalent series resistor) and ESL (equivalent series inductance) than electrolytic caps. This means it can supply more current, and can respond more quickly to changes in current demand. 0.1uF is recommended because smaller capacitors tend to have lower ESR and ESL, and 0.1uF strikes a nice balance between being small enough to respond fast, and having large enough to actually help. in some fancy designs you may have several different sizes of caps to handle small fast ripples and larger slower ripples. Feb 28, 2022 at 9:20
• The ATtiny won't draw a lot of DC current, but that's not the problem why you need the capacitor. The ATTiny runs at, for example, 1 MHz clock, and there are hundreds if not thousands of transistors switcing simultaneously 1 million times per second, and each transistor needs a some energy to switch, so even if average consumption is 1mA, it could for example draw 50 times that current for one 50th of a clock cycle. Feb 28, 2022 at 9:42