带有Arduino的WS2812B可寻址RGB LED灯条指南

这篇文章是关于WS2812B LED灯带的,这是一个可寻址的RGB LED灯带。这篇文章中的信息也适用于其他类似的LED灯条,例如 WS28XX系列的灯条,Neopixel灯条等。

WS2812B LED灯带介绍

WS2812B可寻址LED灯带有几种型号,尺寸,密封胶或LED密度不同。选择最适合您目的的一种。

去哪买?

您可以访问Maker Advisor并找到WS2812B RGB LED灯条的最优惠价格。

在下图中,您可以看到我的WS2812B LED灯条。它长5米,LED封装在防风雨的硅树脂中。因此,它们可以不受雨淋和灰尘的影响而留在外面。

在我看来,这是最酷的LED灯条类型。您可以控制亮度颜色的每个LED的独立,它可以让你产生一种简单的方式惊人的,复杂的影响。

该LED灯条由串联连接的WS2812B LED制成。这些LED的LED内建有一个IC。这允许通过单线接口进行通信。这意味着您仅需使用Arduino的一个数字引脚即可控制许多LED

在下图中,您可以看到LED内的芯片。LED是RGB LED,工作原理是这样的。

这种条非常灵活,可以切成您想要的任何长度。如您所见,该条带分为多个段,每个段包含一个RGB LED。

您可以通过在合适的地方用剪刀剪裁条来调整其大小(标出了剪裁条的正确位置)。

这些条带的两端均带有连接器。我决定剪掉连接器和焊头引脚。如果您要将条带连接到Arduino或面包板,则更加方便。

给WS2812B LED灯条供电

LED灯条应使用5V电源供电。设置为全亮度时,在5V电压下,每个LED消耗约50mA电流。这意味着每30个LED灯带可能会消耗1.5 A电流。请确保选择的电源符合灯带的需求。提供5V和2A的AC到DC电源适配器应该可以完成以下工作:

  • 5V 2A电源适配器

如果您使用外部电源,请不要忘记将电源接地线连接到Arduino接地线。

原理图

在此示例中,将使用5V Arduino引脚为WS2812B LED灯条供电。就我而言,我正在控制14个LED。如果要控制许多LED,则需要使用外部电源。

有用的 提示:

  • 从电源到地连接一个电容,其电容在100uF和1000uF之间,以平滑电源。
  • 在Arduino数字输出引脚和条形数据输入引脚之间添加一个220或470欧姆的电阻,以减少该线上的噪声。
  • 使您的arduino,电源和插排之间的电线尽可能短,以最大程度地减少电压损失。
  • 如果条带损坏并且无法正常工作,请检查第一个LED是否损坏。如果是这样,则将其切下,然后重新焊接排针,它应该可以再次工作。

代码

要控制WS2812B LED灯条,您需要下载FastLED库。

安装FastLED库

  1. 单击此处下载FastLED库。您的下载文件夹中应该有一个.zip文件夹
  2. 解压缩.zip文件夹,您应该得到FastLED-maste r文件夹
  3. 重命名您的文件夹 ~~FastLED主控~~到FastLED
  4. FastLED文件夹移至Arduino IDE安装文件夹
  5. 最后,重新打开您的Arduino IDE

安装所需的库后,将以下代码上传到Arduino板(这是库examples文件夹中提供的示例草图)。转到“文件” >“示例” >“ FastLED” >“ **ColorPalette”,**或复制以下代码。

