# Arduino Spectrum Analyzer on a 10x10 RGB LED-Matrix

22,671

227

48

Published

## Introduction: Arduino Spectrum Analyzer on a 10x10 RGB LED-Matrix

In this Instructables I am going to show you how to create a spectrum analyzer powered by an Arduino nano. Please watch my video first to get a rough explaination on how to build it.

A spectrum analyzer basically analyzes the intensity of different frequencies in a song. To display those values we are going to use a 10x10 RGB LED-Matrix. Every time one of the columns reaches the top of the matrix the hue value of the colors increases and the matrix looks different.

## Step 1: Building the Matrix

To make this awesome spectrum analyzer I first had to build the RGB LED-Matrix. To accomplish this task I have followed the Tutorial of GreatScott on YouTube. He did an awesome job in explaining how to build such a matrix. Just follow the video step by step or use his Instructables as an instruction and then come back and follow the next steps.

Important note: make sure your LEDs are connected as shown in the diagram above. Otherwise my sketch won't work flawless with your matrix.

To convert your Matrix into a spectrum analyzer you need the following additional components:

• 2x 1.8kOhm resistors
• 1x 4.7kOhm resistor
• some flexible wire

First of all I had to include the two headphone sockets to the matrix. We use them to loop the audio signal through the matrix to analyze it. We basically connect our audio source (e.g. a smartphone) to one of them and a speaker to the other one. I just drilled two holes according to the diameter of my sockets and glued them in place with two component adhesive.

In the next step you will see why we need those resistors.

## Step 3: Connecting the Components

First of all, I have connected 3.3V to the AREF pin of the Arduino through a 4.7kOhm resistor. This is to get a better resolution of the sampled values of the audio signal since they normally reach a maximum of only 1V Peak-to-peak. The reason why we get a better resolution is that the 1024 values of the ADC are now not longer mapped to 0-5V but to 0-2.88V (2.88V because of the 4.7kOhm resistor). To understand why we used a 4.7kOhm resistor and how I have calculated those 2.88V have a look at the analog reference article on the Arduino website.

But there is one problem if you want to analyze an audio signal with an Arduino. The signal is mirrored around 0V. Therefore we get both positive and negative voltage peeks. And because Arduinos can't handle negative voltages we have to get rid of them and create an offset.

As you can see in the schematic above I used a voltage divider with two 1.8kOhm resistors to solve this problem. Since they have both the same resistance the signal now alters around 1.44V (2.88V/2) and we got rid of those negative voltages. To make life easier you can solder the resistors directly to the pins of your Arduino nano.

Lastly I connected the two audio jacks. I simply connected both right and both left channels to each other. I then soldered both GND pins together and connected them to the GND wire of the matrix. Which of the two channels you then connect to the Arduinos A7 Pin / voltage divider doesn't really matter.

## Step 4: Programming

To program the built in Arduino nano you first of all have to download both the FastLED and the FFT library. Make sure you have exactly these versions of the libraries listed below otherwise the sketch may not work. Also check if you use at least Arduino IDE 1.6.8 or higher. After you have included both libraries into your Arduino IDE you have to open the "SpectrumAnalyzer" sketch.

Now change the data pin of your LEDs, upload it to your Arduino, connect an audio source and speakers and it is done!

Hope I could help you with this Instructables. If you have any questions feel free to ask them in the comments section below.

## Recommendations

• ### Arduino Class

69,892 Enrolled

• ### Casting Contest

We have a be nice policy.

## 2 Questions

0

That input circuit is a mess and risks damaging your audio device and your Arduino. You have not understood what you have read on the Arduino page.
R2 should be connected to ground not your audio input. Your audio input should be connected to A7 through a series capacitor. You should not connect anything to the Aref input and R3 should go straight to the 5V connector.

0

hi, i have a problem with code. When i upload a cod i get a msg :
In file included from C:\Users\kaspe\Desktop\kodmuzyka\kodmuzyka.ino:15:0:

C:\Users\kaspe\Documents\Arduino\libraries\FastLED/FastLED.h:12:2: warning: #warning FastLED version 3.001.000 (Not really a warning, just telling you here.) [-Wcpp]

#warning FastLED version 3.001.000 (Not really a warning, just telling you here.)

^

C:\Users\kaspe\Desktop\kodmuzyka\kodmuzyka.ino: In function 'loop':

C:\Users\kaspe\Desktop\kodmuzyka\kodmuzyka.ino:84:58: warning: iteration 10 invokes undefined behavior [-Waggressive-loop-optimizations]

