detail.tmall.com
✨
使用 Arduino + WS2812B 创建随环境变化的可遥控灯带
Posted at Oct 31 · Edited at Nov 27
准备
物品
必要的
- Arduino Uno ×1
- 不同类型的杜邦线 ×若干
- 螺丝刀 x1 用于打开电源适配器端子
- 电烙铁 x1 用于连接电源输出的导线和灯带连接器的铜芯
- ≈ 22 AWG 适当长度导线 ×2 用于接入电源适配器输出,你应该准备两种不同颜色便于区分正负极
- 三线插头的电线 ×1 AC220V 用于连接市电和电源适配器,另一头需剪断 输入电压规格可能会根据你所处的国家不同,请以实际为准 你还可以直接购买即插即用的电源适配器来避免该装置存在的安全隐患,但需注意其输出规格
- 电源适配器 ×1 需购买的输入电压规格可能会根据你所处的国家不同,请以实际为准 该装置存在一定安全隐患,你还可以直接购买即插即用的电源适配器,但需注意其输出规格 AC220V → DC5V 20A 100W
- WS2812B ×1 白板滴胶, 60灯珠/m, 5m
- 灯带连接器 x1 这应该是购买灯带后随附的连接器。提供一个连接到灯带的接头,以及 5V+GND 可焊接导线,5V+DIN+GND 母头 (共5个接口)
BTF-LIGHTINGWS2812B RGB IC 5050SMD Pure Gold Led Pixel Strip Flexible Full Color 3
WS2812B RGB IC 5050SMD Pure Gold Led Pixel Strip Flexible Full Color 3
Shipping PolicyNotice: Customers should take care of the clearance and customs duties. Features: Input Voltage:DC 5v. Power: 30leds/m----9watt/meter. 60leds/m----18watt/meter. 74leds/m----22watt/meter. 96leds/m----28.8watt/meter. 100leds/m----30watt/meter. 144leds/m----43.2watt/meter. Grey Scale: 256. Bits/color: 8-b
item.taobao.com
传感器(可选)
- 电位器 用于滑动调整亮度大小
- 按钮 ×2 对应程序里的照明控制按钮,色彩控制按钮
- 红外线传感器/遥控器 HX1838遥控模块+遥控器套件
detail.tmall.com
- 环境光传感器 亮度传感器升级版
item.taobao.com
装饰物(可选)
收藏品 ×若干你喜欢的物品。
- 苔藓(纺织) ≥30g 推荐更大 丝状苔藓浅绿
detail.tmall.com
- 假竹 ×10
item.taobao.com
- 石片 ×10 ”青云石片”, 2-5cm
item.taobao.com
其他(可选)
- LED 连接器 ×若干 如果你要剪断灯带,则需要根据实际情况购买这些连接器来连接它们 不会在文章和接线图中说明
BTF-LIGHTINGConnector & Cable
Connector & Cable
Full Series Digital LED Strip Light. WS2811 WS2812B WS2813 WS2815 SK6812 RGB RGBW, BTF-LIGHTING is a top quality LED lights wholesaler. Deliver high performance hence low power consumption led strips. We support custom order as well.
item.taobao.com
- 电工胶布 x1 用于在不切断的情况下固定灯带 PVC电气胶带(白色)
detail.tmall.com
- 面包板(推荐) ×1 方便给各用电器供电,下文将使用到它
- 电阻 ×若干 用于保护电路,根据实际情况购买 不会在文章和接线图中说明
- 电容 ×若干 用于保护电路,根据实际情况购买 不会在文章和接线图中说明
功能
FastLED LED animation library for Arduino (formerly FastSPI_LED)
FastLED supports popular LEDs including Neopixel, WS2801, WS2811, WS2812B, LPD8806, TM1809, and more. The library runs on a wide range of Arduino and compatible boards, including both AVR- and ARM- based microcontrollers.
多 Cabinet
电位器
Eco 模式
照明模式
- 关闭 照明处于长期关闭状态。
- 正常 开启照明。
色彩模式
- 全局纯色模式 所有灯泡除被忽略的灯泡都以 #FFA028 颜色。
- 独立纯色模式 每个 Cabinet 的灯泡都以其不同的颜色照明。
- RGB模式 所有灯泡除被忽略的灯泡都进行 RGB 循环。
过渡效果
红外遥控
我的遥控器每个按键被接收到的数据和对应的功能
按钮 | 操作 | 接收数据 |
1 | 将亮度设置为 10% | BA45FF00 |
2 | 将亮度设置为 20% | B946FF00 |
3 | 将亮度设置为 30% | B847FF00 |
4 | 将亮度设置为 40% | BB44FF00 |
5 | 将亮度设置为 50% | BF40FF00 |
6 | 将亮度设置为 60% | BC43FF00 |
7 | 将亮度设置为 70% | F807FF00 |
8 | 将亮度设置为 80% | EA15FF00 |
9 | 将亮度设置为 90% | F609FF00 |
0 | 将亮度设置为 0% | E619FF00 |
* | 照明控制按钮 | E916FF00 |
# | 色彩控制按钮 | F20DFF00 |
OK | 打开/关闭电位器控制 | E31CFF00 |
↑ | 将亮度增加 5% | E718FF00 |
↓ | 将亮度减少 5% | AD52FF00 |
← | 将亮度减少 1% | F708FF00 |
→ | 将亮度增加 1% | A55AFF00 |
实践
开发环境
驱动
Avrdude: ser_open(): can't set com-state for "\\.\COMN 的错误。These operating systems have the CDC drivers pre-installed, which means you shouldn't need to install any extra software. However, there are a wide range of operating systems out there, so if you run into driver problems, you can get the archived drivers linked below
Arduino CLI
arduino-cli ,你会发现终端会提示它不存在。展开这里以查看在 Windows 上解决 Arduino CLI 的环境变量问题

