Music not only plays for the ears but also dances before the eyes. Using Arduino as its brains, this product transforms auditory rhythms into a visual spectacle using music-responsive LED light strips.
Devices and components
Arduino Uno Rev3
60W, 12V, 5A PCIe Power Supply
SparkFun Sound Detector (with Headers)
WS2811 Addressable LED Strip (1m, 60 LEDs)
Software and tools
FastLED Library
Arduino IDE
Project description
Music-reactive LED lights.
Used in Arduino IDE software
1#include <FastLED.h> // https://github.com/FastLED/FastLED
2FASTLED_USING_NAMESPACE
3
4#define NUM_LEDS 150 // Total Number of LEDs
5#define DATA_PIN 3 // Connect your Addressable LED Strip to this Pin.
6#define LED_TYPE WS2811 // WS2801, WS2811, WS2812B, LPD8806, TM1809, etc...
7#define COLOR_ORDER RGB // Default Color Order
8#define ENVELOPE_PIN A0 // Envelope Pin of the Sparkfun Sound Detector Module
9
10#define BRIGHTNESS 200 // Min: 0, Max: 255
11#define SATURATION 150 // Min: 0, Max: 255
12#define MIN_VAL 20 // Adjust this between 0 and 75 for sensitivity
13#define MAX_VAL 250 // Adjust this between 75 and 750 for sensitivity
14#define HUE_INIT 10 // < 255
15#define HUE_CHANGE 2 // < 255
16
17/*============= SELECT STYLE =============*/
18/* */
19/* 0 --> LinearReactive */
20/* 1 --> BrightnessReactive */
21/* */
22/* */ int STYLE = 1; /* */
23/* */
24/*========================================*/
25
26CRGB leds[NUM_LEDS];
27byte dynamicHue = HUE_INIT;
28int analogVal = 0;
29int val = 0;
30
31void setup() {
32 pinMode(ENVELOPE_PIN, INPUT);
33
34 FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
35 FastLED.setBrightness(BRIGHTNESS);
36
37 for(int i = 0; i < NUM_LEDS; i++) {
38 leds[i] = CRGB::Black;
39 }
40
41 // Update the LED Strip
42 FastLED.show();
43}
44
45void loop() {
46 analogVal = analogRead(ENVELOPE_PIN);
47
48 if(analogVal > MAX_VAL)
49 analogVal = MAX_VAL;
50
51 if(analogVal < MIN_VAL)
52 analogVal = MIN_VAL;
53
54 switch (STYLE) {
55 case 1:
56 BrightnessReactive();
57 break;
58 default:
59 LinearReactive();
60 break;
61 }
62
63 // Update the LED Strip
64 FastLED.show();
65}
66
67void LinearReactive() {
68 val = map(analogVal, 0, MAX_VAL+1, 0, NUM_LEDS);
69
70 for(int i = 0; i < NUM_LEDS; i++) {
71 if (i <= val)
72 leds[i] = CHSV(HUE_INIT+(HUE_CHANGE*i), SATURATION, BRIGHTNESS);
73 else
74 leds[i].nscale8(10);
75 }
76}
77
78void BrightnessReactive() {
79 val = map(analogVal, MIN_VAL, MAX_VAL, 0, BRIGHTNESS);
80
81 for(int i = 0; i < NUM_LEDS; i++) {
82 leds[i] = CHSV(HUE_INIT+(HUE_CHANGE*i), SATURATION, val);
83 }
84}
Note: Content and images are from: https://projecthub.arduino.cc/, with some modifications.
If you want it removed due to copyright reasons, please leave a comment. Thank you.
I want to share this article more widely so that everyone knows about Arduino and your project.