for(unsigned char x = grenzen[i]; x
^

C:\Users\kaspe\Desktop\kodmuzyka\kodmuzyka.ino:82:5: note: containing loop

for(unsigned char i = 0; i
^

I don't know if you're trying to make the code gone wrong when you posted here or what,

there's some problems with the code you posted

1, the Fastled.show() was outside the "for" loop at the end of the code cause terminal send out garbage (ADC read out garbage) I don't know for sure but terminal monitor show the good value after I put FastLed.show() back into it

2, "for (int i = 0 ; i < 512 ; i+=2) " this just freeze the loop. and when I put it back to 256 and i+=1, the code works fine

3,the CHSV did change the LED as hue++ but didn't change the Spectrum color realtime

I don't know why but I added millis to increase hue each 10 millisecond in the loop and everything works as your video describe

4,For who got register error: just use FHT library instead (FHT can found at open music lab)

5, for who got fft_lin_out or fht_lin_out not declare.... just include library after you define LIN_OUT

goodluck

-Zoe-

Hi ,

Used a 1.5k resistor in place of 1.8k

I have downgraded the IDE to 1.6.7. It does not work with music visualization.

It works randomly. In Serial plotter nothing shows up.

It's good result!

4 replies

graet work. any idea how to get that deep beat drum like(4:00 you ce see that there is no reaction to this ), be detected ?

ok in code ftt 0 and 1 are cleared to 0 , im blind :P

Hi takasukaamaraka can you send me the programm from your LED matrix?

I´m very new and thats my first project with arduino. My LED Matrix is 16x9 and I`ve made the same mistake as AlexeyZ15 I habe reversed every even LED column :/

I can´t figure out what things I have to change that the programm work on my LED Matrix

What values for the frequencies and multipliers have you used for the two additional channels? I did the same thing but yours seems more reactive to the music.

I tried this and this error message keeps coming up

exit status 1
'fft_lin_out' was not declared in this scope

I have a problem with the Spectrum Analyzer ... so I made the spectrum analyzer the same way described in GreatScott!'s video and in this instructables. The problem is that when i upload the code to the Arduino, the spectrum analyzer doesn't light up any LED's in the matrix. The only thing that i changed is that i used two 1.6kOhm resistors instead of 1.8kOhm ones. In code, i changed ADMUX = 0b01000111; with ADMUX = 0x40; on line 54, so that i can use analog Inpit A0. When i open the serial monitor while playing music i can see changing values, and when i don't play music the values are not changing. Is the code processing the audio and the matrix not displaying it? Please help.

i keep getting this error message. Arduino: 1.8.1 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\Documents\Arduino\libraries\FastLED-master/FastLED.h:17:21: note: #pragma message: FastLED version 3.001.005

# pragma message "FastLED version 3.001.005"

^

C:\Users\

\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.17\cores\arduino\main.cpp: In function 'main':

C:\Users\

\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.17\cores\arduino\main.cpp:51:1: error: r28 cannot be used in asm here

}

^

C:\Users\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.17\cores\arduino\main.cpp:51:1: error: r29 cannot be used in asm here

C:\Users\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.17\cores\arduino\main.cpp:51:1: error: r28 cannot be used in asm here

C:\Users\\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.17\cores\arduino\main.cpp:51:1: error: r29 cannot be used in asm here

lto-wrapper: C:\Users\\AppData\Local\Arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.3-arduino2/bin/avr-gcc returned 1 exit status

c:/users//appdata/local/arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.3-arduino2/bin/../lib/gcc/avr/4.9.2/../../../../avr/bin/ld.exe: lto-wrapper failed

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board Arduino/Genuino Mega or Mega 2560.

"Show verbose output during compilation"

option enabled in File -> Preferences.

can you help?

3 replies

I met the same situation, but I solved the problem by replaceing the Arduino15 folder, which is in my C:\Users\\AppData\Local\Arduino15. It contains the core files for AVR programming. I replaced it with the original one(which is automatically built when you run Arduino IDE for the first time). Remember to backup! Hope this can help you.

I am really sorry but I can't really help you with the code because a friend of mine wrote it.
But it may be possible, that the problem occours because you use a arduino mega and not a nano. But I'm not sure.

Good project you made here. Is using pin A7 necessary in this case, or I can use any other Analog input? I`m just using another diy arduino compatible board.

6 replies

You can use any analog pin you like :) Just change it in the code

Thank you for the reply ^^ but...

I almost built my matrix and just realised how dumb I am... I made wrong led connection pattern like on the picture instead of your in the instruction. So every even column is reversed. I think it can be fixed with code. Colud you please help me with it, because its my first arduino project and I`m not familiar with coding yet. Thank you again.

hello Alexey, I wonder how you changed A7 to another pin. You know, it's a

binary data. What if I want to use A0?

The original setting is :

ADMUX = 0b01000111; //use pin A7

(Line 54)

I think pin A0 should be 0b01000000.

But I'm not 100% sure because a friend of mine actually wrote the code.

It actually is 0x40.

Try this one

for(unsigned char y = 0; y < 10; y++){ //set colors of pixels according to column and hue

if(hs[column] > y){

if (y % 2) {

leds[(y*10)-column+9] = CHSV((hue*10)+(column*10), 255, 200);

}

else {leds[(y*10)+column] = CHSV((hue*10)+(column*10), 255, 200);

}

//leds[y+(column*10)] = CHSV((hue*10)+(column*10), 255, 200);

} else {

if (y % 2)

{leds[(y*10)-column+9] = CRGB::Black;

} else {

leds[(y*10)+column] = CRGB::Black;

}

}

}