In this Instructable I am going to show how to make a program in Processing that analyzes sound on your computer and sends data to an Arduino that controls an LED matrix to show the spectrum analysis.

I will be explaining where to get materials, explaining the coding and wiring needed and providing example programs that can be adapted.

I will be using an Arduino Nano and and a 32x16 LED Matrix from Sure Electronics.

Step 1: Required Materials/Software and Where to Get Them

The required materials are:
  1) An Arduino(doesn't really matter which version/variant)
  2) LED Matrix (for this Instructable, I use a 32x16 bicolor matrix, but any matrix should work)
  3) A driver chip if your LED matrix doesn't have them integrated, I will be explaining this in more depth.

Inexpensive LED Matrices: Sure Electronics: http://stores.ebay.com/Sure-Electronics
The display I use: http://www.ebay.com/itm/P4-32X16-RG-Bicolor-LED-3mm-Dot-Matrix-Unit-Board-/350527814626?

Required Software:
  1) Arduino IDE (I am using version 1.0) found here: http://arduino.cc/en/Main/Software
  2) Processing IDE found here: http://processing.org/download/

<p>Thanks for the tutorial! Unfortunately, I'm using a different LED matrix which includes different driver chips as well. Here is the matrix I'm using: <a href="http://www.adafruit.com/product/420" rel="nofollow">http://www.adafruit.com/product/420 </a> </p><p>Is there an easy way to convert the code to work with the Adafruit_GFX or RGBmatrixPanel libraries? Thanks!</p>
<p>Well that display would be better driven by a more powerful microcontroller or FPGA, but it is possible. First wiring will require 12 pins on the Arduino. Using Adafruits GFX library will be a very smooth transition though. Mainly just replace and add the libraries, and change the line calls in the code to match the format of the GFX line methods: matrix.drawLine(X1,Y1,X2,Y2, matrix.Color333(r, g, b));<br><br>I'm not sure if the Color333(r,g,b) method understands a single uint32_t value instead of 3 r,g,b values, I'll look into it.<br><br>You don't need to call the dotmatrix.sendframe(); as the board automatically draws the lines when you call each drawLine method.<br><br>As I don't have this board, it will be difficult to help further, but if you have more questions, feel free to ask.<br><br>Also for more info, follow the tutorial at <a href="https://learn.adafruit.com/32x16-32x32-rgb-led-ma..." rel="nofollow"> </a><a href="https://learn.adafruit.com/32x16-32x32-rgb-led-matrix" rel="nofollow">https://learn.adafruit.com/32x16-32x32-rgb-led-mat...</a></p><p><br><br><strong>EDIT:</strong><br>Okay, I've been looking through the RGBmatrixPanel and the Color333 method does not recognize uint32_t variables, so my function above would not work, but I have submitted an issue request to Adafruit to add the feature, so maybe they'll add it, but I doubt it as they haven't changed it in 6 months.<br><br>But good news for now, I have forked the project and included the changes:<br><a href="https://github.com/Aerospacesmith/RGB-matrix-Panel" rel="nofollow">https://github.com/Aerospacesmith/RGB-matrix-Panel</a></p><p><br>I also added the ability to call a Color(r,g,b) method.<br><br>Example:<br><br>RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);<br>uint32_t BLACK = matrix.Color(0,0,0);<br>uint32_t ORANGE = matrix.Color(7,3,0); //Color333 uses values of 0-7.<br><br>void setup() {<br>matrix.begin();<br>matrix.drawLine(X1,Y1,X2,Y2,matrix.Color333(BLACK));<br>matrix.drawLine(X1,Y1,X2,Y2,matrix.Color333(ORANGE));<br>}<br>void loop(){}<br><br><br>I have created test sketches and they compile so it should work, but again, I do not have this board so I cannot test if it actually works.</p><p> Please let me know if my altered library works.</p>
<p>Wow, I'm not sure what you did to the library, but it worked! I copied your example code directly, inserted some coordinates to draw an X on the matrix, and it worked! I also had to change the colors for BLACK real quick because the black didn't show up on the matrix (obviously).</p><p>What next steps do I need to take to get your rendition of the code to work? Thanks again for your time!</p>
<p>Sorry for not replying sooner. Life tends to get in the way very often.<br><br>Anyway, I'm not sure if you figured it out yet, but should be most/all the changes needed (hopefully):<br><br>#include &lt;Adafruit_GFX.h&gt; // Core graphics library<br>#include &lt;RGBmatrixPanel.h&gt; // Hardware-specific library<br><br>#define CLK 8 // MUST be on PORTB! (Use pin 11 on Mega)<br>#define LAT A3<br>#define OE 9<br>#define A A0<br>#define B A1<br>#define C A2<br><br>Make your new matrix library call:<br>RGBmatrixPanel dotmatrix(A, B, C, CLK, LAT, OE, false);<br><br>Then <strong>before </strong>setup() add the various colors, example Orange is 7,3,0; Red 7,0,0; Green 0,7,0 or ANY color you want since you have that board.<br>Just make sure to declare them as uint32_t types like</p><p>uint32_t BLACK = dotmatrix.Color333(0,0,0);<br>uint32_t GREEN = dotmatrix.Color333(0,7,0);<br>uint32_t RED = dotmatrix.Color333(7,0,0);<br>uint32_t YELLOW = dotmatrix.Color333(7,3,0);</p><p>Remove the dotmatrix.clear(); and replace it with<br>dotmatrix.fillScreen(BLACK);<br>this essentially fills the screen with black and clears it.</p><p><br>Then in each line call: dotmatrix.line(x1,y1,x2,y2,color); change the method from line to match the new libraries drawLine.<br>ex: dotmatrix.drawLine(x1,y1,x2,y2,GREEN);<br><br>Change the pixel calls from dotmatrix.plot(x,y,color); to dotmatrix.drawPixel(x,y,color).<br><br>And finally remove the dotmatrix.sendframe(); as this library/matrix driver pushes and draws the screen on every draw command and doesn't need a draw screen command. However this is also a caveat as drawing the screen on each command will slow down the display.</p>
Hey! This is an awesome project, and I got it working. But now I'm trying to make a stand-alone system. Have you had any luck? What signal processing board do you use?
HI, <br />This is very good. But I have only one question. Can I connect directly the sound to the arduino? <br /> <br />PedroRamalho
<p>im just wondering how the FFT program connects to the stereo mixer, the &quot;java (tm) platform se binary pops up but is not reading any audio levels, iv tried playing stuff from youtube and plugin my iphone still not reading anything </p>
<p>Thanks for the tutorial! but when i run the code on processing, there's and error: :(, help me pls !!</p>
<p>how did you fix this??? i am having the same problem</p>
Thanks for your inquiry,<br>This code was written in Processing 1.<br>It will have compiling errors in Processing 2.<br><br>Try running the code in Processing1
<p>I've tried on Processing 1 but the same error :(</p><p>Display 0 does not exist, using the default display instead.</p><p>WARNING: RXTX Version mismatch</p><p>Jar version = RXTX-2.2pre1</p><p>native lib Version = RXTX-2.2pre2</p><p>Exception in thread &quot;Animation Thread&quot; java.lang.ArrayIndexOutOfBoundsException: 1</p><p>at Audio_Spectrum_to_Arduino3216_doublebar.setup(Audio_Spectrum_to_Arduino3216_doublebar.java:68)</p><p>at processing.core.PApplet.handleDraw(Unknown Source)</p><p>at processing.core.PApplet.run(Unknown Source)</p><p>at java.lang.Thread.run(Thread.java:662)</p>
<p>Have you had any success making this with the standalone Arduino? I don't like the idea of requiring a computer too. I'm looking for something more self contained, just an LED matrix with an Arduino.</p><p>Do you think the Arduino Zero would have enough power to do the audio processing?</p><p>Also, do you think this can all be done with a Raspberry Pi 2?</p>
<p>Is there a way that I can invert the output to the led's so they are inverted..like this</p><p>https://www.youtube.com/watch?v=OZyQ-g3klVU</p>
<p>I was wondering how you get the signal to the arduino? I want to be able to plug it into a audio desk. Is there anyway i can do this!???</p>
<p>Hi friend! First, thanks for the tutorial;<br> I have this module purchased on eBay - Then works with this ht1632c library?<br> Thank you</p>
<p>Hi guys! I'm working on a project for class and I was wondering if anyone could help me figure out how to pick up a note through waveform when played on a guitar so it is read through the computer microphone and transferred to spectrum analysis? Thanks!</p>
<p>So first of all when i run the processing script i get an error on line 45. Replacing the [1] with [0] allows it to run. However i have not got it to work yet as when i go into the arduino sketch to change the pins mine is wired up to i get an error as follows:</p><p>Audio_spectrum_from_Processing.ino: In function 'void _data_clr()':</p><p>Audio_spectrum_from_Processing:3: error: 'volatile struct bits' has no member named 'b10'</p><p>Audio_spectrum_from_Processing.ino: In function 'void _wr_clr()':</p><p>Audio_spectrum_from_Processing:3: error: 'volatile struct bits' has no member named 'b11'</p><p>Audio_spectrum_from_Processing.ino: In function 'void _data_set()':</p><p>Audio_spectrum_from_Processing:3: error: 'volatile struct bits' has no member named 'b10'</p><p>Audio_spectrum_from_Processing.ino: In function 'void _wr_set()':</p><p>Audio_spectrum_from_Processing:3: error: 'volatile struct bits' has no member named 'b11' </p><p>Audio_spectrum_from_Processing.ino: In function 'void _data_out()':</p><p>Audio_spectrum_from_Processing:3: error: 'volatile struct bits' has no member named 'b10'</p><p>Audio_spectrum_from_Processing.ino: In function 'void _wr_out()':</p><p>Audio_spectrum_from_Processing:3: error: 'volatile struct bits' has no member named 'b11'</p><p>Any help please Keanan?</p>
<p>Errors:</p><p>Arduino: 1.6.3 (Windows 8.1), Board: &quot;Arduino Uno&quot;</p><p>Build options changed, rebuilding all</p><p>FY5KV8GGYZNVB9C.pde:8:1: error: 'import' does not name a type</p><p>FY5KV8GGYZNVB9C.pde:9:1: error: 'import' does not name a type</p><p>FY5KV8GGYZNVB9C.pde:10:1: error: 'import' does not name a type</p><p>FY5KV8GGYZNVB9C.pde:12:1: error: 'Serial' does not name a type</p><p>FY5KV8GGYZNVB9C.pde:14:1: error: 'Minim' does not name a type</p><p>FY5KV8GGYZNVB9C.pde:15:1: error: 'AudioInput' does not name a type</p><p>FY5KV8GGYZNVB9C.pde:16:1: error: 'FFT' does not name a type</p><p>FY5KV8GGYZNVB9C.pde:17:6: error: expected unqualified-id before '[' token</p><p>FY5KV8GGYZNVB9C.pde:20:4: error: expected unqualified-id before '[' token</p><p>FY5KV8GGYZNVB9C.pde:33:4: error: expected unqualified-id before '[' token</p><p>FY5KV8GGYZNVB9C.pde:38:6: error: expected unqualified-id before '[' token</p><p>FY5KV8GGYZNVB9C.pde: In function 'void setup()':</p><p>FY5KV8GGYZNVB9C.pde:42:16: error: 'size' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:44:3: error: 'minim' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:44:15: error: expected type-specifier before 'Minim'</p><p>FY5KV8GGYZNVB9C.pde:44:15: error: expected ';' before 'Minim'</p><p>FY5KV8GGYZNVB9C.pde:45:3: error: 'port' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:45:14: error: expected type-specifier before 'Serial'</p><p>FY5KV8GGYZNVB9C.pde:45:14: error: expected ';' before 'Serial'</p><p>FY5KV8GGYZNVB9C.pde:47:3: error: 'in' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:47:24: error: 'Minim' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:51:3: error: 'fft' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:51:13: error: expected type-specifier before 'FFT'</p><p>FY5KV8GGYZNVB9C.pde:51:13: error: expected ';' before 'FFT'</p><p>FY5KV8GGYZNVB9C.pde:53:14: error: 'FFT' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:56:16: error: 'Math' was not declared in this scope</p><p>In file included from FY5KV8GGYZNVB9C.pde:8:0:</p><p>C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:88:22: error: expected unqualified-id before '(' token</p><p> #define round(x) ((x)&gt;=0?(long)((x)+0.5):(long)((x)-0.5))</p><p> ^</p><p>FY5KV8GGYZNVB9C.pde:56:21: note: in expansion of macro 'round'</p><p>FY5KV8GGYZNVB9C.pde:57:3: error: 'peaks' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:58:3: error: 'peak_age' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde: In function 'void draw()':</p><p>FY5KV8GGYZNVB9C.pde:65:1: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:69:3: error: 'fft' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:69:15: error: 'in' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:72:3: error: 'freq_height' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:92:58: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:93:62: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:94:62: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:95:62: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:96:61: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:97:61: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:98:61: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:99:61: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:100:60: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:101:60: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:102:60: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:103:60: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:104:60: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:105:60: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:106:59: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:107:60: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:108:36: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:112:3: error: 'port' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:115:23: error: 'freq_array' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde: In function 'void stop()':</p><p>FY5KV8GGYZNVB9C.pde:124:3: error: 'in' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:125:3: error: 'minim' was not declared in this scope</p><p>FY5KV8GGYZNVB9C.pde:127:3: error: 'super' was not declared in this scope</p><p>Error compiling.</p><p> This report would have more information with</p><p> &quot;Show verbose output during compilation&quot;</p><p> enabled in File &gt; Preferences.</p>
The fft code doesn't go in Arduino, it goes in Processing.
<p>it didnt even compile to load.</p><p>the fft is not including in the program to compile</p>
<p>sir i am unable to include fft library files pls help</p>
Your output shows that you tried to load the code in Arduino. The .PDE file goes in Processing. The .ino goes in Arduino.
<p>First of all, thank you for the tutorial. If it wouldn't be much to ask, could you give a list of the materials and the quantity necessary? </p><p>Thank you</p>
<p>Hey, I was wondering if we could use this for the LED matix? https://www.sparkfun.com/products/12583</p>
<p>Hi,I did all things about hardware but differently add microphone instead of jack input.</p><p>I have 16x64 rgb led panel and ard.uno.Before being crazy or broke everything please give me real working code or tell me something about hardware must change.</p><p>Thanks</p>
<p>I cannot find the code this article mentions, where is the link?</p>
<p>Nice job! I'm looking for some help with a project I'm working on. I'd like to display different animations on different LED matrix panels and control them all with one Arduino or BeagleBone Black. Any ideas? My failsafe is to combine several animations into one file and space them out so they look as if the different matrices are showing different animations.</p><p>Thanks for any advice or help anyone can offer!</p><p>- John</p>
<p>how do I change the audio source? I want to use my music on my PC that is connected to my surround stereo system via Toslink and I would like to have the line in set to my speaker out (optical) so when I play music in media player or games or what not I want the sounds to display on the 32x16 bicolour matrix display. any help would be great, PS stereo system does not have preouts so I can't hook up a cable from my stereo, back to my computer line in.</p>
<p>also is there a way to change the speed it seems to have a delay from what comes out of the speakers to what is being displayed</p>
It's a wonderful project, is it possible to make this without Arduino?
A microprocessor of some kind is required to drive the display.
Yes, an ATMega or a PIC will be required, I am really interested in a schematic + source code. <br> <br>Anyone has such a thing?
hi. <br>how to make ardunio source for max7219 (8x8matrix use) <br>it was too hard to make source <br>help~~
Sorry i haven't replied in a while, things have come up. I am currently working on an Arduino stand-alone spectrum analyzer. I am waiting for the Due to come out before resuming my work.
Hello , I am doing almost the same thing as your project, except that I'll be using RGB LEDs and actually solder them onto a PCB and not use an already built LED matrix. I'm using the Arduino Leonardo and a MSGEQ7 IC which is a graphic equalizer IC with 7 bands. I'll be making 7 columns of RGB LEDs. Each column will somehow correspond to the 7 different frequencies through the digital output pins (CLK, Data, Latch) with 74HC595 shift registers in series. <br> <br>Since i'll be using 7 frequencies, will i need to connect each of the 7 columns to 7 different digital output pins on arduino leonardo? <br> <br>--or-- just connect the shift registers from all the 7 columns in series (daisy-chained) and let the arduino know what frequency band will correspond to each column? (if so, does the arduino need to be programmed already to know what frequency will correspond to each band?) <br> <br>--or-- all the Shift registers from each column be hardwired in series independently from the other columns?? <br> <br>I'm stuck here and have a deadline for this... Please help!
Here's a library for the MSGEQ7. <br>https://github.com/justinb26/MSGEQ7-library <br>I just ran across this and remembered you.
Okay, so if I understand correctly, you will use MSGEQ7 IC to process your audio. The MSGEQ7 then sends 7 Analog signals in sequence that represent the max peak of these frequencies: 63Hz, 160Hz, 400Hz, 1kHz, 2.5kHz, 6.25kHz and <br>16kHz. You then will use a Leonardo to read the data and output corresponding levels to seven columns of RGB LEDs. The seven columns of LEDs will be driven by shift registers. Every 3 shift registers can control 8 RGB LEDs(1 for 8 red, 1 for 8 blue, 1 for 8 green). So for a matrix of 7x8 RGB LEDs, 21 shift registers will be needed. These could be daisy chained to only use 3 digital pins on the Leonardo, or they could be split up. <br>The MSGEQ7 will need to be hooked up as stated in it's datasheet: https://www.sparkfun.com/datasheets/Components/General/MSGEQ7.pdf <br>
Hi, great project! I have been looking into something like this for a while. I saw you're working on a stand alone version. I just was this by adafruit. http://www.youtube.com/watch?v=Tmpl5KA02S4 <br>It may be a help. I just made a one color 8x8 matrix with a max7219. I wonder how easy or hard it would be to transfer adafruits code to use a max7219. It's a bit over my head but I'd be very interested if you have any ideas. Thanks, <br>Matt
Hi! Great project, looking forward to building me one of these some day. Just out of curiosity, have you been able to daisy chain more than two displays using this library?
I only have one display. I'm not sure if this library supports more than two displays. Even if it did, the Arduino isn't fast enough to really drive more than two, unless low frame rate wasn't an issue. Maybe the Due could control more.
Is this the same as a real time sound/music graphic equalizer? Or are they different?
I finally got it working, its a little annoying to get the sound input right but it works and looks really cool.
First congratulations for your work: <br>I wonder how can I use instead of using pixel dot matrix Ws 2801, you have video on this Youtobe spectral analyzer
kinda off topic, what about going the other way around. ie audio in to arduino vu on computer
So if it takes it from the stereo mix:<br><br>Does it work with windows and mac?<br><br>Could you modify the code so that it takes a line in from a device?<br><br>Thanks<br>
Windows will work without any problems. &quot;An AudioInput is a connection to the current record source of the computer. How the record source for a computer is set will depend on the sound-card and OS, but typically a user can open a control panel and set the source from there. Unfortunately, there is no way to set the record source from Java. This is particularly problematic on the Mac because the input will always wind up being connected to the Mic-In, even if the user has set the input differently using their audio control panel.&quot;<br><br>Source: http://code.compartmental.net/tools/minim/manual-audioinput/

About This Instructable


219 favorites

More by Keanan: Arduino / Processing Audio Spectrum Analyzer
Add instructable to: