【雕爷学编程】Arduino动手做(06)---KY-038声音传感器模块3

37款传感器与执行器的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止这37种的。鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里准备逐一动手尝试系列实验,不管成功(程序走通)与否,都会记录下来—小小的进步或是搞不掂的问题,希望能够抛砖引玉。

 

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)
实验六:KY-038高感度声音传感器模块

 

  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

  实验之六:KY-038声音传感器模块声控 感应小开关麦克风模块声音控制模块

  项目:使用KY—038声音模块的阙值触发WS2812节奏灯条

Arduino实验开源代码

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
  【花雕动手做】有趣好玩的音乐可视化系列小项目(04)---WS2812条灯
  项目之一: 使用KY—038声音模块的阙值触发WS2812节奏灯条
*/
 
#include<FastLED.h>
#define LED_PIN 6
#define NUM_LEDS 8
 
CRGB leds[NUM_LEDS];
uint8_t hue = 0;
int soundsensor = 7;
 
void setup() {
  delay(2000);
  Serial.begin(9600);
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(255);
  pinMode(soundsensor, INPUT);
}
 
void loop() {
  int sensval = digitalRead(soundsensor);
 
  if (sensval == 1) {
    Serial.println("ON");
    leds[0] = CRGB :: Red;
    fill_solid(leds, NUM_LEDS, CRGB :: Blue);
    rainbow_moving();
    FastLED.show();
    delay(10);
  }
  else {
    leds[0] = CRGB :: Black;
    fill_solid(leds, NUM_LEDS, CRGB :: Black);
    FastLED.show();
    delay(10);
  }
}
 
void rainbow_moving() {
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CHSV(hue + (i * 10), 255, 255);
  }
  EVERY_N_MILLISECONDS(10) {
    hue++;
  }
}

  

Arduino实验场景图

 

 实验视频剪辑

https://v.youku.com/v_show/id_XNTgxMTgxMjMwOA==.html?firsttime=0

实验场景动态图

 

  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

  实验六:KY-038声音传感器模块声控 感应小开关麦克风模块声音控制模块

  项目:数字信号驱动的七色节奏灯

Arduino实验开源代码

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
  【花雕动手做】有趣好玩的音乐可视化系列小项目(04)---WS2812条灯
  项目之二:数字信号驱动的七色节奏灯
*/
 
#define FASTLED_INTERRUPT_RETRY_COUNT 0
//#define FASTLED_ESP8266_RAW_PIN_ORDER
 
#include <FastLED.h>
#define NUM_LEDS 8
CRGB leds[NUM_LEDS];
 
const int ledPin = 6;
int sensorPin = 7;
boolean val = 0;
 
void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(sensorPin, INPUT);
  Serial.begin (9600);
  FastLED.addLeds<WS2812B, ledPin, RGB>(leds, NUM_LEDS);
}
 
void loop () {
  val = digitalRead(sensorPin);
  Serial.println (val);
  if (val == HIGH) {
    leds[0] = CRGB(180, 0, 0);
    FastLED.show();
    delay(3);
    leds[1] = CRGB(0, 180, 0);
    FastLED.show();
    delay(3);
    leds[2] = CRGB(0, 0, 240);
    FastLED.show();
    delay(3);
    leds[3] = CRGB(150, 0, 240);
    FastLED.show();
    delay(5);
    leds[4] = CRGB(220, 200, 20);
    FastLED.show();
    delay(5);
    leds[5] = CRGB(85, 60, 180);
    FastLED.show();
    delay(10);
    leds[6] = CRGB(50, 220, 20);
    FastLED.show();
    delay(10);
    FastLED.show();
    leds[7] = CRGB(220, 220, 250);
    FastLED.show();
    delay(10);
    FastLED.show();
  }
  else {
    leds[8] = CRGB(150, 0, 255);
    FastLED.show();
  }
  FastLED.clear();
}

  

实验视频剪辑

https://v.youku.com/v_show/id_XNTgxMTgyNDkwNA==.html?firsttime=0

实验场景动态图

 

  【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

  实验六:KY-038声音传感器模块声控 感应小开关麦克风模块声音控制模块

  项目:12位环形音乐反应灯

Arduino实验开源代码

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
  【花雕动手做】有趣好玩的音乐可视化系列小项目(04)---WS2812条灯
  项目之三:12位环形音乐反应灯
*/
 
#define FASTLED_INTERRUPT_RETRY_COUNT 0
//#define FASTLED_ESP8266_RAW_PIN_ORDER
 
#include <FastLED.h>
#define NUM_LEDS 12
CRGB leds[NUM_LEDS];
 
const int ledPin = 6;
int sensorPin = 7;
boolean val = 0;
 
void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(sensorPin, INPUT);
  Serial.begin (9600);
  FastLED.addLeds<WS2812B, ledPin, RGB>(leds, NUM_LEDS);
}
 
void loop () {
  val = digitalRead(sensorPin);
  Serial.println (val);
  if (val == HIGH) {
    leds[0] = CRGB(180, 0, 0);
    FastLED.show();
    delay(3);
    leds[1] = CRGB(0, 180, 0);
    FastLED.show();
    delay(3);
    leds[2] = CRGB(0, 0, 240);
    FastLED.show();
    delay(3);
    leds[3] = CRGB(150, 0, 240);
    FastLED.show();
    delay(5);
    leds[4] = CRGB(180, 200, 20);
    FastLED.show();
    delay(5);
    leds[5] = CRGB(85, 60, 180);
    FastLED.show();
    delay(10);
    leds[6] = CRGB(50, 220, 20);
    FastLED.show();
    delay(5);
    FastLED.show();
    leds[7] = CRGB(0, 0, 250);
    FastLED.show();
    delay(5);
    FastLED.show();
    leds[8] = CRGB(240, 0, 0);
    FastLED.show();
    delay(10);
    leds[9] = CRGB(0, 250, 0);
    FastLED.show();
    delay(10);
    leds[10] = CRGB(0, 0, 255);
    FastLED.show();
    delay(10);
    leds[11] = CRGB(220, 200, 20);
    FastLED.show();
    delay(10);
  }
  else {
    leds[12] = CRGB(150, 0, 255);
    FastLED.show();
  }
  FastLED.clear();
}

  

Arduino实验场景图

 

实验视频剪辑

https://v.youku.com/v_show/id_XNTgxMTczNDcwOA==.html?firsttime=0

实验场景动态图

 

 

posted @   行者花雕  阅读(151)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
点击右上角即可分享
微信分享提示