Project system
Festival LED lights with an Arduino: a chaser, a fade and a 12 V strip
By Bulan Sarkar, founder of ElectronicsInfoline (since 2000) · About a 12-minute read
If you have an Arduino in a drawer, you can make your own Diwali lights with it. You need three small circuits, built in order: a chaser of eight LEDs, a fade, and a 12 V strip switched by a MOSFET.
This page takes you through all three, with the current in every LED worked out against the chip limits. It also tells you where to stop and buy a ready-made string instead.
Wire eight LEDs to pins D2 to D9 of an Arduino UNO, each through its own 330 Ω resistor, and step through them every 150 ms for a chaser. Each red LED then takes 9.1 mA, and all eight together 73 mA, well inside the ATmega328P's 200 mA limit. For a fade, use a PWM pin (3, 5, 6, 9, 10 or 11) with analogWrite(). For a 12 V LED strip, switch it with an IRLZ44N logic-level MOSFET from its own 12 V adapter, never from the Arduino's 5 V pin.
Build it, buy it, or get help
Build it yourself
You have an UNO or Nano, a breadboard and a USB cable, and you want a few dozen LEDs or one plain 12 V strip that you control yourself. Two to three evenings, no soldering needed until the final version.
Buy a module instead
You want more than about 50 individually coloured LEDs or a whole balcony: buy a WS2812B addressable strip or a ready-made 5 V USB string and drive the effects from the Arduino. Hand-wiring that many resistors is not worth it.
Stop and get help
Anything that plugs straight into 230 V mains. Do not cut, rewire or "upgrade" a mains serial-light set or a mains LED rope. Use certified products, and an electrician for any new socket or outdoor point. Everything on this page runs from USB or a ready-made 12 V adapter.
The steps, in order
1. Blink one LED and check the current
Have ready: Arduino UNO, USB cable, red LED, 220 Ω resistor, breadboard, 2 jumpers
Upload the Blink sketch with LED_BUILTIN changed to 8. Wire pin D8 through the 220 Ω resistor to the LED's long leg, and the short leg to GND. With a 2.0 V red LED that is (5 − 2.0) ÷ 220 = 13.6 mA. If this one LED works, your board, cable, driver and breadboard all work.
Check: LED blinks once a second
Figure 1. Step 1: one LED on D8 through 220 Ω, 13.6 mA. The same circuit as project 1 on our Arduino projects page. Figure 2. Step 1 on a breadboard: the long leg (anode) towards the resistor, the short leg to the GND jumper. 2. Wire the eight-LED chaser
Have ready: 8 LEDs, 8 × 330 Ω, 10 jumpers
Put eight LEDs along the breadboard, one per pin from D2 to D9, each with its own 330 Ω resistor and all cathodes on the GND rail. One resistor per LED, never one shared resistor for the lot: LEDs in parallel do not share current evenly. At 330 Ω each LED takes 9.1 mA, bright enough on a dark balcony.
Check: All 8 light with a test sketch that sets every pin HIGH
Figure 3. Step 2: eight LEDs on D2–D9, each with its own 330 Ω resistor, 9.1 mA each. 3. Write the chase pattern
Have ready: The chaser from step 2
Keep the pins in an array {2, 3, 4, 5, 6, 7, 8, 9}. In loop(), switch on pin i, wait 150 ms, switch it off and move to the next; one sweep takes 1200 ms. Then change the pattern: back and forth, two at a time, or fill up and empty. Use millis() instead of delay() once you want a button to change patterns.
Check: The light walks D2 → D9 and repeats
Figure 4. Step 3: which pin is on in each 150 ms step of a simple chase; one sweep takes 1200 ms. 4. Add a fade on a PWM pin
Have ready: The LED on D9 (a PWM pin)
analogWrite(9, value) switches D9 on and off 490 times a second, and the value from 0 to 255 sets how long it stays on. Ramp the value up and down in steps of 5 every 20 ms for a slow breathing glow. Only pins 3, 5, 6, 9, 10 and 11 can do this on an UNO or Nano; on any other pin analogWrite() just switches fully on or off at 128.
Check: D9 glows up and down smoothly, no flicker
Figure 5. Step 4: what analogWrite() puts on D9. The LED switches at 490 Hz, and your eye sees the average. 5. Check the current budget before you add more
Have ready: A pen, or the figure below
Add up what is on at the same time. A chaser has one LED on, 9.1 mA. A "fill up" pattern has all eight on, 73 mA. The datasheet's limits are 40 mA per pin and 200 mA through the chip as absolute maximums, and 150 mA for the group of pins D5 to D13 together; we stay at or under the 20 mA test current per pin. Our five LEDs on D5 to D9 take 45 mA together. For more LEDs per pin, use a transistor or a MOSFET (next step).
Check: Worst-case pattern total written down and under 150 mA
Figure 6. Step 5: current per pattern against the ATmega328P limits from the datasheet (p. 322–323). 6. Switch a 12 V LED strip with a MOSFET
Have ready: IRLZ44N, 330 Ω, 10 kΩ, 12 V adapter, DC jack, LED strip
Read the strip's label: our example is 5 m at 4.8 W per metre, 24 W, so 2.0 A at 12 V. Pick an adapter rated at least 2.5 A. The strip's + goes to the adapter's +12 V, its − to the MOSFET's drain; the source goes to GND. D9 drives the gate through 330 Ω, and 10 kΩ from gate to GND keeps the strip off while the Arduino boots. Join the adapter's ground to the Arduino's GND. At 2.0 A the IRLZ44N wastes about 100.0 mW, so no heatsink is needed. analogWrite(9, …) now fades the whole strip.
Check: Strip off at power-up, full on at 255, dims at 64
Figure 7. Step 6: a 24 W, 12 V strip switched by an IRLZ44N from D9, with its own adapter and a shared ground. 7. Move it to a board and put it up
Have ready: Perfboard or stripboard, soldering iron, enclosure, USB charger
Once the patterns are right, solder the resistors and a header for the LED leads onto a small perfboard, or use a Nano on the same board. Power it from a phone charger. Keep the 12 V and the LED wiring away from curtains and give the MOSFET some air. Label the plugs so nobody connects the 12 V adapter to the USB side.
Check: Runs 2 hours on the bench without anything getting warm
What goes wrong, and how to find it
| Symptom | Likely cause | Check and fix |
|---|---|---|
| The sketch will not upload | Wrong board or port selected, or a clone board with a CH340 USB chip and no driver. | Tools → Board → Arduino UNO, then pick the port that appears when you plug in. On a clone, install the CH340 driver. Unplug anything on D0 and D1 while uploading. |
| One LED never lights | LED in backwards, or it sits in the wrong breadboard row. | Long leg (anode) towards the resistor and the pin. Swap it round. Check the GND rail: on many breadboards it is split in the middle. |
| Every LED is dim | Resistors too large (a 3.3 kΩ read as 330 Ω), or the pin is still an INPUT. | Read the bands: 330 Ω is orange, orange, brown. Check pinMode(pin, OUTPUT) in setup(). A pin left as INPUT only drives the LED through the weak pull-up. |
| The fade jumps between off and full | The LED is on a pin that has no PWM. | Move it to 3, 5, 6, 9, 10 or 11. If you also use tone(), avoid 3 and 11. |
| The strip stays on, or flickers when the board resets | No 10 kΩ pull-down, so the gate floats; or an IRFZ44N used instead of the IRLZ44N. | Fit 10 kΩ from gate to GND. Check the part number: the IRFZ44N needs about 10 V on the gate and stays half on from 5 V, so it gets hot. |
| The Arduino resets when the strip comes on | Missing common ground, or the 12 V and 5 V grounds joined by a thin, long wire. | Run one short, thick ground from the adapter to the MOSFET source and a separate one to Arduino GND. Never power the strip from the Arduino 5 V pin. |
Variants
5 V LEDs on the pins vs a 12 V strip
Up to eight single LEDs run straight off the pins at 5 V (steps 1–5). A strip or anything over 20 mA per channel needs a MOSFET and its own supply (step 6). The code is the same for both.
Through-hole on a breadboard vs a ready module
Breadboard and through-hole parts teach the circuit. For a permanent display, a WS2812B strip needs one data pin and no resistors per LED, but it needs its own 5 V supply sized for the strip and a library such as FastLED.
Arduino UNO/Nano vs ESP32
An ESP32 pin gives 3.3 V, not 5 V. With a red LED, 330 Ω gives only about 4 mA, so use 100 Ω for about 13 mA. The IRLZ44N is specified with 4 V or more on the gate, so from 3.3 V choose a MOSFET with RDS(on) specified at 2.5 V. In return you get Wi-Fi control from your phone.
What we would do
Build the chaser first, on a breadboard, with 330 Ω resistors: it teaches pin current and resistor choice in one evening. Then add one 12 V strip on an IRLZ44N for the main glow. If you find yourself wanting more than about 50 LEDs or colour effects, stop hand-wiring and buy a WS2812B strip with its own 5 V supply. Leave mains-powered lights to certified products.
Tips and tricks
- Buy the LEDs in one colour from one bag. Red, green and blue LEDs drop different voltages, so the same resistor gives a blue LED far less current than a red one.
- Put the pin numbers in an array at the top of the sketch. Then a new pattern is a new loop, not eight new lines.
- Diffuse the LEDs. A strip of tracing paper or the inside of a paper lantern hides the bright dot and makes 9 mA look like more.
- Test the worst pattern first. Run "all on" for ten minutes before you put the lights up; that is when an undersized adapter or a missing pull-down shows.
- Label both power plugs. A 12 V adapter pushed into the wrong jack is the quickest way to destroy the board.
Print the working copy
One A4 page for the bench: the parts list as a checklist, every connection with a tick box, and the tests with the readings to expect. It prints in black and white.
Source and assumptions
Microchip ATmega48A/PA/88A/PA/168A/PA/328/P datasheet, DS40002061B. p. 322: 40 mA DC per I/O pin and 200 mA through VCC and GND (absolute maximum); p. 323, notes 3 and 4: 20 mA test current at 5 V, 150 mA total source current per pin group, 100 mA total sink current per group. Checked 6 October 2026.
Our own choices, not taken from the datasheet: the 2.0 V red LED drop, the 330 Ω and 220 Ω resistors, the 150 ms step, the pin assignment, and the example strip (5 m at 4.8 W/m, 12 V) with a 25 % adapter margin. The IRLZ44N's 0.025 Ω RDS(on) at 5 V is from the Infineon datasheet.
Questions people ask
How many LEDs can an Arduino UNO drive directly? Plan on one standard LED per pin at 10 to 20 mA, and keep the total under about 150 mA. At 330 Ω each red LED takes 9.1 mA, so eight lit together take 73 mA. The datasheet's absolute maximum is 40 mA per pin and 200 mA for the whole chip; for more, use a transistor or MOSFET per channel.
Can I power a 12 V LED strip from the Arduino? No. The strip needs its own 12 V adapter. The Arduino only switches it, through a logic-level MOSFET such as the IRLZ44N, with the two grounds joined.
Why does my LED strip not turn fully off? The MOSFET gate is floating, or the MOSFET is not logic-level. Fit a 10 kΩ resistor from gate to ground and check that the part is an IRLZ44N, not an IRFZ44N.
Tools and guides this system uses
- 15 Arduino projectsThe blink, traffic-light and PWM projects this system builds on.
- LED resistor calculatorResistor and wattage for other LED colours and supplies.
- Resistor colour codeTell 330 Ω from 3.3 kΩ before you solder.
- LED circuitsWhy each LED needs its own resistor.
- Duty cycle and PWMHow a switching pin looks like a dimmer.
- 555 LED flasher systemBlinking lights with no code and no Arduino.
All build systems: Build systems.