The ascent of LED lighting has been stratospheric, and it's easy to meet why. They are cheap to produce, swallow significantly less ability than other lighting options, and in most cases don't get hot, making them safety for a diverseness of uses.

One of the near mutual LED products is the LED strip. In this article, nosotros volition embrace how to set upward the two nigh common types with an Arduino. These projects are very elementary, and even if you are a beginner with Arduino or DIY electronics, y'all will exist able to do this.

We volition also use the Arduino IDE to control them. This projection uses an Arduino Uno, though you could use well-nigh whatever compatible board (such equally the NodeMCU).

Cull Your Strip

When shopping for LED strips there are a few things to consider. First is functionality. If you are planning to apply the strips mostly for ambience lighting, and so a unproblematic 12v RGB LED strip (SMD5050) would exist the correct choice.

Many of these strips come with an infrared remote to control them, though in this project we will be using an Arduino to instead. Spend a little time shopping around, at the fourth dimension of writing information technology was possible to become these strips for as little as $ane per meter.

LED Strip Lights
Image Credit: phanu suwannarat via Shutterstock

If you want something a piffling higher tech, consider the WS2811/12/12B. These strips (sometimes referred to as Neopixels) take integrated chipsets which allow them to be addressed individually. This means they are capable of more than than just ambience lighting.

Yous can use them to build a cheap LED pixel display from scratch. You can fifty-fifty use them to make your ain personal indoor tempest cloud lamp.

LED Pixel Display

These strips only require 5v to power them. While information technology is possible to power pocket-sized amounts of them directly from an Arduino board, it is more often than not a practiced idea to use a split 5V power supply to save yourself from the odour of fried Arduino. If you are looking for individually programmable LEDs, these are for you. At the time of writing, they are available for around $4 per meter.

Some other matter to consider is where these strips are probable to be used. Both of these types of strip come in varying lengths, LED densities (the number of LEDs per meter), and differing degrees of weatherproofing.

When looking at LED strips, pay attention to the numbers on the listing. Usually, the first number volition be the number of LEDs per meter, and the letters IP followed by numbers will exist its weatherproofing. For example, if the list says 30 IP67, this means there will exist 30 LEDs per meter. The half dozen denotes it is completely sealed from dust, and the seven means information technology is protected against temporary submersion in water. (Learn more most weatherproofing and IP ratings.) Once you have your chosen LED strip, it'due south fourth dimension to link information technology upwardly with an Arduino. Let's starting time with the SMD5050.

Getting Connected

Electronic Components Required

In order to connect upwards a 12v LED strip to an Arduino, you will need a few components:

  • 12v RGB LED strip (SMD5050)
  • 1 ten Arduino Uno (whatever uniform lath will do)
  • three x 10k Ohm Resistors
  • 3 10 Logic Level Due north-channel MOSFETs
  • 1 10 Breadboard
  • Hookup wires
  • 12v Power Supply

Earlier setting up the excursion, let's talk about MOSFETs.

Whenever you are decision-making something which is higher voltage than your microcontroller, you lot need something in between to stop your board getting fried. One of the simpler means to practice this is to use a MOSFET. Past sending pulse width modulation (PWM) signals to the gate leg, it's possible to control how much ability passes betwixt the bleed and source legs. Past passing each of the LED strip'southward colors through the MOSFET, you can control the brightness of each individual color on the LED strip.

When using microcontrollers, it is important to employ logic level components in club to ensure things work the way y'all desire them to. Brand certain your MOSFETs are logic level and not standard.

Prepare your excursion like this:

Arduino MOSFET Circuit
  1. Connect Arduino pins 9, 6, and five to the gate legs of the three MOSFETs, and connect a 10k resistor in line with each to the ground rail.
  2. Connect the Source legs to the ground rail.
  3. Connect the Drain legs to the Green, Red, and Blue connectors on the LED strip.
  4. Connect the ability rail to the +12v connector of the LED strip (note that in this image the power wire is black to friction match the colors of the connectors on my LED strip).
  5. Connect the Arduino ground to the ground rail.
  6. Connect your 12v power supply to the power rails.

Almost LED strips have Dupont [Cleaved URL Removed] connectors, which are easy to connect to. If yours don't you may need to solder wires to the LED strip. Don't panic if you lot are fairly new to soldering, it'due south an easy chore, and nosotros take a guide to getting started with soldering should yous need it.

We will be powering our Arduino board by USB for this project. Yous could choose to power your lath using the VIN pin, but make sure you know the ability limitations for your lath before doing this.

When your circuit is complete information technology should look something like this:

Arduino MOSFETs on Breadboard

At present that y'all take continued everything, information technology's time to make a simple Arduino sketch to command it.

Fade Information technology Up

Connect your Arduino board to your computer via USB and open upwards the Arduino IDE. Make sure you have the correct lath and port number selected for your board in the Tools > Board and Tools > Port menus. Open a new sketch and salve it with an appropriate name.

This sketch will fade the lights in 1 color at a time, keep them on for a few seconds, and so fade them out until they are off again. You can follow through here and make the sketch yourself, or only download the consummate code from GitHub.

Begin by defining which pins will be used to control the MOSFETs.

          #define RED_LED 6
#define BLUE_LED v
#define GREEN_LED 9

Next you need some variables. Create an overall brightness variable, along with a variable for each individual color'due south brightness. Nosotros will but exist using the main brightness variable for turning the LEDs off, and then set up it to the maximum brightness value of 255 here.

you lot will also need to create a variable to control how fast the fading volition happen.

          int brightness = 255;
int gBright = 0;
int rBright = 0;
int bBright = 0;
int fadeSpeed = 10;

