Arduino Spectrum Analyzer on a 10x10 RGB LED-Matrix

26,564

229

68

Intro: 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.

Step 2: Additional Parts

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

  • 2x 3.5mm headphone sockets
  • 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.

Share

    Recommendations

    • Optics Contest

      Optics Contest
    • Plastics Contest

      Plastics Contest
    • Audio Contest 2018

      Audio Contest 2018

    68 Discussions

    0
    None
    JazzHandsFrenzyBrynM3

    Answer 5 hours ago

    I honestly have no clue since I have never played with one. I may think about getting one though since it has WiFi built in. For now, I only got the Arduino working and you can use a Bluetooth module to change colors.

    0
    None
    drtydan2019JazzHandsFrenzy

    Reply 9 days ago

    i dont know what went wrong bu i got this eroor can u help

    Arduino: 1.8.5 (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

    In file included from C:\Users\Owner\Desktop\Ardunio Codes\sketch_oct11a\sketch_oct11a.ino:17:0:

    C:\Users\Owner\Documents\Arduino\libraries\F3XPVK1IVO3SD7N/FFT.h:182:3: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]

    "ldi r16, "STRINGIFY(FFT_N/2)" \n" // prep loop counter

    ^

    C:\Users\Owner\Documents\Arduino\libraries\F3XPVK1IVO3SD7N/FFT.h:213:3: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]

    "ldi r16, "STRINGIFY(FFT_N/4)" \n" // prep loop counter

    ^

    C:\Users\Owner\Documents\Arduino\libraries\F3XPVK1IVO3SD7N/FFT.h:265:3: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]

    "ldi r24, "STRINGIFY(FFT_N/8)" \n" // prep loop counter

    ^

    C:\Users\Owner\Documents\Arduino\libraries\F3XPVK1IVO3SD7N/FFT.h:492:3: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]

    "ldi r16, hi8((fft_input + "STRINGIFY(FFT_N*4)")) \n" // prep end of dataspace register

    ^

    C:\Users\Owner\Documents\Arduino\libraries\F3XPVK1IVO3SD7N/FFT.h:686:3: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]

    "cpi r28, lo8(fft_input + "STRINGIFY(FFT_N*4)") \n" // check if at end of dataspace

    ^

    C:\Users\Owner\Documents\Arduino\libraries\F3XPVK1IVO3SD7N/FFT.h:701:3: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]

    "sbrc r11, "STRINGIFY(LOG_N - 2)" \n" // check if finished with all butteflies

    ^

    C:\Users\Owner\Documents\Arduino\libraries\F3XPVK1IVO3SD7N/FFT.h:760:3: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]

    "ldi r20, "STRINGIFY((FFT_N/2) - _R_V)" \n" // set to first sample

    ^

    C:\Users\Owner\Documents\Arduino\libraries\F3XPVK1IVO3SD7N/FFT.h:849:3: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]

    "ldi r20, "STRINGIFY(FFT_N/2)" \n" // set loop counter

    ^

    C:\Users\Owner\Documents\Arduino\libraries\F3XPVK1IVO3SD7N/FFT.h:993:3: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]

    "ldi r20, "STRINGIFY(FFT_N/2)" \n" // set loop counter

    ^

    C:\Users\Owner\Documents\Arduino\libraries\F3XPVK1IVO3SD7N/FFT.h:1162:3: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]

    "ldi r20, "STRINGIFY(FFT_N/2)" \n" // set loop counter

    ^

    C:\Users\Owner\Documents\Arduino\libraries\F3XPVK1IVO3SD7N/FFT.h:1309:3: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]

    "ldi r20, "STRINGIFY(((FFT_N)&(0xff)))" \n"

    ^

    C:\Users\Owner\Documents\Arduino\libraries\F3XPVK1IVO3SD7N/FFT.h:1523:3: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]

    "sbrs r21, "STRINGIFY((LOG_N) - 1)" \n" // check if done

    ^

    C:\Users\Owner\Desktop\Ardunio Codes\sketch_oct11a\sketch_oct11a.ino: In function 'loop':

    C:\Users\Owner\Desktop\Ardunio Codes\sketch_oct11a\sketch_oct11a.ino:75:70: warning: iteration 10 invokes undefined behavior [-Waggressive-loop-optimizations]

    for(int ii=0; ii<11; ii++)if( display_band[ii] > 0 ) display_band[ii] -=1;

    ^

    C:\Users\Owner\Desktop\Ardunio Codes\sketch_oct11a\sketch_oct11a.ino:75:25: note: containing loop

    for(int ii=0; ii<11; ii++)if( display_band[ii] > 0 ) display_band[ii] -=1;

    ^

    C:\Users\Owner\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21\cores\arduino\main.cpp: In function 'main':

    C:\Users\Owner\Desktop\Ardunio Codes\sketch_oct11a\sketch_oct11a.ino:75:70: warning: iteration 10 invokes undefined behavior [-Waggressive-loop-optimizations]

    for(int ii=0; ii<11; ii++)if( display_band[ii] > 0 ) display_band[ii] -=1;

    ^

    C:\Users\Owner\Desktop\Ardunio Codes\sketch_oct11a\sketch_oct11a.ino:75:25: note: containing loop

    for(int ii=0; ii<11; ii++)if( display_band[ii] > 0 ) display_band[ii] -=1;

    ^

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

    }

    ^

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

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

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

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

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

    collect2.exe: error: ld returned 1 exit status

    exit status 1

    Error compiling for board Arduino Nano.

    0
    None
    JazzHandsFrenzydrtydan2019

    Reply 9 days ago

    I got the same error when I first compiled it. I'll upload the libraries that I used to my GitHub then all you should have to do copy them to your library folder. I'll respond again when I do that. Probably be later today.

    And to me, it sounds like just your library didn't initialize. It took me alot of researching to get the library working so that's why I'll just upload my library folder.

    I added the library folder. Copy the contents to your library folder and try to compile again. I believe that is your only issue.

    0
    None
    JazzHandsFrenzydrtydan2019

    Reply 8 days ago

    No problem. I've been working on it and I am probably going to change a few key things so, just look out for that code and be sure to save the old one in case it doesn't work.

    0
    None
    JazzHandsFrenzyBrynM3

    Answer 12 days ago

    Since very little wattage runs through the resistors, and its not powering anything, you dont need to worry about wattage. just make sure the resistance is correct.

    0
    None
    JazzHandsFrenzy

    12 days ago

    I followed this guide to a tee, and i had no problems. The only issue i had was with his code so i have been working on a updated version that offers more options.

    0
    None
    Bazzynga

    15 days ago

    It's really works)

    0
    None
    GinaD49

    Question 3 months ago

    Hello, I am trying to convert this code to work on two 20x14 panels and two 5x14 panels, using only one Arduino Uno. I'm having a bit of difficulty in changing the matrix size, and outputting the different dimensions through two different channels (it's been about 4 years since I've used Arduino, I'm a little rusty to say the least). If anyone has any tips it would be greatly appreciated!!

    1 more answer
    1
    None
    JazzHandsFrenzyGinaD49

    Answer 19 days ago

    I started working on this new code so if you are still looking to getting it working, i would gladly help you.

    0
    None
    Hoàng AnhL

    4 months ago

    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

    as your video

    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-

    0
    None
    Sudhanshu_S

    5 months ago

    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.

    Please help me with this, I really want this nice project to work