这是个会使你惊讶其妙的 rgb led 台灯。它将对周围的声音和音乐做出反应,并将像可视化器一样播放。
在这个项目构建中,我们将使用简单的组件和一些基本的arduino编程来制作一个与所有声音和音乐共舞的漂亮灯。站在桌子上玩游戏、播放音乐和其他任何真正能发出声音的东西时,它都会产生令人惊叹的效果。让我们开始吧!
第 1 步:主要用品首先要做的事情是:规划我们需要什么样的用品,它们的成本是多少?它们在很大程度上是可选的,并且可以通过所需功能进行变动。但虽然如此,还是有一些关键的东西是必需的: arduino nano(或任何同样小的 arduino 类型) 声音检测模块(rm 5.90 购买链接) 5伏电源(或12伏降压模块) 每个可单独寻址的 led 灯条 60 个 led 根据您想要的外观,您可能希望以不同的方式排列条带或以其他方式漫射光。这是你可以发挥创造力的地方。如果您喜欢我的方法,我使用了以下项目: 最高的宜家 droppar 罐 一小段pvc管。 泡沫板 热胶枪 第 2 步:为组件供电为组件供电将是一种直接的方法。我只是使用 arduino nano 的 usb 线直接插入电脑。如果您使用 ac 到 dc 电源等外部电源,您将需要一个降压模块来帮助您减少流向电路的电流量。否则,如果您不使用它,您可能很有可能会烧毁 arduino,包括连接的组件。
该部分的核心是声音检测器模块。这将为 arduino 提供模拟信号,我们可以用它巧妙地点亮 rgb 灯。为了能够做到这一点,我们需要为这两个设备供电。(关注公众号 电路一点通)幸运的是,它们都需要 5 伏输入。我正在使用降压模块从 12 伏降到 5 伏,但直接使用 5 伏电源会更容易。将 arduino 和声音检测器板上的 vin 连接到正极输入。然后将 arduino 上的 gnd 和检测器连接到负极。我们还需要将 led 灯条上的正负输入连接到电源。
第 3 步:检测器和条带
将所有三个部分连接到电源后,我们需要将它们相互连接。声音检测器模块将通过模拟输入引脚与 arduino 通信。在这种情况下,我将使用 0 号引脚。
led 灯条需要一个数字脉冲才能了解我们要处理的 led。因此,我们需要将数字输出引脚连接到 arduino nano。我将使用 6 号引脚。
在选择区域使用收缩管,这样电缆以后就不会在狭窄的空间内相互碰撞。太棒了,现在我们大部分都完成了电子设备!
第 4 步:上传代码这个构建中最重要的部分可以说是代码。它可以将这个构建从非常酷变为非常棒。主要原理是将我们从传感器获得的模拟值映射到要显示的 led 数量。
第 5 步:准备外壳
一开始我以为盖子是亚克力做的,后来我买了罐子,发现它不是亚克力而是玻璃。所以我需要重新调整我的计划,制作一个易于戳和安装 arduino 和 led 的盖子。所以我选择了泡沫板。
第一步,我需要切割泡沫板,使其完全呈圆形,并且与罐子的玻璃盖具有相同的直径。我没有合适的测量直径工具,所以我使用湿记号笔即兴创作了该方法,并标记了玻璃的直径并将其印在一张纸上。之后,我将纸粘贴到泡沫板上,但沿着纸上圆圈的边缘粘贴到板上。它并不完美,但应该足以容纳所有 arduino 和 led 组件。
第二步,我需要打破罐盖上的玻璃。警告!请用厚塑料袋盖住罐子,以防止玻璃散落在房间周围,并在空旷的地方进行。了解您的周围环境。打碎玻璃后,请确保所有粘在罐盖侧面裂缝处的玻璃都被清除。这是为了防止您或其他人因将它们自己切割到卡住的玻璃上而受伤。
第三步,将圆形泡沫板放在罐盖的中心。确保泡沫是紧的,不要太松,它们正好适合罐子。
第四步,我才意识到我需要改变这个项目的布局。我想让用户在出现故障时可以轻松访问 arduino 组件。所以,我决定使用迷你面包板并将其放在盖子的中心。不仅如此,我还为声音模块上的电缆剪了两个孔,我将把它们放在罐盖的底部,进入罐子和面包板上,还有一个孔让 arduino 与 usb 电缆连接以发挥作用作为电路的电源。
第五步,我用胶带标记pvc管并在胶带的中心画线。然后,我把它贴在 pvc 管上。标记是我均匀切割 pvc 管并尝试干净切割的指标。
在测量了我需要使用的 pvc 长度后,我按照我提供的标记仔细切割它。pvc 管的长度取决于您的罐子高度。你可以使用任何你想要的长度。
第六步,我将用 led 灯条切割的 pvc 管翘曲,使其略微倾斜并螺旋到 pvc 的顶部。我确保为多余的电缆长度创建一个小孔,以便将其隐藏在 pvc 罐内以进行电缆管理。然后我需要找到一种方法将 pvc 放在面包板上。使用热胶枪或双面胶带,我可以将 pvc 管粘在额外的泡沫板上,然后将其粘贴到面包板上未使用的区域。在这一步中,我能够将一些组件连接到面包板。面包板的左侧区域为正极,面包板的右侧区域为负极。
第七步,我把声音模块放在罐盖的外面。这样做是为了便于模块稍后在 jar 外拾取声音。放置模块后,将其与电缆连接并按照给出的示意图进行匹配。然后,将所有电缆与传感器和 arduino 连接到面包板。arduino 是垂直安装的,因此用于为电路供电的电缆将能够通过泡沫板轻松地与 arduino 板连接。
到此,这个项目就完成了。我花了一段时间加上尝试和错误,但最终我依旧设法完成了它。 coding for the arduino:
#include
/** basic configuration **/
//the amount of leds in the setup
#define num_leds 60
//the pin that controls the leds
#define led_pin 6
//the pin that we read sensor values form
#define analog_read 0
//confirmed microphone low value, and max value
#define mic_low 0.0
#define mic_high 200.0
/** other macros */
//how many previous sensor values effects the operating average?
#define avglen 5
//how many previous sensor values decides if we are on a peak/high (e.g. in a song)
#define long_sector 20
//mneumonics
#define high 3
#define normal 2
//how long do we keep the current average sound, before restarting the measuring
#define msecs 30 * 1000
#define cycles msecs / delay
/*sometimes readings are wrong or strange. how much is a reading allowed
to deviate from the average to not be discarded? **/
#define dev_thresh 0.8
//arduino loop delay
#define delay 1
float fscale( float originalmin, float originalmax, float newbegin, float newend, float inputvalue, float curve);
void insert(int val, int *avgs, int len);
int compute_average(int *avgs, int len);
void visualize_music();
//how many leds to we display
int curshow = num_leds;
/*not really used yet. thought to be able to switch between sound reactive
mode, and general gradient pulsing/static color*/
int mode = 0;
//showing different colors based on the mode.
int songmode = normal;
//average sound measurement the last cycles
unsigned long song_avg;
//the amount of iterations since the song_avg was reset
int iter = 0;
//the speed the leds fade to black if not relit
float fade_scale = 1.2;
//led array
crgb leds[num_leds];
/*short sound avg used to normalize the input values.
we use the short average instead of using the sensor input directly */
int avgs[avglen] = {-1};
//longer sound avg
int long_avg[long_sector] = {-1};
//keeping track how often, and how long times we hit a certain mode
struct time_keeping {
unsigned long times_start;
short times;
};
//how much to increment or decrement each color every cycle
struct color {
int r;
int g;
int b;
};
struct time_keeping high;
struct color color;
void setup() {
serial.begin(9600);
//set all lights to make sure all are working as expected
fastled.addleds(leds, num_leds);
for (int i = 0; i < num_leds; i++)
leds[i] = crgb(0, 0, 255);
fastled.show();
delay(1000);
//bootstrap average with some low values
for (int i = 0; i (song_avg/iter * 1.1)) {
if (high.times != 0) {
if (millis() - high.times_start > 200.0) {
high.times = 0;
songmode = normal;
} else {
high.times_start = millis();
high.times++;
}
} else {
high.times++;
high.times_start = millis();
}
}
if (high.times > 30 && millis() - high.times_start 200) {
high.times = 0;
songmode = normal;
}
}
//main function for visualizing the sounds in the lamp
void visualize_music() {
int sensor_value, mapped, avg, longavg;
//actual sensor value
sensor_value = analogread(analog_read);
//if 0, discard immediately. probably not right and save cpu.
if (sensor_value == 0)
return;
//discard readings that deviates too much from the past avg.
mapped = (float)fscale(mic_low, mic_high, mic_low, (float)mic_high, (float)sensor_value, 2.0);
avg = compute_average(avgs, avglen);
if (((avg - mapped) > avg*dev_thresh)) //|| ((avg - mapped) cycles) {
song_avg = song_avg / iter;
iter = 1;
}
longavg = compute_average(long_avg, long_sector);
//check if we enter high mode
check_high(longavg);
if (songmode == high) {
fade_scale = 3;
color.r = 5;
color.g = 3;
color.b = -1;
}
else if (songmode == normal) {
fade_scale = 2;
color.r = -1;
color.b = 2;
color.g = 1;
}
//decides how many of the leds will be lit
curshow = fscale(mic_low, mic_high, 0.0, (float)num_leds, (float)avg, -1);
/*set the different leds. control for too high and too low values.
fun thing to try: dont account for overflow in one direction,
some interesting light effects appear! */
for (int i = 0; i < num_leds; i++)
//the leds we want to show
if (i 255)
leds[i].r = 255;
else if (leds[i].r + color.r 255)
leds[i].g = 255;
else if (leds[i].g + color.g 255)
leds[i].b = 255;
else if (leds[i].b + color.b < 0)
leds[i].b = 0;
else
leds[i].b = leds[i].b + color.b;
//all the other leds begin their fading journey to eventual total darkness
} else {
leds[i] = crgb(leds[i].r/fade_scale, leds[i].g/fade_scale, leds[i].b/fade_scale);
}
fastled.show();
}
//compute average of a int array, given the starting pointer and the length
int compute_average(int *avgs, int len) {
int sum = 0;
for (int i = 0; i < len; i++)
sum += avgs[i];
return (int)(sum / len);
}
//insert a value into an array, and shift it down removing
//the first value if array already full
void insert(int val, int *avgs, int len) {
for (int i = 0; i < len; i++) {
if (avgs[i] == -1) {
avgs[i] = val;
return;
}
}
for (int i = 1; i 10) curve = 10;
if (curve newbegin){
newrange = newend - newbegin;
}
else
{
newrange = newbegin - newend;
invflag = 1;
}
zerorefcurval = inputvalue - originalmin;
normalizedcurval = zerorefcurval / originalrange; // normalize to 0 - 1 float
// check for originalmin > originalmax - the math for all other cases i.e. negative numbers seems to work out fine
if (originalmin > originalmax ) {
return 0;
}
if (invflag == 0){
rangedvalue = (pow(normalizedcurval, curve) * newrange) + newbegin;
}
else // invert the ranges
{
rangedvalue = newbegin - (pow(normalizedcurval, curve) * newrange);
}
return rangedvalue;
}
迪米智能电吹风方案实现高精度温量
OPPO的A53s计划在其A系列智能手机中添加新机型
冷焊机与氩弧焊机区别
三星即将公布首颗3nm芯片,或将扭转订单数量
4.55英寸720p高清 索尼LT29i工程机曝光
基于Arduino DIY音频反应台灯
电磁炸弹系统技术介绍
区块链技术在资产管理业务中的应用
如何才能实现真正的智慧影院
印度推迟中国专家签证审批,锂电池厂商警告:影响工厂生产
中国十强芯片制造企业
提高模拟电路水平的进阶之路
中芯国际CEO邱慈云请辞 赵海军出任新东家
自动化、信息化进程加快,工控机市场前景广阔
智能人工气候箱的应用领域以及使用效果
GNSS位移监测站结构安全监测设备
超详细单片机学习汇总资料,STM32大神笔记
华为荣耀新品发布会已定:12月16日,四曲面屏超牛新品来袭
第三代骁龙8发布,支持100亿参数生成式AI
小型断路器工作条件_小型断路器特点