logo-mobile

ROHM

ROHM
Menu
  • Arduino –
  • Raspberry Pi –
  • Trending –
  • Others –
  • About –
  • Contact –

Arduino

How to Add an RGB LED Strip to Your Home Lighting

DevicePlus Editorial Team
Published by DevicePlus Editorial Team at January 15, 2021
Categories
  • Arduino
Tags

LEDs are a quick and simple way to add a splash of color to your home, applying strips of LEDs to the underside of your kitchen cabinets, in corners of a living room, or anywhere else that could use a bit of extra lighting. If you want to make your own lighting on the cheap—and have more control over the colors and patterns of your lighting—you can use an Arduino to do it.

How LED Strips Work

LED strips come in a variety of forms, but in general, most models feature a long strip with LED modules placed periodically along it, and the occasional dotted line where you can cut the strip if you need to. These spots are usually marked with metal contacts so you can add additional wiring to connect multiple pieces of a strip together. At the end, you’ll see a few wires that you can plug into your Arduino.

The number of wires can vary, but for this guide, we’ll be using a strip that contains its own control circuit that lets you address each individual LED using a single wire. There’s an additional power and ground wire, meaning you only need three wires for the whole project. Since this type of strip is generally more convenient, we’ll be using this type, specifically, a WS2812B-based LED strip.

LED strips can be controlled using external libraries, such as FastLED or Adafruit’s Neopixel library. For this guide, we’ll use the FastLED library, which contains functions for controlling a wide array of LED strip controllers and makes it easy to set colors or animation patterns.

To add the library to your sketch, download the library here. Then, in your Arduino IDE, head to Sketch > Include library > Add .ZIP library… and choose the FastLED library. This will also provide a selection of example sketches in the Examples section of the File menu, so take a look through those as you explore. For now, though, we’ll start simply by setting each LED to the same color.

What You’ll Need

You can buy as many or as few LED strips as you need to cover your room, though keep in mind that each LED draws power. For just a few LEDs, you can use the 5V power on the Arduino, but for a substantial number of LEDs, you’ll want an external power source. We’ll do this project using just the Arduino, but it’s something to be aware of as you scale your project. With that in mind, here’s what you’ll need:

An LED strip
Power source (for large strips)
Arduino Uno
Arduino IDE
USB Cable
Wiring

The wiring on this project is relatively straightforward, since we chose an addressable LED strip. But first, let’s start with the code we’ll be using.

The Code

Since we’re using the FastLED library, the code for this example will be fairly simple. We’re going to instruct the Arduino to turn on each LED in sequence and set it to a color. First, here’s the full code, which you can upload to your Arduino Uno.

#include <FastLED.h>

#define numberOfLEDs 100
#define controlPin 5

CRGB leds[numberOfLEDs];

void setup() {
FastLED.addLeds<WS2812B, controlPin, GRB>(leds, numberOfLEDs);}

void loop() {
for (int thisLED = 0; thisLED < numberOfLEDs; thisLED++) {
leds[thisLED].r = 50;
leds[thisLED].b = 0;
leds[thisLED].g = 0;
FastLED.show();
}

}

Now, let’s go through a few things this code does.

#include <FastLED.h>

#define numberOfLEDs 100
#define controlPin 5

CRGB leds[numberOfLEDs];

The first line here will include the FastLED library, so you can use its functions in your sketch. The next two lines will define a pair of constants that correspond with the number of LEDs you want to control on your strip—this can be just a portion of your LED strip if you want!—and the pin on your Arduino board that you’ll use to control them. Finally, the CRGB line will create an array with the number of LEDs you specified above.

For this example, we’ll use 10 LEDs, which should be few enough that the Arduino can supply enough power to the strip on its own, so we can demonstrate how this works.

void setup() {
FastLED.addLeds<WS2812B, controlPin, GRB>(leds, numberOfLEDs);
}