In your setup function nosotros will set up our Arduino pins to output. We will also telephone call a couple of functions with a 5 second delay in betwixt. These functions don't exist nevertheless, but don't worry, we'll get to them.

          void setup() {
pinMode(GREEN_LED, OUTPUT);
pinMode(RED_LED, OUTPUT);
pinMode(BLUE_LED, OUTPUT);
TurnOn();
delay(5000);
TurnOff();
}

Now create the TurnOn() method:

          void TurnOn() {            
for (int i = 0; i < 256; i++) {
analogWrite(RED_LED, rBright);
rBright +=1;
delay(fadeSpeed);
}

for (int i = 0; i < 256; i++) {
analogWrite(BLUE_LED, bBright);
bBright += i;
delay(fadeSpeed);
}
for (int i = 0; i < 256; i++) {
analogWrite(GREEN_LED, gBright);
gBright +=1;
delay(fadeSpeed);
}
}

These three for loops take each color up to its full brightness over a time specified past the fadeSpeed value.

Finally y'all need to create the TurnOff() method:

          void TurnOff() {
for (int i = 0; i < 256; i++) {
analogWrite(GREEN_LED, brightness);
analogWrite(RED_LED, effulgence);
analogWrite(BLUE_LED, effulgence);

effulgence -= 1;
filibuster(fadeSpeed);
}
}
void loop() {
}

This method applies our brightness variable to all three color pins and reduces them to zilch over a period of time. We need an empty loop method here too, in lodge to avert compilation errors.

Once you have completed this sketch, save it. Verify the sketch and upload it to your Arduino board. If you are getting errors, check through the code again for any pesky typos or missing semicolons.

Now you lot should see your LED strip ramp upward each color individually, belongings the white color for v seconds, and then uniformly fade to goose egg:

If you are having any difficulties, double check your wiring and lawmaking over again.

This project is a simple fashion to get started, but the ideas covered in it can be expanded on to make really effective lighting. With just a few more components y'all could create your own sunrise alert. If you got a starter kit with your Arduino you could use whatsoever button or sensor to trigger your LEDs when yous enter the room, for example:

Now that nosotros have covered the SMD5050s, allow's motion on to the WS2812B strips.

Vivid Ideas

These strips crave fewer components to get them running, and at that place is some leeway as to exactly what values of components you can use. The capacitor in this circuit makes sure that the 5v LEDs go a steady ability supply. The resistor ensures the information betoken received from the Arduino is gratuitous from any interference.

You volition need:

  • WS2811/12/12B 5v LED strip (all three models accept integrated fries and piece of work much the same way)
  • one x Arduino Uno (or similar uniform board)
  • 1 x 220-440 Ohm Resistor (anything between these ii values is fine)
  • 1 x 100-thou microFarad Capacitor (anything betwixt these two values is fine)
  • Breadboard and hook upwards wires
  • 5V power supply

Gear up your excursion every bit shown in the diagram:

Arduino Circuit

Take note that the capacitor must be the correct orientation. You lot tin can tell which side attaches to the ground track by looking for the minus (-) sign on the body of the capacitor.

This time circular we are powering the Arduino using the 5v Power supply. This makes the projection stand lonely once we are done, though in that location are important things to note here.

Firstly, make certain that your lath can have 5v ability in before attaching it to the power source. Virtually all development boards run at 5v through the USB port, just the power input pins on some can sometimes skip the voltage regulators and turn them into toast.

Also, it is good practice to make sure that multiple separate power sources are non connected to the Arduino -- disconnect the USB cable whenever you are using an external power supply.

Once yous are plugged in it should look similar this:

Arduino Completed Circuit

Now that our LED strip is wired in, let's move on to the code.

Dancing Lights

In order to safely program our board, disconnect the VIN line from the power line. Y'all'll reattach it after.

Attach your Arduino to the computer and open the Arduino IDE. Check that you have the correct board and port number selected in the Tools > Board and Tools > Port menus.

Nosotros will be using the FastLED library to test out our setup. You can add the library by clicking on Sketch > Include Library > Manage Libraries and searching for FastLED. Click install, and the library will be added to the IDE.

Under File > Examples > FastLED select the DemoReel100 sketch. This sketch cycles various things which can be done with the WS2812 LED strips, and is incredibly easy to gear up.

All you need to change is the DATA_PIN variable so that information technology matches pivot 13, and the NUM_LEDS variable to define how many LEDs are in the strip you lot are using. In this case, I am using simply a minor line of ten LEDS cut from a longer strip. Use more than for a bigger calorie-free testify!

Arduino Code

That'south it! Upload the sketch to your lath, disconnect the USB cablevision and turn on your 5v ability supply. Finally, reattach the Arduino's VIN to the power line and watch the show!

Arduino Finished Circuit

If nothing happens, cheque over your wiring and that you specified the correct Arduino pin in the demo sketch.

Endless Possibilities

The demo sketch shows off some of the many possible combinations of effects that tin exist achieved with the WS2812 strips. Alongside beingness a step up from regular LED strips, they tin can be put to practical utilize too. A good adjacent projection would be edifice your own ambilight for your media eye.

While these strips are definitely more functional than the SMD5050s, don't disbelieve the standard 12v LED strips quite nevertheless. They are unbeatable in terms of price, and there are a huge number of applications for LED low-cal strips.

Learning to work with LED strips is a good way to get familiar with bones programming on the Arduino, but the all-time way to learn is by tinkering. Modify the to a higher place code and see what you tin can practise! If all of this was a bit besides much for yous, consider starting with these Arduino projects for beginners.

Image Credits: mkarco/Shutterstock

How to Run a Linux Desktop Using the Windows Subsystem for Linux

Read Next

About The Author