Fade
Goal
- 3+ LEDs with current limited using resistors, at least one of which fades
- button, tilt switch, or custom switch with current limited
- for-loop
digitalWrite()
digitalRead()
analogWrite()
Schematic
Each diode and switch is wired to its own pin providing power.
The 3 diodes all connect to the same ground.
The calculation below yielded the minimum resistances needed.
Calculation
Red and Green LEDs:
Blue LED:
Pushbutton:
Pushbuttons were rated for 50mA on the datasheets (octopart).
220 Ohm resistors were used for all 4 resistors across 3 different situations.
- For red and green, it was the closest resistor value which exceeded the minimum of 160.
- For blue, the minimum was 100, but I would not use exactly 100, since fluctuations could cause the necessary resistance to actually be more than 100 at times. Thus 220 was the next smallest value available.
- For the button, the minimum was 85, but 220 still worked fine, and if I used it then I would have less risk of mixing up resistors later, since all my resistors would be the same, so I chose to use 220 for the button as well.
Circuit
Firmware
Notes
-
The voltage is assumed to be across an LED with a 1.8V drop.
Voltage over time for analogWrite with 3 duty cycles
Red = 64, Green = 128, Blue = 255
-
With 3 LEDs that draw 20mA of current each, i.e. 60 total in parallel, a 1200mAh battery can power the circuit for 1200mAh / 60mA = 20 hours.
-
The voltage across my 3 LEDs when all were on was: R 1.96 G 2.67 B 2.66V. The theoretical voltage drop for R and G is 1.8V, while for B is 3.3V. The actual voltage across was greater for R and G and less for B.