#include <FastLED.h>#define LED_PIN     5
#define NUM_LEDS    14
#define BRIGHTNESS  64
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];#define UPDATES_PER_SECOND 100// This example shows several ways to set up and use 'palettes' of colors
// with FastLED.
//
// These compact palettes provide an easy way to re-colorize your
// animation on the fly, quickly, easily, and with low overhead.
//
// USING palettes is MUCH simpler in practice than in theory, so first just
// run this sketch, and watch the pretty lights as you then read through
// the code.  Although this sketch has eight (or more) different color schemes,
// the entire sketch compiles down to about 6.5K on AVR.
//
// FastLED provides a few pre-configured color palettes, and makes it
// extremely easy to make up your own color schemes with palettes.
//
// Some notes on the more abstract 'theory and practice' of
// FastLED compact palettes are at the bottom of this file.CRGBPalette16 currentPalette;
TBlendType    currentBlending;extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;void setup() {delay( 3000 ); // power-up safety delayFastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );FastLED.setBrightness(  BRIGHTNESS );currentPalette = RainbowColors_p;currentBlending = LINEARBLEND;
}void loop()
{ChangePalettePeriodically();static uint8_t startIndex = 0;startIndex = startIndex + 1; /* motion speed */FillLEDsFromPaletteColors( startIndex);FastLED.show();FastLED.delay(1000 / UPDATES_PER_SECOND);
}void FillLEDsFromPaletteColors( uint8_t colorIndex)
{uint8_t brightness = 255;for( int i = 0; i < NUM_LEDS; i++) {leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);colorIndex += 3;}
}// There are several different palettes of colors demonstrated here.
//
// FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,
// OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
//
// Additionally, you can manually define your own color palettes, or you can write
// code that creates color palettes on the fly.  All are shown here.void ChangePalettePeriodically()
{uint8_t secondHand = (millis() / 1000) % 60;static uint8_t lastSecond = 99;if( lastSecond != secondHand) {lastSecond = secondHand;if( secondHand ==  0)  { currentPalette = RainbowColors_p;         currentBlending = LINEARBLEND; }if( secondHand == 10)  { currentPalette = RainbowStripeColors_p;   currentBlending = NOBLEND;  }if( secondHand == 15)  { currentPalette = RainbowStripeColors_p;   currentBlending = LINEARBLEND; }if( secondHand == 20)  { SetupPurpleAndGreenPalette();             currentBlending = LINEARBLEND; }if( secondHand == 25)  { SetupTotallyRandomPalette();              currentBlending = LINEARBLEND; }if( secondHand == 30)  { SetupBlackAndWhiteStripedPalette();       currentBlending = NOBLEND; }if( secondHand == 35)  { SetupBlackAndWhiteStripedPalette();       currentBlending = LINEARBLEND; }if( secondHand == 40)  { currentPalette = CloudColors_p;           currentBlending = LINEARBLEND; }if( secondHand == 45)  { currentPalette = PartyColors_p;           currentBlending = LINEARBLEND; }if( secondHand == 50)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND;  }if( secondHand == 55)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }}
}// This function fills the palette with totally random colors.
void SetupTotallyRandomPalette()
{for( int i = 0; i < 16; i++) {currentPalette[i] = CHSV( random8(), 255, random8());}
}// This function sets up a palette of black and white stripes,
// using code.  Since the palette is effectively an array of
// sixteen CRGB colors, the various fill_* functions can be used
// to set them up.
void SetupBlackAndWhiteStripedPalette()
{// 'black out' all 16 palette entries...fill_solid( currentPalette, 16, CRGB::Black);// and set every fourth one to white.currentPalette[0] = CRGB::White;currentPalette[4] = CRGB::White;currentPalette[8] = CRGB::White;currentPalette[12] = CRGB::White;}// This function sets up a palette of purple and green stripes.
void SetupPurpleAndGreenPalette()
{CRGB purple = CHSV( HUE_PURPLE, 255, 255);CRGB green  = CHSV( HUE_GREEN, 255, 255);CRGB black  = CRGB::Black;currentPalette = CRGBPalette16(green,  green,  black,  black,purple, purple, black,  black,green,  green,  black,  black,purple, purple, black,  black );
}// This example shows how to set up a static color palette
// which is stored in PROGMEM (flash), which is almost always more
// plentiful than RAM.  A static PROGMEM palette like this
// takes up 64 bytes of flash.
const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{CRGB::Red,CRGB::Gray, // 'white' is too bright compared to red and blueCRGB::Blue,CRGB::Black,CRGB::Red,CRGB::Gray,CRGB::Blue,CRGB::Black,CRGB::Red,CRGB::Red,CRGB::Gray,CRGB::Gray,CRGB::Blue,CRGB::Blue,CRGB::Black,CRGB::Black
};// Additionl notes on FastLED compact palettes:
//
// Normally, in computer graphics, the palette (or "color lookup table")
// has 256 entries, each containing a specific 24-bit RGB color.  You can then
// index into the color palette using a simple 8-bit (one byte) value.
// A 256-entry color palette takes up 768 bytes of RAM, which on Arduino
// is quite possibly "too many" bytes.
//
// FastLED does offer traditional 256-element palettes, for setups that
// can afford the 768-byte cost in RAM.
//
// However, FastLED also offers a compact alternative.  FastLED offers
// palettes that store 16 distinct entries, but can be accessed AS IF
// they actually have 256 entries; this is accomplished by interpolating
// between the 16 explicit entries to create fifteen intermediate palette
// entries between each pair.
//
// So for example, if you set the first two explicit entries of a compact
// palette to Green (0,255,0) and Blue (0,0,255), and then retrieved
// the first sixteen entries from the virtual palette (of 256), you'd get
// Green, followed by a smooth gradient from green-to-blue, and then Blue.

查看原始代码

您必须将NUM_LEDS变量更改为LED灯带中的LED数量。在我们的示例中,LED灯带长14个LED。

#定义NUM_LEDS 14

如果要使用Arduino的另一个引脚来控制LED灯条,则需要更改LED_PIN变量:

#定义LED_PIN 5

示范

最后,这就是您将要拥有的。如此惊人的效果:

还有这个:

还有这个:

等等 (…)

使用LED灯条盒

这些LED灯带通常带有可移动胶带,因此您可以将它们粘贴在任何需要的地方。问题在于它们的粘着性不太好,因此可能是第二天您会在地板上找到条带。

解决方案:我发现这种带状盒子可以很好地散射光线,例如,如果您需要永久性解决方案,可以将其拧在架子上。

带有Arduino的WS2812B可寻址RGB LED灯条指南相关推荐

  1. 基于Arduino 的 WS2812B RGB LED 灯带指南

    基于Arduino 的 WS2812B 可寻址 RGB LED 灯带指南 前言 介绍 WS2812B LED 灯条 为 WS2812B LED 灯条供电 原理图 代码 示范 前言 这篇文章是关于WS2 ...

  2. 如何利用Arduino和TFT LCD操控NeoPixel LED灯条

    原文地址:https://circuitdigest.com/microcontroller-projects/neopixel-rgb-led-strip-with-arduino 如何利用Ardu ...

  3. ESP32 / ESP8266 RGB LED灯带配颜色选择器Web服务器

    在本项目中,我们将向您展示如何使用带有颜色选择器的网络服务器通过ESP8266或ESP32板远程控制RGB LED灯条.我们将控制5V RGB LED灯带,并且代码将用Arduino IDE编写. 在 ...

  4. 秒上手!使用Arduino控制基于WS2812B的LED灯条

    使用Arduino控制基于WS2812B的LED灯条 一.材料准备 硬件部分 1. Arduino UNO R3 开发板 2. 基于WS2812B的LED灯条 3. 杜邦线若干 软件部分 1. Ard ...

  5. 01. 全彩RGB LED灯模块使用教程

    全彩RGB LED灯模块使用教程 (适用于Arduino,micro:bit等常见单片机) 文章目录 全彩RGB LED灯模块使用教程 RGB灯模块简介 一.参数介绍 二.使用步骤 1.引脚说明 2. ...

  6. 使用无线WIFI模块NodeMCU Lua V3物联网开发板8266-01/01S 在Arduino搭建环境到点亮一个LED灯

    使用无线WIFI模块NodeMCU Lua V3物联网开发板8266-01/01S 在Arduino搭建环境到点亮一个LED灯 软件下载 基于Arduino环境搭建 点亮一个LED灯 上传成功 修改代 ...

  7. led七彩灯芯片IC 遥控变色RGB彩色灯条单片机方案设计 MCU软件

    ​ led七彩灯芯片IC 遥控变色RGB彩色灯条单片机方案设计 MCU软件 主要还有杰理,凌通,山景,炬力,建荣,三星,凌阳,佑华,义隆,松翰,九齐,Winbond.ALPHA.RTS.DT.GRAC ...

  8. arduinows2812灯条程序_Arduino 控制WS2812 LED灯条

    传统的LED限制总是很多,比如需要很多的引脚.所以有一种很好的解决方案是用灯条.理论上这种灯条可以通过通讯,用一根数据总线可以控制达到无上限个数的RGB-LED灯珠,并且在数量在1024以下时,延迟是 ...

  9. led灯条维修_led硅胶线条灯不亮的8大原因,怎样识别led灯带的质量

    1.led软灯条的包装保护不完善,在运输过程中会因撞击而损坏灯珠. 2.焊接质量不好,在弯曲过程中,LED柔性灯条的焊接点容易出现脆裂和脱落. 3.灯条安装时弯折角度过大,造成led柔性灯带焊点与铜箔 ...

  10. led灯条串联图_液晶电视维修:LED灯光电路原理,电路图原理分析?

    之前家里的电视背光不亮了,有声音,认为灯条坏了,换上后还是不亮,当时没时间修电路板,就直接换了一块电源板,今天找到电源板,仔细看了一下,查了下资料,当时应该是这个芯片或者外围元件损坏. 工作原理:LE ...

最新文章

  1. u盘文件看得见却打不开_win7下u盘文件打不开怎么办 win7下u盘文件打不开解决方法...
  2. 程序员该做的事 - 每天、每周、每月
  3. 初识德国的小朋友兴趣课程
  4. vscode setting json_win10+letex+vscode+texlive+latex workshop+sumatrapdf
  5. Linux下进程通信的八种方法
  6. python import如何使用_python之import引用
  7. Windows 10家庭版和专业版的区别在哪?Windows 10专业版好还是家庭版好?
  8. 旅游后台管理系列——SSM框架Service层整合
  9. arcmap新手教程_ArcMap 入门
  10. typedef使用方法
  11. 2019年Java春招汇总,技术类校招社招千道面试题,几百份大厂面经(附答案+考点)...
  12. 瞬变抑制二极管TVS原理简介
  13. linux c 操作word文档,C and Word and linux 总结.doc
  14. 某项目的双代号网络图如下所示_某工程项目的双代号网络计划如下图所示(时间单位:月)。...
  15. 计算机网络第一章概述
  16. 艺点动画-跟随原理讲解
  17. 星淘惠:四川一地获批设立跨境电子商务综合试验区跨境电商再添新砖
  18. jaccard相似度算法
  19. 如何设置谷歌浏览器背景图片
  20. 基于椭球 磁补偿 matlab,基于椭球拟合的三轴磁传感器误差补偿方法.pdf

热门文章

  1. 牛客小白月赛1分元宵
  2. 【MILP】Mixed-Integer Quadratic Programming portfolio optimzation
  3. 论文解读(PairNorm)《PairNorm: Tackling Oversmoothing in GNNs》
  4. Windows10正式版为什么没有休眠选项?
  5. android项目版本,怎查看Android项目的Android版本
  6. 洛谷 Floating point exception: 8 Floating-point exception. 报错
  7. 深入浅出matplotlib(9):知道两点坐标画直线
  8. 清理docker产生的垃圾文件
  9. crucible-4.8.2更改mysql5.7数据库报错User ‘crucible‘ has exceeded the ‘max_questions‘ resource
  10. 那些年常见的前端bug (持续更新)