The rise of LED lighting has been stratospheric and it’s easy to see why. They are cheap to manufacture, use significantly less energy than other lighting options, and do not heat up in most cases, making them safe for a variety of applications.

One of the most common LED products is the LED strip. In this article, we will cover how to set up the two most common types with Arduino. These projects are very simple and even if you are new to Arduino: or DIY electronics you can do it.

We will also use the Arduino IDE to control them. This project uses an Arduino Uno, although you can use just about any compatible board (e.g. NodeMCU.).

Choose your lane

When shopping for LED strips, there are a few things to consider. First, it’s functionality. If you plan to use the strips primarily for ambient lighting, then a simple LED band RGB 12V ( SMD5050 ).

Many of these strips come with an infrared remote to control them, although for this project we will be using an Arduino instead. Spend some time shopping, at the time of writing you could get these strips for as little as $1 a meter.

LED strips
Image credit: phanu suwannarat via Shutterstock

If you want something a little higher, consider WS2811 / 12 / 12B . These bands (sometimes called neopixels ) have built-in chipsets that allow them to be accessed individually. This means that they are capable of more than just ambient lighting.

You can use them to make a cheap LED pixel display from scratch. You can even use them to make your own storm cloud light fixture.

LED display

These strips only require 5V to power them. Although they can be powered in small portions directly from the Arduino board, it is generally recommended to use a separate 5V power supply to keep yourself from the smell of a fried Arduino. If you are looking for individually programmable LEDs, these are for you. At the time of writing, they are available for about $4 per meter.

Another thing to consider is where these bands can be used. Both types of strips come in different lengths, LED densities (number of LEDs per meter) and varying degrees of weather protection.

When looking at LED strips, pay attention to the numbers in the listing. Usually the first number is the number of LEDs per meter, and the letters IP and numbers are weather protection. For example, if the list says 30 IP67 this means that the meter will account for thirty LEDs. 6 means that it is completely sealed from dust, and 7 means that it is protected from temporary immersion in water. Let’s start with SMD5050.

In touch

Requires electronic components

To connect a 12V LED strip to an Arduino, you will need a few components:

  • 12v RGB led strip ( SMD5050 )
  • 1 x Arduino Uno (any compatible board will do)
  • Resistors 3 x ten kOhm
  • 3 x N-channel MOSFETs with logic level
  • 1 x breadboard
  • Connecting wires
  • 12v power supply

Before setting up the schema, let’s talk about MOSFETs .

Whenever you are driving something that is at a higher voltage than your microcontroller, you need something in between to keep your board from frying. One of the easier ways to do this is to use a MOSFET. By sending pulse width modulation signals ( PWM ) per branch shutter you can control how much energy passes between the branches runoff and source . By passing each of the LED strips through a MOSFET, you can control the brightness of each individual color on the LED strip.

When using microcontrollers, it’s important to use logic level components to ensure everything works the way you want. Make sure your MOSFETs are logic level and are not standard .

Set up your schema like this:

Arduino MOSFET Circuit

  1. Connect Arduino Pins 9 , 6 and 5 to gate branches three MOSFETs and connect a resistor ten kOhm on the line of each to the ground bus.
  2. Connect the legs source to the ground bar.
  3. Connect drain legs to green , red and blue connectors on the LED strip.
  4. Connect the power rail to the connector + 12V led strip (note that the power wire is black in this image to match the colors of the connectors on my led strip).
  5. Connect the Arduino ground to the ground rail.
  6. Connect a 12V power supply to tires nutrition.

Most LED strips have Dupont connectors that are easy to connect to. If you don’t, you may need to solder wires to the LED strip. Don’t panic if you are new to soldering, it’s an easy job and we have a guide to getting started with soldering. if you need it.

We will be powering our Arduino board via USB for this project. You can power up your board using the VIN pin, but before doing so, make sure you know the power limits for your board.

When your circuit is complete, it should look something like this:

Arduino MOSFETs on a Breadboard

Now that you’ve got everything connected, it’s time to make a simple Arduino sketch to control it.

fade it up

Connect the Arduino board to your computer via USB and open the Arduino IDE. Make sure you have the correct board and port number selected for your board in menu Tools> Fee and Tools> Menu ports . Open a new sketch and save it with an appropriate name.

This sketch will fade the lights out one color at a time, keep them on for a few seconds, and then fade out until they turn off again. You can go here and sketch it yourself, or just download the full code from GitHub.

Start by determining which contacts will be used to drive the MOSFETs.

#define RED_LED 6 #define BLUE_LED 5 #define GREEN_LED 9 

Next, you need a few variables. Create a shared variable brightness along with a variable for the brightness of each individual color. We will only be using the main brightness variable to turn off the LEDs, so set the maximum brightness value here to 255.

