Arduino Spectrum Analyzer on a 10x10 RGB LED-Matrix

38,653

246

89

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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.

Make it Glow Contest 2016

Participated in the
Make it Glow Contest 2016

First Time Authors Contest 2016

Participated in the
First Time Authors Contest 2016

Be the First to Share

    Recommendations

    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    89 Discussions

    0
    None
    Kirk Tindel

    Question 4 months ago on Introduction

    I built this and it seems to work great for regular music - but I'm using it with a guitar amplifier and noticing that even with there being no sound (including hum or anything, just complete silence) I still get almost full peaks showing.

    Is there a way to adjust the sensitivity through code, instead of having to solder in new resistor values (and guess around with that until I get the right ones)?

    Thanks for the code, though - works great!

    0
    None
    TheBoj

    5 months ago

    Great project FischiMc. Thank you for posting.
    As I am new to
    Arduino and am looking to build this so I might be asking a silly
    question here. Can someone post a diagram as to how the LED strip
    connects to the Arduino board?
    Does the power supply still connect
    directly the LED strip also go to Arduino 5V pin and ground as well as
    data from LED strip to D3? Then we simply add the components listed in
    your schematic? Also which lines need to be modified to in number of
    rows or columns? EG 15 rows x 20
    Ive already soldered the LED's as described in the video just wanting to clarify.

    Thank you

    0
    None
    bcoffe73

    Question 6 months ago

    game

    0
    None
    BrynM3

    Question 1 year ago

    Would it be possbile to use the esp8266 for this

    4 answers
    0
    None
    JazzHandsFrenzyBrynM3

    Answer 1 year 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
    JazzHandsFrenzyJazzHandsFrenzy

    Reply 10 months ago

    i have just got myself a esp8266 and am currently working on a code for it that will have a web based gui. I am going off of someone else's code but tying to adapt it to work for this guide. if you are still interested, let me know and ill try and help you with setup.

    0
    None
    CantdoitJazzHandsFrenzy

    Reply 10 months ago

    Do you know if it's possible to run this on a Photon Particle? Or is it even worth having..

    0
    None
    Jhon MarvinLJazzHandsFrenzy

    Reply 10 months ago

    Hi! Can I ask what parameters I should change in your code in order to implement this on a 3x10 Matrix? I want to use this for 3 frequencies only. Thanks a lot!!

    1
    None
    JazzHandsFrenzyJhon MarvinL

    Reply 10 months ago

    I added comments, just search for matrix7 and read instructions throughout the code.

    0
    None
    Jhon MarvinLJazzHandsFrenzy

    Reply 10 months ago

    Hi! I'm sorry to bother again. Your code works flawlessly. However, I messed up during soldering so I can only have a 3x9 Matrix. Can I ask if the comments you put can also be applied for height change, or should I change more parameters? Thanks a lot!!!

    0
    None
    Jhon MarvinLJhon MarvinL

    Reply 10 months ago

    I'm also not sure about what to do regarding line 85 because you said to change the max dot count to the width if I am keeping the 10 height. What should I do if I have to change the height as well?

    0
    None
    JazzHandsFrenzyJhon MarvinL

    Reply 10 months ago

    Email me at jazzhandsfrenzy@gmail.com and I will be able to hopefully guide you to getting the matrix all set up for you. I can't help you right now but should be able to help and maybe even test a code for you within 24 hours hopefully.

    1
    None
    JazzHandsFrenzyJhon MarvinL

    Reply 10 months ago

    ill add in some commits and if they are not specific, feel free to message again.

    0
    None
    Jhon MarvinLJazzHandsFrenzy

    Reply 10 months ago

    OK. I appreciate that. I'm not actually that familiar with these types of Arduino code. Will comment if ever I beed more help. Thanks!

    1
    None
    JazzHandsFrenzyJhon MarvinL

    Reply 10 months ago

    No biggie. I'm not that either but, am learning. Once you semi understand, it gets easier.

    0
    None
    drtydan2019JazzHandsFrenzy

    Reply 1 year 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 1 year 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.