Path ,点击选中,然后选择 “Edit” (编辑),你应该会发现最下方有一个包含 “Arduino CLI” 的变量,例如我的是 C:\Program Files\Arduino CLI\ ,如果你是下载的 exe 版本的 Arduino CLI,请复制它的绝对路径(不包含文件本身)。然后,复制这个变量。Path ,点击选中,然后选择 “Edit” (编辑),然后选择 “New” (新建),粘贴刚刚复制的变量或路径,然后选择 “OK” (完成),最后再次选择 “OK” (完成)Visual Studio Code


C:\Program Files\Arduino CLI\.ino 文件,点击展开,然后粘贴这个项目的代码。
<Select Board> 和 <Select Serial Port> 并选择 Arduino Uno (Arduino AVR Boards) 和开发板目前处于的串口,例如我的是 COM5 。
.vscode 文件夹内,扩展应该会生成一个arduino.json文件,你需要在该文件内指定代码的编译文件夹,名称随意,我这里使用了 dist作为输出(编译)文件夹的名称。"output": "./dist” ,最后我的 arduino.json 如下:FastLED LED animation library for Arduino (formerly FastSPI_LED)
FastLED supports popular LEDs including Neopixel, WS2801, WS2811, WS2812B, LPD8806, TM1809, and more. The library runs on a wide range of Arduino and compatible boards, including both AVR- and ARM- based microcontrollers.
Arduino: Library Manager 
FastLED ,点击 Install 安装。和刚刚的做法一样,在搜索框中搜索并安装 “IRRemote” (≥4.5.0) ,点击 Install 安装。

.vscode 下生成一个 c_cpp_properties.json 文件,这样你就可以在 Visual Studio Code 里编写由 IntelliSense 提供支持的 Arduino 源文件了。接线
电源
- 准备线材 使用剥线钳,将三线插头电线的另一端的绝缘层剥开,并使其露出适当长度的铜芯。 你应该区分出其中的三根导线,分别为
- 连接导线 使用螺丝刀,分别解下电源 L, N, ⏚, V+, V- 对应的端子,如果有两个 V+ V- 对应的端子,解下一个即可。
- 连接 Arduino 这里使用的是 Arduino Uno。
- 连接各用电器
数据
- D1 照明控制按钮
- D2 色彩控制按钮
- D6` 灯带 插入到灯带连接器的绿色杜邦线母头上
- D5` 红外线传感器
- A0 环境光传感器
- A1 电位器 在正中央的引脚
结语
参考
VS code配置Arduino开发环境_vscode arduino-CSDN博客
文章浏览阅读4.2k次,点赞11次,收藏35次。使用VS Code+Arduino-CLI来进行Arduino开发_vscode arduino
[Warning] Failed to generate IntelliSense configuration. · Issue #1235 · microsoft/vscode-arduino
What do I need to do to correct this on MacOS 10.4.6 with : Version: 1.56.0-insider Commit: ce791d27dc9889a392f4d29abefe9c53eb0b5129 Date: 2021-04-16T11:23:31.851Z Electron: 11.4.2 Chrome: 87.0.428...
Arduino ForumAvrdude: ser_open(): can't set com-state for "\\.\COM7"Avrdude: ser_open(): can't set com-state for "\\.\COM7"
Better news, it does work in the hardwired application. Despite the differences it behaves the same. 😀
How to Install CH340 Drivers - SparkFun Learn
In this tutorial, we'll show you how to install CH340 drivers on multiple operating systems if you need. The driver should automatically install on most operating systems. However, there is a wide range of operating systems out there. You may need to install drivers the first time you connect the chip to your computer's USB port or when there are operating system updates.
剥线钳 - 维基百科,自由的百科全书剥线钳 - 维基百科,自由的百科全书
美式简易手动剥线钳是一对相对应的刀片,像是剪刀或斜口钳。增加了中心的凹口以便于切割绝缘层而不切到电线芯。此种剥线钳使用时要施加压力并绕绕绝缘层旋来切割层周的绝缘层割因为于绝缘层没有粘结到电芯上,因此很容易将其从末端拉出。这种类型的剥线适用于于任何尺寸的电线。