You will also need to create a variable to control the fade rate.

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

In your function settings we’ll set our Arduino pins to a pin. We will also call several functions with a 5 second delay between them. These features don’t exist yet, 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 a method TurnOn() :

 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 += 1; delay(fadeSpeed); } for (int i = 0; i < 256; i++) { analogWrite(GREEN_LED, gBright); gBright +=1; delay(fadeSpeed); } } 

These three cycle for take each color to full brightness for the time specified by the value fadeSpeed .

Finally you need to create a method turnoff() :

 void TurnOff() { for (int i = 0; i < 256; i++) { analogWrite(GREEN_LED, brightness); analogWrite(RED_LED, brightness); analogWrite(BLUE_LED, brightness); brightness -= 1; delay(fadeSpeed); } } void loop() { } 

This method applies our variable brightness to all three color outputs and reduces them to zero within a certain period of time. Here we also need an empty loop method to avoid compilation errors.

Once you've completed this sketch, save it. Check the sketch and upload it to your Arduino board. If you get errors, check your code again for annoying typos or missing semicolons.

You should now see your LED strip boosting each color individually, holding white for 5 seconds and then fading evenly to zero:

LED strip flashing

If you have any difficulty, double check your wiring and check the code again.

This project is an easy way to get started, but the ideas in it can be extended to create really effective lighting. With just a few components, you can create your own sunrise alarm clock create an alarm clock If you have a starter kit with your Arduino included you can use any button or sensor to turn on the LEDs when you enter the room, for example:

Arduino Motion Controlled Lighting

Now that we have considered SMD5050 let's move on to the stripes WS2812B .

Bright Ideas

These strips require fewer components to run, and there is some leeway as to which component values ​​you can use. The capacitor in this circuit ensures that the 5V LEDs receive a constant power supply. The resistor ensures that there is no signal from the data received from the Arduino.

You will need:

  • WS2811 / 12 / 12B 5V LED strip (all three models have built-in chips and work almost the same)
  • 1 x Arduino Uno (or similar compatible board)
  • 1 x 220-440 ohm Resistor (anything between these two values ​​is fine)
  • 1 x 100-1000uF capacitor (anything between these two values ​​is fine)
  • Layout and wire connection
  • 5V power supply

Set up your circuit as shown in the diagram:

arduino circuit

Note that the capacitor must be in the correct orientation. You can tell which side is attached to the ground rail by looking at the capacitor body with a minus (-) sign.

This time we are powering the Arduino from a 5V power supply. This makes the project self-contained when we're done, although there are a few important points here.

First, make sure your board can receive 5V power before connecting it to a power source. Almost all development boards run at 5V via the USB port, but some power pins can sometimes bypass voltage regulators and turn them into toast.

Also, it's a good idea to make sure that multiple separate power supplies are not connected to the Arduino - unplug the USB cable whenever you use an external power supply.

Once connected, it should look like this:

Arduino Complete Circuit

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

dancing lights

To safely program our board, disconnect the line VIN from the power line. You will attach it later.

Connect your Arduino to your computer and open the Arduino IDE. Make sure the menu Tools> Fee and Tools> Ports menu correct board and number selected port .

We will use the library fast LED to test our setup. You can add a library by clicking 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 thumbnail DemoReel100 . This sketch is cyclic repeats various actions that can be performed with help LED strips WS2812 and incredibly easy to set up.

All you need to change is the variable DATA PIN, to make it match conclusion 13 and variable NUM_LEDS, to determine how many LEDs are in the strip you are using. In this case, I only use a small line of 10 LEDs cut from a longer strip. Use more for more light show!

arduino code

This is it! Upload the sketch to your board, unplug the USB cable, and turn on the 5V power. Finally, reconnect the VIN of the Arduino to the power line and watch the show!

Arduino finished circuit

If nothing happens, check the wiring and make sure you have the correct Arduino pin on the demo sketch.

Limitless Possibilities

The demo shows some of the many possible combinations of effects that can be achieved with the WS2812 strips. In addition to being a step ahead of conventional LED strips, they can also be used in practice. A good next project would be to create your own backlight. for your media center.

While these strips are definitely more functional than the SMD5050, don't discount the standard 12V LED strips just yet. They are unbeatable in terms of price and there are a huge number of uses for LED strips. light up the ribbons light up the ribbons

Learning how to work with LED strips is a good way to learn the basics of Arduino programming, but the best way to learn is to tinker. Modify the above code and see what you can do! If all this was too much for you, consider starting with these Arduino projects for beginners.

Image Credits: mkarco/shutterstock

Похожие записи