I have a bit of experience with the Arduino and wiring up various components, sensors, using communication protocols, etc. -- but my circuits have never really involved capacitors, or inserted with only a small amount of understanding, so I'm trying to learn some more about them
The Blink sketch was running (flashing Pin 13 / "L" LED) on the Arduino at the time and, while pressing the button (causing the LED to light and the capacitor to charge), the "L" LED flashed erratically and I also got the "USB Disconnected" sound from my computer which was supplying power to the Arduino -- which makes me suspect that the board was shorting or drawing too much current?
I inserted a resistor in series with a capacitor and that solved the problem. But I don't see one used in other tutorials (ex. this circuit from Sparkfun's tutorial).
Do capacitors always need a resistor, or is there something I'm missing? The LED did stay lit and faded out after a short while after releasing the button, as expected.
Don't use that circuit.
The capacitor basically shorts out the power supply until the cap is charged.
Potentially bad for the supply (laptop?) and the switch.
That circuit can only be used on e.g. a 9volt block battery, relying on some internal resistance of the battery.
The charge in the cap makes the LED fade out when you release the button.
Fading (in and/or out) can also be done with an Arduino PWM pin.
Look at the "Fade" sketch in the examples that come with the IDE.
Leo..
The link is to a circuit that is powered by nine volts which cannot be USB. Capacitors do not always need a resistor, it depends upon the circuit. In the circuit shown, the capacitor will initially draw a lot of current if it is originally discharged.
Drawing a lot of current from a battery or a power supply may not be a problem. Drawing a lot of current from a USB port can be a big problem.
I realize it's a 9V source in the link -- but my assumption is that it can be replaced with the 5V from the Arduino, as just a simple example.
I also tried a 9V 1A power supply with the Arduino (to rule out limitations of supplying current via USB as mentioned by vaj4088), but also saw the same behavior.
I'm inclined to go with Wawa's explanation:
The capacitor basically shorts out the power supply until the cap is charged.
That circuit can only be used on e.g. a 9volt block battery, relying on some internal resistance of the battery.
Just trying to understand the underlying cause:
Is the circuit shorting while the capacitor is charging?
Or, is it attempting to draw too much current?
Both?
I understand I can fade the LED using PWM or other methods, but my goal was just to learn a little bit about using capacitors.
The problem isn't the supply to the arduino, it's that you are trying to take it from an I/O pin using the Blink sketch, which you seem to have modified the circuit. There is a difference between trying to pull current from the 5v pin and trying to get it through a I/O pin.
Is the circuit shorting while the capacitor is charging?
Or, is it attempting to draw too much current?
Both?
When a capacitor is not charged and is suddenly connected to a voltage it looks like a short circuit. So there is nothing to limit the current except the impedance of the voltage source. As it starts to charge the current it draws drops rapidly. An inductor works in exactly the opposite way, looking initially like an open circuit and eventually after some time looking like a short circuit. Although in this case there is some resistance due to the resistance of the wire.
Putting a capacitor without a resistor across the supply to a running circuit will typically cause malfunction
as the capacitor "crowbars" the voltage (imagine the voltage being bashed down with an iron bar!) for an
instant.
The decoupling capacitors already in circuit act similarly when the supply is first turned on, causing the
supply voltage to rise over a period of time, not instantly, but this generally doesn't create problems.
Using a resistor in series with a capacitor hardly ever makes sense
If a capacitor is connected from the supply voltage to ground it has the task to eliminate spikes and compensate for a sudden power change of chips. This makes a lot of sense.
Resistors in front or behind capacitors are usually only used in filters (low-pass/high-pass) or oscillator circuits. A lot of analogue circuits use this combination as well.
In a digital world like Arduino it hardly ever makes sense. It is OK for a delayed reset on the RESET pin of any device.
The circuit in the link of the first post in this thead must have been designed by a naive person. It could destroy a low power power supply and might reset other devices on account of the sudden voltage drop when you press the button.
When you switch off the lights at your home, you do not use a hammer with your light switch ... even when it works for a while.
arduinoaleman: Using a resistor in series with a capacitor hardly ever makes sense
A bit of a sweeping statement.
Having some means of limiting the inrush current in a capacitor, especially in large ones, almost always makes sense.
Sure we don't usually put resistors directly in series with bypass capacitors, however we do rely on the impedance and the rate of rise of the power source (transformer etc) to limit the inrush when the circuit is first powered up. In cases where we have large capacitors and not enough inherent impedance to limit inrush, then some extra resistance has to be added, for example with an NTC thermistor or a timed charging resistor on an auxiliary contact.