This single line sets up the LEDs using the controller chipset that corresponds with your LED strip. This line can vary based on the strip you get, and you may need to check the FastLED documentation to find the right version of this line for you. FastLED’s Blink sketch (which is different from the Blink sketch that comes built into the Arduino IDE) includes a long collection of these lines for a variety of chipsets. If you’re using the WS2812B, this line should work as is.

void loop() {
for (int thisLED = 0; thisLED < numberOfLEDs; thisLED++) {
leds[thisLED].r = 50;
leds[thisLED].b = 0;
leds[thisLED].g = 0;
FastLED.show();
}

}

In this section, the for() loop will run through each LED in the array and turn them on one by one. The three lines beginning with leds[] will set the color of the LED using a combination of red, green, and blue values up to 255 each. You can try playing with these values to change the color of the LEDs. Setting all three values to 0 will turn the LED off entirely.

The Wiring

Since we chose a simple LED strip, the wiring for this project is, likewise, very simple. You’ll only need three wires:

● Connect the 5V wire coming off of the LED strip to 5V on your Arduino (for just a few LEDs) or to a power source (for a long strip of many LEDs).
● Connect the GND on your LED strip to GND on your Arduino.
● Connect the middle wire (sometimes labeled DIN) to pin 5 on your Arduino.

Once all three wires are connected, supply power to your Arduino (and your LED strip, if using a separate power source), and your lights should turn on. Try playing around with the code to change the colors or write more complex animations. The FastLED library also comes with some pre-built sketches you can explore for even more choices.

DevicePlus Editorial Team
DevicePlus Editorial Team

Check us out on Social Media

  • Facebook
  • Twitter

Recommended Posts

  • Let’s Make Arduino LED Holiday LightingLet’s Make Arduino LED Holiday Lighting
  • Let’s Make Arduino LED Holiday Lighting using Proximity SensorLet’s Make Arduino LED Holiday Lighting using Proximity Sensor
  • Display characters with LEDs! How to use a matrix LEDDisplay characters with LEDs! How to use a matrix LED
  • How to Use a Relay to Control Lamp or Other High-Voltage ElectronicsHow to Use a Relay to Control Lamp or Other High-Voltage Electronics
  • Using Arduino with Parts and Sensors – Infrared Remote Control (Last Part)Using Arduino with Parts and Sensors – Infrared Remote Control (Last Part)
  • How to Create a Morse Code Generator Using ArduinoHow to Create a Morse Code Generator Using Arduino
Receive update on new postsPrivacy Policy

Recommended Tutorials

  • How to integrate an RFID module with Raspberry Pi How to integrate an RFID module with Raspberry Pi
  • How to Use the NRF24l01+ Module with Arduino How to Use the NRF24l01+ Module with Arduino
  • How to Run Arduino Sketches on Raspberry Pi How to Run Arduino Sketches on Raspberry Pi
  • Setting Up Raspberry Pi as a Home Media Server Setting Up Raspberry Pi as a Home Media Server

Recommended Trends

  • SewBot Is Revolutionizing the Clothing Manufacturing Industry SewBot Is Revolutionizing the Clothing Manufacturing Industry
  • All About The Sumo Robot Competition And Technology All About The Sumo Robot Competition And Technology
  • 5 Interesting Tips to Calculating the Forward Kinematics of a Robot 5 Interesting Tips to Calculating the Forward Kinematics of a Robot
  • Go Inside the Drones That Are Changing Food Delivery Go Inside the Drones That Are Changing Food Delivery
Menu
  • Arduino –
    Arduino Beginner’s Guide
  • Raspberry Pi –
    Raspberry Pi Beginner's Guide
  • Trending –
    Updates on New Technologies
  • Others –
    Interviews / Events / Others

Check us out on Social Media

  • Facebook
  • Twitter
  • About
  • Company
  • Privacy Policy
  • Terms of Service
  • Contact
  • Japanese
  • 简体中文
  • 繁體中文
Don’t Forget to Follow Us!
© Copyright 2016-2023. Device Plus - Powered by ROHM
© 2023 Device Plus. All Rights Reserved. Muffin group

istanbul escort istanbul escort istanbul escort