3 LED Crossfade with PWM and Arduino
This ones quite simple, just mix/ crossfade 3 separate LEDs using Phase Width Modulation (PWM) and Arduino.
You will need 3 LEDs, I’m using a 5mm Red, Green and Blue so I can make the full light colour spectrum (When all combined they make white light). If you look at an LED you will see one pin is slightly longer of the 2, this is the positive (+) terminal, the shorter being negative. Make sure you get the LED the right way round.
You will also need 3 220 Ohm resistors to ensure that the LEDs dont get too much voltage/current. these have the following colour code: Red, Red, Brown, Gold. If you use a higher value such as 1 Kiloohm (1ooo Ohms) the LEDs will appear dim as they won’t get enough power. Unlike the LED it doesn’t matter which way round you use the resistors. I generally would recommend getting a kit of different types of resistors like this one here as its useful in the long run.
You will also need some jumper wires and you also need to have an Arduino board and know how to upload a sketch.
So a quick look at this basic circuit:
The Arduino board supplies the power to the LED via the digital PWM pins, meaning for this we don’t need to use the 5v pin. By using the chip and PWM to regulate the power, basically its a fancy way of saying we’re blinking the LED, we can effectively alter the brightness of the LED. So alot of the hardwork and potential coding we would need to do is taken care of for us.
I connect each digital pin (9,10 & 11) to an LED – I’ve used corresponding coloured wiring for this, e.g. red wire, red LED. I’ve placed a resistor between the wire and the LED to ensure that it doesn’t get too much juice. I then connect the negative pin of each LED to the negative rail on the breadboard and then that goes to the GND pin on the Arduino board completing the circuit.
Here’s my final circuit below, I’ve added a few labels to show you where thigns are connected and the +/- for the LEDs I’ve also added a few lines so you see where things line up.
The only thing left is to upload the following sketch, this sets a value for each LED, assigning it to a pin, the code then loops through incrementing the values between 1 and 255 for each LED. The counter in the code starts at 1 and increments up to 762 (254×3 – 254 values for each LED) before reseting to 1 to start the loop again.
For more detail: 3 LED Crossfade with PWM and Arduino
EasyEDA: Ideas for Circuit Design, Innovation for Electronics Access
Free Circuit Design: Schematic – Simulation – PCB Layout – Gerber Viewer
Cheapest PCB Prototype: Only $2 for 10pcs 10×10cm PCBs, 24 hours Quick Turn, DHL Delivery in 3 Days