
作者: tomouwerkerkerk
这是一款小巧温馨的悬浮桌面氛围灯,可变色的微光给房间增添了些许温柔的气息。
它是基于 Arduino 和 3D 打印的组件构建而成,搭建起来也非常的简单,喜欢的初学者可以来尝试一下。
材料清单

Arduino Nano x 1
PLA 材料 x 若干
LED 灯带(WS2812 60led/m)x 若干
12.7mm x 5mm 磁铁 x 2
5mm x 3mm 磁铁 x 2
磁性开关 x 1
5v 插头 x 1
5v 电源适配器 x 1
硅胶电线 x 若干
电烙铁 x 1
胶水 x 1
3D 打印机 x 1
螺丝刀 x 1
3D 打印部件

一般部件打印设置
填充20-100%,不用支撑。

LED 支架设置
填充100%,100% 的填充可以让灯光有更好的扩散性!
3D 打印的文件可在本项目文件库中下载:
https://make.quwj.com/project/427
制作 LED 灯

从 LED 到灯的底座需要穿过三根电线。这是整个制作过程中最难的部分。

1、剪三根长度为 130mm 的电线(可多预留一些,以便长度不够),剪一条长度合适的 LED 灯带。
2、将所有的电线焊接到 LED 灯带上。在电线末端做一下标记,以便将它们连接到 Arduino 上时,不会混淆。

3、把电线全部装进灯壳的小孔里。

4、在 LED 灯带上胶水,然后把它放到灯壳主体内。可将电线编成辫子,这样看起来更美观一点。


5、放置一块磁铁到主体的上部。

准备电源
电源部分可选择电池或者充电宝。如图所示,我选择 USB 插头充电。

1、将电源插孔连接器粘在灯底的圆孔处。

2、将红黑线接到连接器并引出来,它们将焊接到 Arduino 上。
制作磁性开关(可选)
这步是可选的。你可以选择直接拔掉插头,只在底座上放一块磁铁。
1、用钳子从磁性开关上取下白色的部分。

2、在 SIG、VCC 和 GND 上焊接三根线。
3、将磁铁粘在磁铁/开关底座的圆形一侧,并将开关滑入到位。注意,我们需要测试一下开关没有被小磁铁所触发。如果它被触发了,系统将不会工作了,稍后会在编程步骤中测试这一点。

4、将磁铁/开关底座放在灯底的合适位置,当把灯放在灯座上时,希望能够正常的灯熄灭。我们可以将已经制作好的带有磁铁的LED 灯带放在灯座的另一侧来测试。
焊接 Arduino

1、把两根电线分别连接到 VIN 和电源插口的 GND。
2、把 LED 灯带的线焊接到 GND、V5 和一个数字端口(D1-D12)。

3、把磁性开关线焊接到 GND、V5 和一个数字端口上。
编程
这一步很简单。如果用的部件和文中一样,代码文件可在本项目文件库中下载:
https://make.quwj.com/project/427
1、下载 Arduino IDE。
2、安装 FastLed 库(取决于你使用的 LED):
https://www.arduino.cc/reference/en/libraries/fastled/
3、磁性开关代码:
https://wiki.seeedstudio.com/Grove-Magnetic_Switch/
4、运行代码。
5、检查磁性开关是否被触发。通过向后或向前滑动,对其进行相应的调整。

现在,整个项目完成,这盏温馨可爱的磁悬浮灯就完成啦!
项目所用的代码在本项目文件库中可以下载:
https://make.quwj.com/project/427
via instructables.com/Magnetic-Levitating-Lamp/