32-Band Audio Spectrum Visualizer Analyzer

This project is for making a 32-band audio (music) frequency spectrum analyzer / visualizer using Arduino.

Jan 20, 2019

245522 views

235 respects

Components and supplies

1

32x8 LED matrix display

1

Arduino Nano R3

2

Capacitor 100 nF

1

Resistor 10k ohm

2

Resistor 100k ohm

3

Resistor 4.75k ohm

1

Pushbutton switch 12mm

Tools and machines

1

Soldering iron (generic)

Project description

Code

Source code

arduino

Source code

arduino

Downloadable files

Schematic diagram - updated

Schematic diagram - updated

Comments

Only logged in users can leave comments

audiotechno1000

2 months ago

Hello Shajeed Can this be code to have 16X32 if so let me know and if possible can you code this. Thank you

stevenjryall

6 months ago

I've built this and it works but there's definitely some changes I'd strongly recommend! There's definitely a lot of noise in the system, I'd recommend trying to use a very clean power source and ground everything really well. I'm currently using 330nF caps on the audio in which seem to help with the noise somewhat better. Also added a 330nF cap between AREF and GND, feeling this may help clean up noise in the lower frequencies. HOWEVER, I do feel some level of software noise gate may really help clean up the visible noise causing some LED's to flicker when no audio is running through the system. Some kind of software feature to detect the volume of audio coming in and only trigger the LED's when it's at a minimum level. The minimum level could be really low but it may eliminate some of the visible noise, if not all. DAW's (digital audio workstations, music recording software) as well as physical sound hardware often implements features like these, I'm pretty sure something like that could help here too! The suggestion to change ADCSRA = 0b11100101; to ADCSRA = 0b11100100; which changes the division factor to 16, definitely helps to spread the visible frequencies. Using a sample rate of 128 does seem to spread the visible frequencies better but an UNO really can't keep up. I'm considering perhaps a microcontroller with a faster frequency could keep up better? Haven't tried reducing the resistance of the audio inputs to see if signal can come through more amplified - currently have a headphone jack set to full gain to give me enough juice for it to work properly - but I imagine messing with those resistance values will help. All in all, this is an awesome and well implemented project that can be expanded on a lot. Now, time to print a cool case! ;)

tigersaw

7 months ago

Very good - I built the project into an old Sony tuner, only changes were to change the input resistor to 100k and make it dual channel: https://www.youtube.com/shorts/GFvtqTAg4cM

bga1

8 months ago

Hello shajeeb, I would like to build this project, but I am getting this message when I attempt to compile: Compilation error: 'arduinoFFT' does not name a type; did you mean 'ArduinoFFT'? I did add both libraries: arduinoFFT.h and MD_MAX72xx.h I am using a Uno board.

rafununu

7 months ago

Try with version 1.1 of arduinoFFT

sorali

a year ago

Thank you for sharing a great project. I got a great idea for using the LED matrix.

sorali

a year ago

Thank you for sharing a great project. I got a great idea for using the LED matrix.

javifv7

a year ago

Hola, que diferencia hay entre los código y por que me sale que los tengo que declarar, o solo me pasa a mi?. Un saludo

seregaz

2 years ago

that MAX7219 LED display can be enlarged ? if i will buy two 4x8x8 and attach one segment to make 5x8x8. it will work? it looks like segments attached as parralel connection. so can i hope 5x8x8 will work? another question will it work with fake arduino? some Aduino Nano with CH340G. can this arduino get voltage too same time? and work with IR remote for switch mode? i need two variants: voltage at left part + equalizer like here, switch mode by remote, voltage + volume peaks for stereo channel. no any arduino experience.

richard_gui

2 years ago

Hi, I want to change the frequency spectrum on my display. For example, 280 Hz to 14k Hz. Want part of the code I need to change to achieve my goal?

rudyx77

2 years ago

Do you have this circuit diagram made in Tinkercad, if yes, could you send it to me at: rudilipo10@gmail.com

rudyx77

2 years ago

I am doing it as a graduation project and I would need it

Anonymous user

2 years ago

hi shajeeb, thanks for sharing the amazing projects. currently i want to use 8x8 led matrix. can u guide me which part from the coding that i need to change? thanks

dougal

2 years ago

Nice clean uncomplicated example of sampling, FFT and display. Well done, excellent showcase !

Anonymous user

2 years ago

Hello, I wanted to ask if I can also use RGB's in the dimensions 14x20 instead of the LED matrix display?

shajeeb

2 years ago

It is possible to use any type of led/display in place of dot matrix display. With reference to the flowchart given above , you will have to change everything below 'compute FFT' block to make it working with other type of displays.

Anonymous user

2 years ago

Hey, it's a cool project but I have a question: would it be possible to use RGB LED strips instead of the LED matrix?

Attilator

2 years ago

Hi, thanks.   Probably yes, but it needs a different library a change in code. ______________________________________________________________

Anonymous user

2 years ago

Very cool project! I am trying to replicate this project but with a P10 DMD module. What changes will have to be made to make this code compatible with these displays?

Anonymous user

2 years ago

Great project was fun to make, my only issue is that I am getting a high pitched tone in my headphones with each illumination of an LED. I am using a two way splitter, one goes to my headphones and the other to the audio input of the project. If I use enough volume it will cause a cascading loop on the max7219. Any suggestions? Everything else works great though.

shajeeb

2 years ago

I don't suggest to use headphone and analyzer in parallel for various reasons. You will have to keep at high volume for getting full display (vertical) on the analyzer. Impedance mismatch of the headphone and the analyzer may cause the problems you explained. Some music player's output may be coming out of bridged amplifier where grounding one line can cause problem. Thats said, you can experiment and make It working. And make sure grounding is perfect.

Anonymous user

2 years ago

Would it be possible to do this with an adafruit 32x32 RGB led matrix? I'm not quite sure how to implement the drawing of the signals to the matrix (it uses functions such as drawline). Any help would be much appreciated, thanks

shajeeb

2 years ago

Yes, it will work the required code change. You can use libraries like <FastLED.h> & <LEDMatrix.h>

Anonymous user

2 years ago

Hi. Great job on the coding! I am making my own matrix with a pcb kit. It is pre programmed and has CS CLK Data In/Out 5v and GND on each of 4 pcbs to create an 8x32 display. Can I use this code as is, or do I have to modify it? Also, can I just hook up data out from it’s control board, and data out from an Arduino to a switch to select which code I want to use, or do I have to hook up CS and CLK from the Arduino too? I know I have a lot of questions, but I’m almost done. Could I use a microphone and still get these results? Lastly, how could I make this with rgb color values for each of the 8 leds in the 32 sections? Sorry for all the questions, but I’m a big newb. Thanks!

Anonymous user

2 years ago

Hi, i'm not found this project library file. Please give this library file link.

Anonymous user

2 years ago

Dear shajeeb, Why do you use 2 100 nF capacitors on your audio input? And what do you use the resisitors for on the audio input ? I am just learning how to connect an audio input to the arduino and find this really difficult.

shajeeb

2 years ago

Those Capacitor + Resistor pairs are for mixing both cleft & right audio channels.

Anonymous user

2 years ago

Hello Shajeeb, I have assembled this audio visualizer of yours and I'm wondering if I can get the visualizer to work at volume 40-50 as effectively as it does at 100? (I have this hooked up to my pc) Thanks!

Anonymous user

2 years ago

You might choose the way i've written above as an answer the the divider question. Never tried, but it should scale your audio volume input up or down when you change it. (You may observe a short delay)

Anonymous user

2 years ago

HI, thank you for such great project! I have already done it and I even made housing for it using 3D printer. Anyway, I have a question. When i connect Arduino to some kind of source (for example laptop) but audio input connect to different source (for example mobile phone), the analyzer is not working. I have connect Arduino and audio input into the same device. What is the reason? i have been thinking about it but still can't find the reason. Thank you!

shajeeb

2 years ago

Thanks, It is not clear the problem you are trying to explain. Are you trying to say it works with laptop audio output but not with mobile output ?

Anonymous user

2 years ago

Hi, well done with the housing. Would you please share it with us? Where can we find the .stl files?

Anonymous user

2 years ago

Hey!. I'm having a problem where after the code is uploaded the LED is continuous lit up and I'm not able to to test it with Sine wave. Also, I fed audio through my phone but I see the LED is still continuous lit up. What should I do? I'm pretty sure my connections are correct.

shajeeb

2 years ago

Disconnect the audio input part and see what happens. If the writing is correct & code is loaded properly then there should be nothing on the display now.

Anonymous user

2 years ago

Hi, This project looks amazing. I have a question, can I use a liquid crystal display instead of a LED matrix display? Thanks

shajeeb

2 years ago

Yes , you can use liquid crystal display instead of a LED matrix display with required library (<LiquidCrystal.h>) and code changes. Please refer to online documents to get details of managing LCD.

Anonymous user

2 years ago

I gave this a 120 BPM kickdrum sound and it sometimes gave a much smaller or even no pulse on the display. Can I ask why is that? I need my results to be consistent.

Anonymous user

2 years ago

Awesome project! thanks for sharing. Before I stumbled on your post, I was looking into utilizing MSGEQ7 chip for the signal analysis. I even ordered a few of them :) If you don't mind, I have a couple of questions . 1. the 2.75v mentioned in the diagram, is that due to the 32Kohm AREF internal resistance? 2. In your post-processing, you added "constrain(data_avgs[i],0,80)". doesn't this clip your output? can't the the map function alone do the trick? Cheers,

shajeeb

2 years ago

Thanks 1. Yes 2. constrain is for limiting the upper side (clip) Please experiment with various combinations to get different outcome.

Anonymous user

2 years ago

Definitely a very interesting project! It would be even nicer if it was used Bicolor or Tricolor Led Matrix! Has anyone done?

Anonymous user

2 years ago

Any way to adjust the scale to use more of the display? Seems that most of the #2 display sections are about as far as it lights. I can get activity along the whole display by touching the unconnected audio input. I checked all the components and hand picked for best accuracy and match. Unfortunately I don’t have access to a signal generator to fully check the out. Any thoughts? This is a great project.....thanks for sharing it!

Anonymous user

2 years ago

From what I can tell from testing with a frequency response app (and some slightly modified code to run this on an LCD), the scale this uses is linear. 10kHz lines up in the center of the screen, theres equal distances between 5k-10k and 10k-15k, and all the lower frequencies are grouped up in one area. Since the lower frequencies are all getting compressed together (which is where a lot of music happens in),this would explain why all the lights group up in the spots closest to the left of the screen. It generally makes more sense, and is more traditional, to use a log scale from 20Hz-20kHz with audio. Ex, here is a graph of audio frequency ranges: https://www.google.com/url?sa=i&source=images&cd=&ved=2ahUKEwi_68eF69vlAhXPmq0KHbR2CtQQjRx6BAgBEAQ&url=https%3A%2F%2Fwww.audioreputation.com%2Faudio-frequency-spectrum-explained%2F&psig=AOvVaw0RKByNehCSf8qFBrw6kI1y&ust=1573344464507394 Ill be modifying this code sometime soon to try to have it use a log scale.

shajeeb

2 years ago

It is designed to display entire audio range upto 19khz in 32 intervals. If you are looking for a system to display frequencies only up to 4khz then first thing you need to modify is the ADC sampling frequency. Please read documentation of ATmega328P and experiment.

shajeeb

2 years ago

Yes, this implementation uses linear scale to divide entire audio frequency range. Did you implement it in logarithmic scale ?

Anonymous user

2 years ago

Thanks for your explanation of what you found. I’d love to pull this project out of the drawer it’s been hiding in. I think the code change you suggest would be awesome. Thanks!

shajeeb

2 years ago

How are you feeding audio into the Spectrum analyzer ? If the signal has all frequencies and are reasonably strong enough then different will light up. You may try adjusting bass / treble settings (if your system has) to observe the response change.

shajeeb

2 years ago

There are online tone generators which can generate sine wave at audio frequencies. Try feeding those signals by connecting output of your computer / laptop .

alien666dj

2 years ago

Hello! Have you modify/made changes to the code? Help me figure out how to make two LCD 8x64 matrices, what changes in the code are needed?

thote1276

2 years ago

Hello, Thanks for the project I have also the project to visualize frequencies from 60Hz to 16kHz. To achieve this, you say that we need to change the ADC seeting ? Is there an other solution to visualize low frequencies with the FFT ? Thomas

lumek

2 years ago

I observe exactly same thing. I'm wondering if the FFT library has a setting to work in different frequency range or the RC combination could shift it. Any ideas much appreciated.

Anonymous user

2 years ago

Thanks for responding. I’ve tried several audio sources. From preamp output to amplifier output and a lot in between. I adjusted bass and treble controls with no real change. Aside from the 3v3 voltage being slightly higher than your published values, I’m suspecting that 3 different Nano clones i’ve tried may not have the output speed the display needs to make this work. I’m ordering a “Genuine” Arduino Nano to compare them. I’ll post the outcome here. Ken

Anonymous user

2 years ago

I don’t know why I didn’t think of that..... I’ll grab one and see what happens. Thanks for the suggestion.

Anonymous user

2 years ago

So I procured a tone generator app. Although I can get the entire length of the display to light with frequency changes, the scale is too high. For example, 18khz is almost at the end of the display, 9.5khz is in the center and 4.2khz is almost at the beginning of 5he scale. It seems to me that the whole scale needs to shift down in frequency to be visually appealing and more useful in my situation. The current display output pretty much shows the first 3 or 4 columns to be the active ones. Any thoughts about shifting the whole thing down in frequency? Maybe widen the range? Thanks for the tone generator app suggestion!

StantomRM3

2 years ago

It is a great project and I'll post up how I got on, however having the same "challenge" as the lads above to spread the display out of the left edge I made some slight adjustments to the ADCSRA setup which seems to have had the right effect. It might not be as pure as original but visually provides more width. Useful site: https://garretlab.web.fc2.com/en/arduino/inside/arduino/wiring_analog.c/analogRead.html Change: // ADCSRA = 0b11100101; // set ADC to free running mode and set pre-scalar to 32 (0xe5) ADCSRA = 0b11100100; // changed last bit to change division factor from 32 to 16 Great job sir

Anonymous user

2 years ago

Great project, thanks for the idea of using FFT transform for spectrum analysis. One note: you code does it in 2 steps: collects samples and then analyses them. While collecting it technically sits waiting, then when running FFT it is not collecting. You can do both if you set ADC to use interrupt on completion (ADCSRA.ADIE) calling subprogram . Meanwhile FFT can run. Hope that will let you to increase sample size to 128 without performance loss.

shajeeb

2 years ago

Thanks for the suggestion. Samples are collected in ADC non-blocking mode hence reading 64 samples take less than 2 ms. Most majority of the time is being taken for FFT calculation which is in order of magnitude compared to sampling . So, having another samples ready while FFT is being calculated may not be useful and will have to be discarded multiple times. Also doing FFT on 128 samples (with the library I am using & ATmega328P) make the entire system laggy which spoils the fun. If interested someone can pick up on this suggestion and try out.

Anonymous user

2 years ago

I am new to Arduino and coding but i have a question. If I will be using led strips to make this. Will i have to change the code at all in order to use led strips. I plan on making it 32 band like you did so 32 leds across but will i have to change anything if i decide to make it more than 8 less vertically. Maybe like 20 or so. Thanks for any advice!

hedleyp

2 years ago

Hi, yes you will need to change the code. If you are new to Arduino and coding then I would start off by parking this sketch and just working on reading audio from an input so you can then view it using the basic example ReadAnalogSerial script. You will need to build a Passive RC HPF filter and bias the input so it reads at 512 on the Analog pin. If this means nothing to you like it meant nothing to me a week ago, then start off with baby steps! It will mean more to you at the end and have you grinning when you get it working and also understand it. Then once you can read the analog pin and see test frequencies in the Serial plotter it is time to move on to learning FFT and then add on the lights as an output. Otherwise this script will mean nothing to you and you won't learn anything or be able to fix/tweak it.

Anonymous user

2 years ago

Hello, for the audio input, can I simply use a TRRS 3.5mm breakout board https://www.makerlab-electronics.com/product/trrs-3-5mm-jack-breakout/ and a male-to-male 3.5mm jack? I intend to connect my phone or computer on the other end of the male-to-male jack and the other end to the TRRS 3.5mm breakout board which connects to the spectrum analyzer arduino. Will it be possible or safe?

Anonymous user

2 years ago

Hi, I want to change the frequency spectrum on my display. For example, 280 Hz to 14k Hz. Want part of the code I need to change to achieve my goal?

Anonymous user

2 years ago

Hola gracias por el aporte , mi consulta es saber si se puede utilizar tira led teniendo en cuenta que son RGB ) multicolores, como se nombraría los led de una barra (tira de led ) estaré atento en servaver@hpotmail.com

Anonymous user

2 years ago

can someone help me with construction of this project?

Anonymous user

2 years ago

do you have any tips on getting the code to work with an RGB matrix and having different colors for different intensity levels on each frequency?

shajeeb

2 years ago

Sorry, I never experimented with RGB matrix and libraries.

Anonymous user

2 years ago

I built this, with only 8 bands, and an electret microphone with an OpAmp based amplifier. And learnt something useful :-) Observing that the lights were blinking prettily, but seemingly without connection to the music, I attached the oscilloscope to the amplified microphone signal (I’d done that before, and it looked fine, but just in case). What I saw was a 740Hz or so pulse signal completely drowning the microphone signal. The interference goes away when I detach the LED matrix. Vcc looked fine, so I assume the interference went over the air from the display to the jumper wires connecting my mic to the preamplifier. Lesson learnt: when using microphones near devices that can produce interference, you need better shielding than a breadboard and some jumper wires 👍

Anonymous user

2 years ago

Fantastic project, Making this as a Christmas present for my dad who's an audiophile. One modification question. I connected the 2nd 8x32 display after the first one which makes the same image appear on the 2nd display, which is fine. However I wanted to flip the image on the second display so that that the 2nd display is like a mirror reflection of the first one. Like if you lay one 8x32 on top of a mirror sort of thing only in a different color. I tried doing a flip flop by overwriting the contets of your button check function with int flip = false; void displayModeChange() { if (flip) { for (int i = 0 ; i <= 8 ; i++ ) { MY_ARRAY[i] = MY_MODE_1[i]; } } else { for (int i = 0 ; i <= 8 ; i++ ) { MY_ARRAY[i] = MY_MODE_5[i]; } } } I figured that right after you write mx.setColumn(displaycolumn, displayvalue); I can swap out the array MODE_1 for array MODE_5 and the next cycle it would just use that but it seems to just write the data to both display. I feel like it's a syncronous.

shajeeb

2 years ago

You are trying to independently control both displays. For that you need to create another display object (by copying line 61 of the original code) and feed data into that object separately.

ihavenoidea2203

2 years ago

Hi! I have implemted you project and I have a problem. Instead of having multiple LED light up on a column, there's only one LED on at a time. do you know what can be the cause?

Anonymous user

2 years ago

Hello, First of all very nice Project. Now my Problem is even when not active some pixels are illuminated on the Matrix Display and i don't know why. I've uploaded a short Video to Youtube to better show my problem. Would really appreciate some help because i've rebuild this to use it in School Link : https://www.youtube.com/watch?v=UO_fKas3Lq4

Anonymous user

2 years ago

Like my problem in the last comment...i've solved it by edit adc value (try with -256)

Anonymous user

2 years ago

I was wondering, if I could use something else instead of the 100nF capacitors? I only have 22pF, 104pF, 10uF, 100uF capacitors at the moment and I dont want to wait weeks for new ones to arrive

shajeeb

2 years ago

You can connect + of the capcaitor sign towards resistor.

shajeeb

2 years ago

It is suggested to use non-polarized 100nf or 220nf or 470nf capacitor. You can try with 10uF, but response to signal may be slightly slow.

shajeeb

2 years ago

Your understanding is correct, you can use 10uF.

Anonymous user

2 years ago

My 10uF clearly has a big minus on the side of it. It also says ROHS which I dont know what it is. Can it still be used? (Ps.: these came in my arduino starter kit so I dont know much about them)

Anonymous user

2 years ago

I'm quite new to electronics, does non polarized mean that the capcitor does not have a plus and a minus? If so then I think I only have the 22pF, 104pF capacitors which are non polarized.

Anonymous user

2 years ago

Hello, Friend! I want to ask about your conections. You say that with R1 & R2 we divide 3.3v for our AREF pin. What is the purpose of conecting signal between R1 and R2? Does this mean that we divide our signal also?

shajeeb

2 years ago

R1,R2 voltage divider is for providing a DC bias to audio input. This makes audio to fluctuate above a fixed DC voltage instead of zero voltage. With this ADC can sense both positive and negative cycles of the input audio.

Anonymous user

2 years ago

Cool project. Would love to pick your brain for a project of mine.

Anonymous user

2 years ago

Hi there, this project looks great! I am looking to do a similar project myself (I am Arduino noob). Could this be implemented on a 256 x 64 OLED Display? https://www.aliexpress.com/item/NEW-OLED-Display-2-8-256-64-25664-Dots-Graphic-LCD-Module-Display-Screen-LCM-Screen/32988174566.html?spm=a2g0o.cart.99999999.259.38443c002yNZUR

Anonymous user

2 years ago

of course, this can be displayed on many things. Your device is most likely have similar methods to display its content.

Anonymous user

2 years ago

Everything worked just fine but the modules weren´t in the correct order. So 280hz, for example, is on Modul 4 on the left side. 18600hz is on Module 1 on the right side. The direction is left to right, but the order of the Modules is 4 3 2 1. Anyone else with that problem? Maybe it´s a newer version of the Library

shajeeb

2 years ago

Your display hardware module could be different. Try with changing the line #define HARDWARE_TYPE MD_MAX72XX::FC16_HW to #define HARDWARE_TYPE MD_MAX72XX::GENERIC_HW or #define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW

novax1

2 years ago

Hello If you have not been able to solve. I had the same problem and I could solve it by modifying the MD_MAX72XX file. I give an example. directory // documents / Arduino / libraries / MD_MAX7219, the document to be modified is MD_MAXX7219.h #define USE_ICSTATION_HW 1 /** •\\file •\\brief Main header file for the MD_MAX72xx library */ /** \\def USE_PAROLA_HW Set to 1 (default) to use the Parola hardware modules. The software was originally designed to operate with this hardware type. */ #define USE_PAROLA_HW 0 /** \\def USE_GENERIC_HW Set to 1 to use 'generic' hardware modules commonly available, with connectors at the top and bottom of the PCB, available from many sources. */ #define USE_GENERIC_HW 0 /** \\def USE_ICSTATION_HW Set to 1 to use ICStation DIY hardware module kits available from http://www.icstation.com/product_info.php?products_id=2609#.UxqVJyxWGHs This hardware must be set up with the input on the RHS. */ #define USE_ICSTATION_HW 1 /** \\def USE_FC16_HW Set to 1 to use FC16 hardware module kits. FC16 modules are similar in format to the ICStation modules but are wired differently. Modules are identified by a FC-16 designation on the PCB */ #define USE_FC16_HW 0 /** \\def USE_OTHER_HW Set to 1 to use other hardware not defined above. Module 0 (Data In) must be set up on the RHS and the CUSTOM hardware defines must be set up in the MD_MAD72xx_lib.h file under for this section, using the HW_Mapper utility to work out what the correct values to use are. */ #define USE_OTHER_HW 0 sorry for English but I have to translate it. I hope you find it useful. regards

Anonymous user

2 years ago

I am having a problem. I did the same project with ESP32, with a splitter cable of which one end is going into spectrum analyser, and the other powers my headphones so that I can listen to the song. For some reason there is a lot of noise in my headphones the moment I power up this spectrum analyzer system. Can you please help me? P.S I am using only the left output of audio. Also, I am powering the whole thing using my laptop's USB. Putting a 220uF between VCC and GND of esp32 reduces the noise by a tiny bit. But not much.

Anonymous user

2 years ago

Hi Shajeeb Thanks for sharing your project with us all. It is very well documented and just by following it I, for one, have learnt a lot about audio, the hardware as well as FFT. There’s just a couple of minor things I’m not too sure about - - why do you have to divide the sample value by 8 before doing the FFT ? - is it really necessary to subtract the 512 due to the DC bias ? Thanks

shajeeb

2 years ago

Thank you. 1. Division by 8 is to reduce the amplitude of the measured input so that it can be uniformly (vertical) fit in the display used 2. Yes 512 need to be subtracted otherwise it will appear in the output as a DC level.

Anonymous user

2 years ago

Do you divide because you assume, that audio input comes in at max volume? In this case you may not be able to bypass your audio signal to speaker because you might want to change the volume down. I would suggest a 'learning algorithm' searching for the peak audio amplitude. Maybe with a circular buffer in addition, so you can mean the amplitude peak over a longer time and check for the amplitude history. With the peak you can adjust your divider You may use the amplitude (history) for a pi-control algorithm with saturation aswell. Saturation would be necessary to avoid infinite integration when volume is to low. (E.g. no audio input available) In this case it also could be a way to skip the controller algorithm. In order to that you can lower the volume just with an minor impact because of the low freqent step response from the algorithm (Depends on the time slot you select for the amplitude update and whether you choose a moving average by the circular buffer).

Anonymous user

2 years ago

Hello! I am working on this project and was wondering what steps you can take to reduce noise? placing a 100nf cap between Aref and ground seemed to help with higher frequency noise (1k-15k) however I still see lots of feedback in the low frequency range (20-500 Hz). Will adding series capacitance on my L and R audio inputs help this? I currently have 220 nF across, and 100nF was still very noisy on the audio input. Also has anyone successfully implemented a log scale? My setup momentarily worked with no noise or flickering, but still looking at a log scale to shift some of the LED activity to the right of the display matrix...

Anonymous user

2 years ago

Yes I implemented a log scale sort of but I used linear FHT output and 5 dB/octave gain to logify the response since it made sense visualizing music. All about it on my blog: https://emumannen.blogspot.com/2021/09/arduino-goes-to-town-part-4.html

sbrennessel

2 years ago

Hello Shajeeb! Thank you for posting this, it has really jump started a personal project of mine! I am trying to adapt your code to use 32 one meter long LED strips instead of an LED matrix display. I am using the FastLED library to run the LED strips and hoping to use your code for the FFT data. I was wondering if you could explain what the peaks[] array is doing in the "send to display according measured value" section of the loop? Is this array only used when the program is in the "only peak pattern"? Also, in the "send to display according measured value" portion of the code, I wanted to make sure, after the line data_avgs[i] = map(data_avgs[i], 0, 80, 0, yres); if yres was set to be 60 (the number of LED's in the strip) instead of 8 would data_avgs[5] be equal to the number of LED's that should be lit up in the 6th strip? Thank you!

Anonymous user

2 years ago

I would like to create something similar. If you succeed please message me ;)

Anonymous user

2 years ago

cool project! do you mind posting a photo of the arduino nano board and the connections to help visualize the schematic?

shajeeb

2 years ago

Please refer to the new images I added which shows two different ways of feeding audio input. I don't suggest to use another mic for audio pickup as the signal strength and frequency response will depend a lot on that mic.

shajeeb

2 years ago

You need to assemble only the items shown in the schematic diagram. Everything except display will easily fit on a breadboard. Second board what you see in the photo is an amplifier which connects to external speaker. That amplifier is not part of the Spectrum analyzer but it is to hear what is being played.

shajeeb

2 years ago

I may try to make a diagram with Fritzing which will have physical wiring details.

Anonymous user

2 years ago

hey, just wanted to check in about a possible diagram with fritzing or a photograph of the wiring? I'm trying to build something similar and was wondering if I mount everything on a breadboard? it looks like you have two breadboards in the photo?

Anonymous user

2 years ago

I am a little confused on how/where to connect the audio. Is there anyway you could post a diagram of this? How do I connect the left and right channels and also an external speaker? What kind of cord/cable do you use? Do you think I could use a microphone to pick up music instead? Thank you so much for answering my questions!

Anonymous user

2 years ago

The schematic is wrong - The 10k resistor should be between D5 and GND, not in series with the push button. As it is shown the link between D5 and gnd will hold D5 permanently low regdless of the pushbutton state. Otherwise a very nice project! ;)

shajeeb

2 years ago

Thanks Skywatch for catching it . I have updated the diagram.

novax1

2 years ago

Hi There is way to lower the brightness of max7219. thanks

shajeeb

2 years ago

You can use mx.control(MD_MAX72XX::INTENSITY, 8) to change the brightness. You can find more details inside the example "MD_MAX72xx_Test/MD_MAX72xx_Test.ino"

novax1

2 years ago

Hi all. I'm new in this. Good hour, good job, it works perfectly. It is always good to find for those who know less. Thank you. Sorry for the English but I have to translate Spanish.

shajeeb

2 years ago

Thanks.

Anonymous user

2 years ago

Hi, I have connected up the parts as shown in the schematic diagram and used the Arduino code above but the dot matrix units just light up random LEDs. What could cause this?

Anonymous user

2 years ago

Good job ! So I want to make a display with 64 x 8 resolution, but I don't know how to change the code has columns and rows I changed the columns from 32 to 64 and then I went to that part of the code and change 31 to 63 displaycolumn=31-i; Believing it would be possible, but it didn't work out.

Anonymous user

2 years ago

Hi Shajeeb, Thank you for this code. I think there is a bug in your averaging loop where you don't traverse the entire vReal array. Since step evaluates to 1, you only traverse half of vReal and only have one sample in each average. int step = (SAMPLES/2)/xres; //- EVALUATES TO 1! for(int i=0; i<(SAMPLES/2); i+=step) //- CORRECT { data_avgs[c] = 0; for (int k=0 ; k< step ; k++) { //- ONLY EXECUTES ONCE data_avgs[c] = data_avgs[c] + vReal[i+k]; //- k IS ALWAYS 0 BECAUSE STEP IS 1 } data_avgs[c] = data_avgs[c]/step; //- ONLY AVERAGES THE VALUE IN i c++; } Is this correct? I've done it the following way: #define SAMPLES (64) #define OUTPUT_N (SAMPLES / 2) int samples_per_average = SAMPLES / OUTPUT_N; //- EVALUATES TO 2 for (int i = 0; i < OUTPUT_N; i++) //- LOOPS 32 TIMES, LIKE YOURS { averages[i] = 0; for (int j = 0; j < samples_per_average; j++) //- LOOPS TWICE { int idx = (i * samples_per_average) + j; //- TAKES i AND j INTO ACCOUNT averages[i] += vReal[idx]; } averages[i] /= samples_per_average; //- AVERAGES 2 VALUES }

Anonymous user

2 years ago

Dude.Thanks for your post. Have you try your code? It's working or have some problem?

Anonymous user

2 years ago

would someone be kind enough to help me under stand the following code? void setup() { ADCSRA = 0b11100101; // set ADC to free running mode and set pre-scalar to 32 (0xe5) ADMUX = 0b00000000; // use pin A0 and external voltage reference pinMode(buttonPin, INPUT); mx.begin(); // initialize display delay(50); // wait to get reference voltage stabilized } void loop() { // ++ Sampling for(int i=0; i<SAMPLES; i++) { while(!(ADCSRA & 0x10)); // wait for ADC to complete current conversion ie ADIF bit set ADCSRA = 0b11110101 ; // clear ADIF bit so that ADC can do next operation (0xf5) int value = ADC - 512 ; // Read from ADC and subtract DC offset caused value vReal[i]= value/8; // Copy to bins after compressing vImag[i] = 0; }

shajeeb

2 years ago

AVR documentation might help you get details of these. Sample one is http://www.avrbeginners.net.

Anonymous user

2 years ago

hi i am new to this and wanted to build it but i was wondering where the arrows pointing down connect to in the project when looking at the diagram

shajeeb

2 years ago

Arrows pointing down means ground of power supply (standard representation of ground in electrical/electronic diagrams), in our case it is negative terminal of 5v supply.

Anonymous user

2 years ago

Hallo sir.. Can I use led instead of dot display. For that which changes I need to make in this project? Thank u

shajeeb

2 years ago

It is possible to use any type of led/display in place of dot matrix display. With reference to the flowchart given above , you will have to change everything below 'compute FFT' block to make it working with other type of displays.

w3223w

2 years ago

An integrated and potentiometer is used in the circuit in the video, but they are absent in the diagram. input is very deaf what can be done to strengthen it. thanks for the circuit

shajeeb

2 years ago

Thanks Sedor for answering the question. Yes , you can insert a simple amplifier board between music player and the spectrum analyzer to adjust the audio input signal strength. This amplifier is not a must hence avoided in the diagram to avoid complexity for the beginners.

Anonymous user

2 years ago

I am using a small amplifier to strenghten the input signal... in my case it helped.

Anonymous user

2 years ago

First I want to thank you for sharing such amazing project. Secondly should this code run on the original Arduino UNO as well? The sampling gives back only 63.00 values in vReal regardless what the Analog 0 pin may have. I'm wondering if UNO needs different setting of ADCSRA and/or ADMUX registers?

shajeeb

2 years ago

Stability of the voltage fed into AREF pin is very important to get accurate reading. In addition, increased reference voltage (5v instead 3.3v) will make ADC step response to be low for small changes in input signal. In that case you have to make sure input signal is strong enough. Please read some online document to get more details on how ATmega328P ADC behaves with external reference voltage.

shajeeb

2 years ago

Yes, I had tested it with UNO & Nano with out any change in code.

shajeeb

2 years ago

Good to know that you could fix wiring error. Ideally none of the LEDs should glow when input is disconnected. Are you seeing static with input connected or disconnected ? Hope you are powering unit from a quality 5v source.

shajeeb

2 years ago

1) This circuit works on 5v which you normally feed from USB port or a 5v charger . 2) 3.3v regulated supply is generated by UNO/Nano board , you don't have to feed it. 3) Make sure ground wire of audio cable is connected to the ground of this system. 4) Try to feed audio input from another source and compare.

Anonymous user

2 years ago

@2 Yes Pro Nano have both 5V and 3.3V but Pro Micro does not. Can I use the 5V instead 3.3V? Will it negatively affect the function? Thanks for helping!

Anonymous user

2 years ago

Disconnected inputs are almost clean. There seem to be many other frequencies and noise when I fed single frequency from a generator app on my iPhone. It may get better when I move this from breadboard to PCB. But I have yet another question about the 3.3V. It seems as Pro Micros do not have 3.3V. Does this circuit need to supply 3.3V for correct operation or I could go away with 5V only? Thank you!

Anonymous user

2 years ago

Problem solved, I used wrong pin for AREF. Now it is working but I'm having quite a lot static comparing to your clean frequency test pictures. Besides grounded shield, can I help the circuitry to do better job with less static? Is there something I can make it better? Thank you in advance for any suggestions :)

Anonymous user

2 years ago

Hi.Before at all,my congrats for the project. I've followed the schematics and build it. Now my problems/questions: _I pick the signal from a standard 3,5mm jack to rca cable.And before filtering with 100uf capacitors, i've split to a female 3,5 jack.So i can see and listen music.The problem are these: --when insert 2nd cable for hear it,the display's spectrum go lower --i ve try to put the earphone to another connector available from pc,reproducing the same stream,but nothing change. Remain half. My question is; There's a way to adjust the sensibility? _There is always a noise,very annoying,and that noise it's show in the spectrum. --There's a solution? Patterns: int MY_MODE_1[]={0, 128, 192, 224, 240, 248, 252, 254, 255}; // standard pattern I can't understand what that numbers indicate for the pattern. I've try the first 2 set to 128,and i've a static line on the base (and it's what i wanna! Lucky!!!) But others?Can i have a reference sheet? At first try i've blow my nano,because for the button,i've shortcut 5v and gnd,and from the schematics seems like that!

Anonymous user

2 years ago

It's more obvious if you express it in binary, ie (0b00000000, 0b10000000, 0b1100000, 0b11100000, 0b11110000, etc...). Those values are fed into mx.setColumn() to indicate which LEDs are supposed to light up in each row.

Anonymous user

2 years ago

Hi, I like this project a lot. I was wondering how would you make this project in a smaller scale. Such as a 3x4 LED matrix.

shajeeb

2 years ago

3x4 display is too small for audio spectrum display. Probably what you need is a VU meter to show overall amplitude of the input signal.

Anonymous user

2 years ago

Is there any place with step by step instructions on this?

shajeeb

2 years ago

Sorry, I don't have any other document than what is given here.

Anonymous user

2 years ago

I'm trying to send the values through the serial port to processing to visualize the values on screen. The problem I'm having is that the output is really laggy and doesn't respond well to the music. Could this problem be caused because I'm sending it through serial instead of using the display? I'm not sure how the display works and if it is faster than serial. Thanks in advance :)

shajeeb

2 years ago

You can try with maximum serial speed. Still sending data via serial port makes the entire system to work slow as it blocks entire code till internal buffers get freed up for accepting new data pushed.

Anonymous user

2 years ago

Hi Shajeeb! Your project looks really good! I'm in the process of making an EQ for my apprenticeship test. I think I can use this spectrum analyzer as an extra accessory. My EQ is 10 bands (32, 64, 125, 250, 500, 1K, 2K, 4K, 8K, 16K) per channel and each channel must be able to be displayed separately. - Do you know how it can be made? Another thing: I use led bar arrays instead of DOT display. I have ordered MAX7219CWG circuits home. Is it possible to turn it into a 10x10 or 10x16 display with led bar arrays? - How is this made easiest? My last question: Is there a built-in form of AGC regulation that you can regulate in your project or is it something you can build on? I hope you can help me - thanks. Sorry for the English

Anonymous user

2 years ago

Great idea, works like a charm! Used it at a vintage computer for visualizing it's sound-output. I am not a programmer, so please allow me this question: is it possible to show a (pre defined) text when nothing happens? (if not, maybe at least a text when the system ist switched on?)

shajeeb

2 years ago

Yes doable, you have to make necessary changes in the code to achieve that. For example to show a text message while powering ON you can add the required code inside setup() function followed by small delay [eg delay(2000) ] .

chrissurya

2 years ago

I am building a project based on this one, with small modification on how the LED display the result... Kindly take a view, here is my page... https://create.arduino.cc/projecthub/chrissurya/32-linier-11-pseudo-log-band-audio-spectrum-analyzer-8e8c7b

Anonymous user

2 years ago

Please tell me How to instal code on android phone as it is showed compilation error when trying

ThomAce

2 years ago

Dear Friend, Your project is very good! I just used your code and built a similar stuff but with a two lines of LCD display. I have some doubts about the accuracy and representation of the frequencies, but your code is far better than the others I tried.

shajeeb

2 years ago

Thanks for your interest in my project. I just went through your modified stereo LCD version. You can check frequency response by feeding known frequency input signals (use signal generators or online tone generator) . Another point is that stereo processing causes additional latency hence you might see slow response from the system and higher frequencies are ignored.

Anonymous user

2 years ago

Hello everyone,I've made a board for this project With Frizting. You can use the frizting file and PCB file , using the link below: http://www.mediafire.com/file/7mnq7dspoogdna2/AudioSpectrum_With_Arduino.zip/file

shajeeb

2 years ago

Thanx.

Anonymous user

2 years ago

Not sure what the point of "set ADC to free running mode" comment is in 'setup'. You are not using free running mode anyway. In your code you are using ADC in a single measurement mode. "ArduinoFFT library can do FFT of samples between 16 to 128...". Um... ArduinoFFT library has no limit on the number of samples it can process. Also, it is worth noting that you are using the ArduinoFFT library through a deprecated interface. Also, an absolutely critical detail in your code is how it chooses the ADC sampling frequency to make sure that the post-FFT data properly references the actual absolute frequencies. For some reason this detail is not even mentioned in the description.

Anonymous user

2 years ago

For such a small capacitance as 100nf one'd typically use a non-polarized capacitor.

Anonymous user

2 years ago

True, but UNO, Mini and Mega do not have a capacitor on AREF. AFAIK, only Pro Mini has it. And adding a filtering cap on AREF does significantly reduce noise.

Anonymous user

2 years ago

Precisely. And, again, in your code you are piling up multiple unrelated and completely unnecessary ADC modes on top of each other. It "works", but it is incorrect (as in "nonsensically excessive"). You are not using Free Running ADC mode in your code at all. So, there's no need to set it up. The comment about this mode that you wrote in your code will only confuse people, since they will think that this somehow matters. Also, your schematic is missing another ultra-important component prescribed by ATmega datasheet - a filtering capacitor at the AREF pin. If you are using external voltage reference through AREF, this capacitor is needed. This will significantly drop the noise floor at lower frequenices range. Just try it.

Anonymous user

2 years ago

As I stated above, the capacitor should be connected between AREF pin of the Arduino and ground. The value is not exact science: 100nf is usually considered a "standard" value.

shajeeb

2 years ago

ATmega needs few external components like crystal , resistors and capacitors for its operation. All these are part of the standard Arduino board. Please refer to the board circuit diagram and suggest. But if some one wants to experiment it should be OK to do.

shajeeb

2 years ago

Thanks for your interest in this project and comments. Some AVR documentation might provide more details on ADC. Sample one is at http://www.avrbeginners.net.

Anonymous user

2 years ago

Dude, can you please tell me where put the filtering cap and relative value? Thanks

Anonymous user

2 years ago

Thank you. I'll try with a cap. Polarized or not?

Anonymous user

2 years ago

BTW, I tried implementing the same thing, but using 128x64 OLED display (through SPI) to output the histogram. It works quite adequately, but it is noticeable that FFT, as a blocking operation, consumes a lot of processing cycles, which is visible as low refresh rate of the display and missed beats in the input signal. But once I switched from `arduinoFFT` library used here to OpenMusicLabs implementation (I tried both their FFT and FHT), it just skyrocketed on me! It is faster than `arduinoFFT` by an order of magnitude (if not two). OpenMusicLabs implementation is a bit crude and hackish (interface-wise), but it is incredibly faster. If you just want to play with this a little bit, `arduinoFFT` used here will do the job. But if you want to see a properly operating spectrum analyzer, then it is just doesn't cut it. There are probably other well-optimized FFT/FHT implementations out there, but OpenMusicLabs's one is very very good.

shajeeb

2 years ago

Please publish your result which will be useful for some enthusiasts . (Btw, I stopped experimenting on this project a while back )

Anonymous user

2 years ago

Your project looks very interesting. Is it possible to extend it to 2x 32x8 DOT matrix displays with 1x Arduino Nano and 1x button to display right and left stereo channel separated?

shajeeb

2 years ago

It is doable, but arduinoFFT library will be slow for computing FFT of 2 x 64 samples. One option could be to make 2 x 32 samples with caviet of less response on lower frequency band. Arduino Nano is cheaper than Dot Matrix LED display . Hence I would suggest to use 2 x Arduino Nano + 2 Displays + 1 button switch. If you power both system from same power supply you can use single switch to D5 pin of both Arduinos via 10k resistors.

Anonymous user

2 years ago

would it be complicated to change the display code of 16 x 32?

Anonymous user

2 years ago

I would like to use 2 modules of this increasing the lines leaving the analyzer with a matrix of 32x16 I think it would look really cool

Anonymous user

2 years ago

yes I made the following changes I left the "#define MAX DEVICES 8" but when I change the "#define yres 16" ai the display is already confused and I do not know how to modify the "MY_MODE_x" I am from Brazil thank you very much for your attention sorry for my English bad

shajeeb

2 years ago

It depends on the type of change you are interested in .

shajeeb

2 years ago

Ok, your plan is to use 2 modules to form 32x16 display. A 32x8 display is formed by cascading four 8x8 displays. So you need to first get eight of 8x8 displays connected to form one 32x16 display . Once you get that working then you need to make some changes in the code like "#define yres" and "MY_MODE_x" values.

Anonymous user

2 years ago

Hi Shajeeb, thanks a lot for this amazing project! I love this solution very much, because it utilizes only the Arduino Nano and the LED DOT Matrix Display, i.e. no extra hardware is needed. I assembled it as per your instructions, and it works! I also tested it by a SINE signal generator (0,2V peak-peak) have noticed, that the frequencies from 20Hz till 900Hz are indicated only in the first Column. Here is the link to the video file: http://youtu.be/hQKLOAs5_ug Is there any chance to “stretch” these frequencies either in the FFT or in the script?

Anonymous user

2 years ago

Thanks a lot. Yes, this is exactly what I am looking for. I will check his modifications. I have 2 more questions: 1. The code aubtracts the "ZERO" \\value from the digitized signal in this line: int value = ADC - 512. This way some of the values result in negative numbers. Is this OK? I was thyinking of a software "rectifier", like: if (value<0) value = -value 2. Now the code utilizes FFT library. I heard that the FHT is faster and more effetive. Is this true and applicable in this solution? Thanks for your advises.

Anonymous user

2 years ago

Thanks Shajeeb. I am not good enough with coding, so I am not capable to test the FHT. However, I love this project so much, that I can publish it in the national Practical Electronics Magazine to get more popularity - if you agree, please let me know.

Anonymous user

2 years ago

In order to better resolve lower frequencies you'd need more samples. Say, 128 instead of 64. However, If lower frequencies is all you care about, you can actually _decrease_ _the_ _sampling_ _frequency_ and keep the number of samples unchanged. That will give you greater resolution in the lower part of the spectrum at the expense of lower resolution in upper part of the spectrum. But if you need the full range, then more samples is the only way to go.

shajeeb

2 years ago

1. It is fine , please try and see if it makes any difference. 2. May be true, please experiment and share result here.

shajeeb

2 years ago

Thanks. What I have done is linear division of entire audio spectrum into 32 slots . Hence each column represents ~600 Hz range. Looks like what you are looking for is more expansion on the lower frequencies. Some one had commented here with "log scale" splitting of audio range, please take a look at that.

Anonymous user

2 years ago

Hello, thanks for this project and I was searching it. How to build this using WS2811 LEDs ? Can you please give me some idea to how to change the code according to it? Thanks,

shajeeb

2 years ago

Thanks. Some one recently has posted a modified version of this project with WS2812 , please take a look at that.

Anonymous user

2 years ago

Hi, very cool project! I am trying to replicate this, but with a WS2812b LED-strip instead of the dot matrix display, and map the amplitudes to the brightness of the LEDs. However I am running into some issues with setting the brightness of each LED. If I'm not mistaken, in your code you use the array data_avgs[xres] to store the amplitudes of the frequencies in each band. Then why is this a character array?

shajeeb

2 years ago

Char consumes only 8 bits compared to 16 bits by int . Here we don't need large numbers hence char is good enough which saves memory.

Anonymous user

2 years ago

Sir Our project is not working what must be the fault . We did the exact connection as per the circuit diagram given above also we compiled the code properly and uploaded it in to nanoR3 board . The output is not coming on to the display screen when Audio is connected please help us with the needfull...THANK YOU

Anonymous user

2 years ago

Hello Friend! First of all I want to thank you for your project, it’s very awsome! Is it possible to combine two led matrix max7219 to make an 8x64 spectrum analyzer? What needs to be fixed in the firmware? If you can describe in more detail, i am new in arduino(...

shajeeb

2 years ago

It is possible to use any type of display in place of dot matrix display. With reference to the flowchart given above , you will have to change everything below 'compute FFT' block to make it working with other type off displays.

Anonymous user

2 years ago

How did you input audio? Just a splitter cable?

shajeeb

2 years ago

I do have one stereo 3.5mm female socket connected to the audio input wires of Spectrum analyzer. Then use a stereo 3.5mm splitter cable to connect headphone out of mobile phone to the Spectrum analyzer and to the amplifier. If you are taking audio output from line-out of the music system then you may not need splitter cable. I may try to make a diagram with Fritzing which I am not familiar with.

ronald12314

2 years ago

CAN I REPLACE 5K WITH 4.7K OR IS IT BETTER WITH 5.6K ? TY FOR RESPONSE

Anonymous user

2 years ago

ADMUX = 0b00000000; // use pin A0 and external voltage reference Is is possible to use pin A1 instead fo A0 for ADMUX on an Arduino NANO? I'm already using the pin A0 for a different input. What would the hex notation look like if I can use A1? I think i figured it out. The new ADMUX address for A1 would be: 0b00000001. I had another question. If I were using a display with 40 columns and 11 rows, what changes would be required? I tried changing these variable but the sketch wouldn't progress past FFT computation: //#define SAMPLES 80 //Must be a power of 2 //#define xres 40 // Total number of columns in the display, must be <= SAMPLES/2 //#define yres 11 // Total number of rows in the display

Anonymous user

2 years ago

I am by no means an expert, but I think the reason your sketch stops during the FFT might be because you set the number of samples to be 80, which is not a power of 2. I think the reason is that most implementations of the FFT algorithm, and probably including the one used here, requires the sample size to be a power of 2.

shajeeb

2 years ago

1. 0b00000001 is correct 2. Next SAMPLES size you can use after 64 is 128 which consumes lots of memory and Arduino-FFT becomes really slow with that number.

Anonymous user

2 years ago

Thanks for the inspiration shajeeb. I made some changes implementing my own version of a 32 band music visualizer. You find the complete source code at my blog: https://emumannen.blogspot.com/2021/09/arduino-goes-to-town-part-5.html

Anonymous user

2 years ago

Hi, I want to change the frequency spectrum on my display. For example, 280 Hz to 14k Hz. Want part of the code I need to change to achieve my goal?

Anonymous user

2 years ago

I've not been able to find the MAX7219 LED display. Are you using a PCB to attach your lights or is the PCB part of the display?

Anonymous user

2 years ago

Thank you very much!

Anonymous user

2 years ago

https://www.amazon.com/Wangdd22-MAX7219-Arduino-Microcontroller-Display/dp/B01EJ1AFW8

Anonymous user

2 years ago

such a good project, I will do this project using stm32f407 and a microphone and map it into RGB ws2812b dot matrix

shajeeb

2 years ago

Thanks . Glad to know that you have a plan to try out with different hardware.

Anonymous user

2 years ago

Would this female jack work in this project? Link:https://www.electronicscomp.com/mx-3.5mm-stereo-female-socket-connector-pcb-mounting-3-pin-mx-2267

Anonymous user

2 years ago

Good job ! So I want to make a display with 64 x 8 resolution, but I don't know how to change the code has columns and rows I changed the columns from 32 to 64 and then I went to that part of the code and change 31 to 63 displaycolumn=31-i; Believing it would be possible, but it didn't work out.

chrissurya

3 years ago

I am building a project based on this one, with small modification on how the LED display the result... Kindly take a view, here is my page... https://create.arduino.cc/projecthub/chrissurya/32-linier-11-pseudo-log-band-audio-spectrum-analyzer-8e8c7b

Anonymous user

3 years ago

Hi, i'm not found this project library file. Please give this library file link.

Anonymous user

3 years ago

I built this, with only 8 bands, and an electret microphone with an OpAmp based amplifier. And learnt something useful :-) Observing that the lights were blinking prettily, but seemingly without connection to the music, I attached the oscilloscope to the amplified microphone signal (I’d done that before, and it looked fine, but just in case). What I saw was a 740Hz or so pulse signal completely drowning the microphone signal. The interference goes away when I detach the LED matrix. Vcc looked fine, so I assume the interference went over the air from the display to the jumper wires connecting my mic to the preamplifier. Lesson learnt: when using microphones near devices that can produce interference, you need better shielding than a breadboard and some jumper wires 👍

Anonymous user

3 years ago

Hello! I am working on this project and was wondering what steps you can take to reduce noise? placing a 100nf cap between Aref and ground seemed to help with higher frequency noise (1k-15k) however I still see lots of feedback in the low frequency range (20-500 Hz). Will adding series capacitance on my L and R audio inputs help this? I currently have 220 nF across, and 100nF was still very noisy on the audio input. Also has anyone successfully implemented a log scale? My setup momentarily worked with no noise or flickering, but still looking at a log scale to shift some of the LED activity to the right of the display matrix...

Anonymous user

2 years ago

Yes I implemented a log scale sort of but I used linear FHT output and 5 dB/octave gain to logify the response since it made sense visualizing music. All about it on my blog: https://emumannen.blogspot.com/2021/09/arduino-goes-to-town-part-4.html

Anonymous user

3 years ago

Definitely a very interesting project! It would be even nicer if it was used Bicolor or Tricolor Led Matrix! Has anyone done?

Anonymous user

2 years ago

I used a DIY 32x8 RGB LED matrix. All about it on my blog: https://emumannen.blogspot.com/search/label/Arduino

gautam_bhosle

4 years ago

Sir Our project is not working what must be the fault . We did the exact connection as per the circuit diagram given above also we compiled the code properly and uploaded it in to nanoR3 board . The output is not coming on to the display screen when Audio is connected please help us with the needfull...THANK YOU

Anonymous user

4 years ago

Hello Shajeeb, I have assembled this audio visualizer of yours and I'm wondering if I can get the visualizer to work at volume 40-50 as effectively as it does at 100? (I have this hooked up to my pc) Thanks!

Anonymous user

2 years ago

You might choose the way i've written above as an answer the the divider question. Never tried, but it should scale your audio volume input up or down when you change it. (You may observe a short delay)

Anonymous user

4 years ago

Hi Shajeeb, Thank you for this code. I think there is a bug in your averaging loop where you don't traverse the entire vReal array. Since step evaluates to 1, you only traverse half of vReal and only have one sample in each average. int step = (SAMPLES/2)/xres; //- EVALUATES TO 1! for(int i=0; i<(SAMPLES/2); i+=step) //- CORRECT { data_avgs[c] = 0; for (int k=0 ; k< step ; k++) { //- ONLY EXECUTES ONCE data_avgs[c] = data_avgs[c] + vReal[i+k]; //- k IS ALWAYS 0 BECAUSE STEP IS 1 } data_avgs[c] = data_avgs[c]/step; //- ONLY AVERAGES THE VALUE IN i c++; } Is this correct? I've done it the following way: #define SAMPLES (64) #define OUTPUT_N (SAMPLES / 2) int samples_per_average = SAMPLES / OUTPUT_N; //- EVALUATES TO 2 for (int i = 0; i < OUTPUT_N; i++) //- LOOPS 32 TIMES, LIKE YOURS { averages[i] = 0; for (int j = 0; j < samples_per_average; j++) //- LOOPS TWICE { int idx = (i * samples_per_average) + j; //- TAKES i AND j INTO ACCOUNT averages[i] += vReal[idx]; } averages[i] /= samples_per_average; //- AVERAGES 2 VALUES }

zonalimitatore

2 years ago

Dude.Thanks for your post. Have you try your code? It's working or have some problem?

kumazu

4 years ago

Hello, First of all very nice Project. Now my Problem is even when not active some pixels are illuminated on the Matrix Display and i don't know why. I've uploaded a short Video to Youtube to better show my problem. Would really appreciate some help because i've rebuild this to use it in School Link : https://www.youtube.com/watch?v=UO_fKas3Lq4

zonalimitatore

2 years ago

Like my problem in the last comment...i've solved it by edit adc value (try with -256)

ronald12314

4 years ago

CAN I REPLACE 5K WITH 4.7K OR IS IT BETTER WITH 5.6K ? TY FOR RESPONSE

zonalimitatore

4 years ago

Hi.Before at all,my congrats for the project. I've followed the schematics and build it. Now my problems/questions: _I pick the signal from a standard 3,5mm jack to rca cable.And before filtering with 100uf capacitors, i've split to a female 3,5 jack.So i can see and listen music.The problem are these: --when insert 2nd cable for hear it,the display's spectrum go lower --i ve try to put the earphone to another connector available from pc,reproducing the same stream,but nothing change. Remain half. My question is; There's a way to adjust the sensibility? _There is always a noise,very annoying,and that noise it's show in the spectrum. --There's a solution? Patterns: int MY_MODE_1[]={0, 128, 192, 224, 240, 248, 252, 254, 255}; // standard pattern I can't understand what that numbers indicate for the pattern. I've try the first 2 set to 128,and i've a static line on the base (and it's what i wanna! Lucky!!!) But others?Can i have a reference sheet? At first try i've blow my nano,because for the button,i've shortcut 5v and gnd,and from the schematics seems like that!

Anonymous user

2 years ago

It's more obvious if you express it in binary, ie (0b00000000, 0b10000000, 0b1100000, 0b11100000, 0b11110000, etc...). Those values are fed into mx.setColumn() to indicate which LEDs are supposed to light up in each row.

Anonymous user

4 years ago

Hello, for the audio input, can I simply use a TRRS 3.5mm breakout board https://www.makerlab-electronics.com/product/trrs-3-5mm-jack-breakout/ and a male-to-male 3.5mm jack? I intend to connect my phone or computer on the other end of the male-to-male jack and the other end to the TRRS 3.5mm breakout board which connects to the spectrum analyzer arduino. Will it be possible or safe?

Anonymous user

4 years ago

Great project was fun to make, my only issue is that I am getting a high pitched tone in my headphones with each illumination of an LED. I am using a two way splitter, one goes to my headphones and the other to the audio input of the project. If I use enough volume it will cause a cascading loop on the max7219. Any suggestions? Everything else works great though.

shajeeb

2 years ago

I don't suggest to use headphone and analyzer in parallel for various reasons. You will have to keep at high volume for getting full display (vertical) on the analyzer. Impedance mismatch of the headphone and the analyzer may cause the problems you explained. Some music player's output may be coming out of bridged amplifier where grounding one line can cause problem. Thats said, you can experiment and make It working. And make sure grounding is perfect.

Anonymous user

4 years ago

ADMUX = 0b00000000; // use pin A0 and external voltage reference Is is possible to use pin A1 instead fo A0 for ADMUX on an Arduino NANO? I'm already using the pin A0 for a different input. What would the hex notation look like if I can use A1? I think i figured it out. The new ADMUX address for A1 would be: 0b00000001. I had another question. If I were using a display with 40 columns and 11 rows, what changes would be required? I tried changing these variable but the sketch wouldn't progress past FFT computation: //#define SAMPLES 80 //Must be a power of 2 //#define xres 40 // Total number of columns in the display, must be <= SAMPLES/2 //#define yres 11 // Total number of rows in the display

shajeeb

2 years ago

1. 0b00000001 is correct 2. Next SAMPLES size you can use after 64 is 128 which consumes lots of memory and Arduino-FFT becomes really slow with that number.

Anonymous user

2 years ago

I am by no means an expert, but I think the reason your sketch stops during the FFT might be because you set the number of samples to be 80, which is not a power of 2. I think the reason is that most implementations of the FFT algorithm, and probably including the one used here, requires the sample size to be a power of 2.

Anonymous user

4 years ago

Hi, very cool project! I am trying to replicate this, but with a WS2812b LED-strip instead of the dot matrix display, and map the amplitudes to the brightness of the LEDs. However I am running into some issues with setting the brightness of each LED. If I'm not mistaken, in your code you use the array data_avgs[xres] to store the amplitudes of the frequencies in each band. Then why is this a character array?

shajeeb

2 years ago

Char consumes only 8 bits compared to 16 bits by int . Here we don't need large numbers hence char is good enough which saves memory.

Anonymous user

4 years ago

This looks very nice. Would it work with an ESP8266?

shajeeb

2 years ago

All the libraries used are very generic (not hardware specific) hence I don't see any reason for it to not work on ESP8266.

Anonymous user

4 years ago

Fantastic project, Making this as a Christmas present for my dad who's an audiophile. One modification question. I connected the 2nd 8x32 display after the first one which makes the same image appear on the 2nd display, which is fine. However I wanted to flip the image on the second display so that that the 2nd display is like a mirror reflection of the first one. Like if you lay one 8x32 on top of a mirror sort of thing only in a different color. I tried doing a flip flop by overwriting the contets of your button check function with int flip = false; void displayModeChange() { if (flip) { for (int i = 0 ; i <= 8 ; i++ ) { MY_ARRAY[i] = MY_MODE_1[i]; } } else { for (int i = 0 ; i <= 8 ; i++ ) { MY_ARRAY[i] = MY_MODE_5[i]; } } } I figured that right after you write mx.setColumn(displaycolumn, displayvalue); I can swap out the array MODE_1 for array MODE_5 and the next cycle it would just use that but it seems to just write the data to both display. I feel like it's a syncronous.

shajeeb

2 years ago

You are trying to independently control both displays. For that you need to create another display object (by copying line 61 of the original code) and feed data into that object separately.

Anonymous user

4 years ago

Would it be possible to do this with an adafruit 32x32 RGB led matrix? I'm not quite sure how to implement the drawing of the signals to the matrix (it uses functions such as drawline). Any help would be much appreciated, thanks

shajeeb

2 years ago

Yes, it will work the required code change. You can use libraries like <FastLED.h> & <LEDMatrix.h>

Anonymous user

4 years ago

Hola gracias por el aporte , mi consulta es saber si se puede utilizar tira led teniendo en cuenta que son RGB ) multicolores, como se nombraría los led de una barra (tira de led ) estaré atento en servaver@hpotmail.com

Anonymous user

4 years ago

Hey!. I'm having a problem where after the code is uploaded the LED is continuous lit up and I'm not able to to test it with Sine wave. Also, I fed audio through my phone but I see the LED is still continuous lit up. What should I do? I'm pretty sure my connections are correct.

shajeeb

2 years ago

Disconnect the audio input part and see what happens. If the writing is correct & code is loaded properly then there should be nothing on the display now.

Anonymous user

4 years ago

Very cool project! I am trying to replicate this project but with a P10 DMD module. What changes will have to be made to make this code compatible with these displays?

Anonymous user

4 years ago

Dear shajeeb, Why do you use 2 100 nF capacitors on your audio input? And what do you use the resisitors for on the audio input ? I am just learning how to connect an audio input to the arduino and find this really difficult.

shajeeb

2 years ago

Those Capacitor + Resistor pairs are for mixing both cleft & right audio channels.

Anonymous user

4 years ago

Hi Shajeeb! Your project looks really good! I'm in the process of making an EQ for my apprenticeship test. I think I can use this spectrum analyzer as an extra accessory. My EQ is 10 bands (32, 64, 125, 250, 500, 1K, 2K, 4K, 8K, 16K) per channel and each channel must be able to be displayed separately. - Do you know how it can be made? Another thing: I use led bar arrays instead of DOT display. I have ordered MAX7219CWG circuits home. Is it possible to turn it into a 10x10 or 10x16 display with led bar arrays? - How is this made easiest? My last question: Is there a built-in form of AGC regulation that you can regulate in your project or is it something you can build on? I hope you can help me - thanks. Sorry for the English

Anonymous user

4 years ago

Hi, I have connected up the parts as shown in the schematic diagram and used the Arduino code above but the dot matrix units just light up random LEDs. What could cause this?

Anonymous user

4 years ago

Please tell me How to instal code on android phone as it is showed compilation error when trying

Anonymous user

4 years ago

Great idea, works like a charm! Used it at a vintage computer for visualizing it's sound-output. I am not a programmer, so please allow me this question: is it possible to show a (pre defined) text when nothing happens? (if not, maybe at least a text when the system ist switched on?)

shajeeb

2 years ago

Yes doable, you have to make necessary changes in the code to achieve that. For example to show a text message while powering ON you can add the required code inside setup() function followed by small delay [eg delay(2000) ] .

w3223w

4 years ago

An integrated and potentiometer is used in the circuit in the video, but they are absent in the diagram. input is very deaf what can be done to strengthen it. thanks for the circuit

Anonymous user

2 years ago

I am using a small amplifier to strenghten the input signal... in my case it helped.

shajeeb

2 years ago

Thanks Sedor for answering the question. Yes , you can insert a simple amplifier board between music player and the spectrum analyzer to adjust the audio input signal strength. This amplifier is not a must hence avoided in the diagram to avoid complexity for the beginners.

Anonymous user

4 years ago

Awesome project! thanks for sharing. Before I stumbled on your post, I was looking into utilizing MSGEQ7 chip for the signal analysis. I even ordered a few of them :) If you don't mind, I have a couple of questions . 1. the 2.75v mentioned in the diagram, is that due to the 32Kohm AREF internal resistance? 2. In your post-processing, you added "constrain(data_avgs[i],0,80)". doesn't this clip your output? can't the the map function alone do the trick? Cheers,

shajeeb

2 years ago

Thanks 1. Yes 2. constrain is for limiting the upper side (clip) Please experiment with various combinations to get different outcome.

Anonymous user

4 years ago

Cool project. Would love to pick your brain for a project of mine.

Anonymous user

4 years ago

Hey, it's a cool project but I have a question: would it be possible to use RGB LED strips instead of the LED matrix?

Anonymous user

2 years ago

Hi, thanks.   Probably yes, but it needs a different library a change in code. ______________________________________________________________

Anonymous user

4 years ago

HI, thank you for such great project! I have already done it and I even made housing for it using 3D printer. Anyway, I have a question. When i connect Arduino to some kind of source (for example laptop) but audio input connect to different source (for example mobile phone), the analyzer is not working. I have connect Arduino and audio input into the same device. What is the reason? i have been thinking about it but still can't find the reason. Thank you!

Anonymous user

2 years ago

Hi, well done with the housing. Would you please share it with us? Where can we find the .stl files?

shajeeb

2 years ago

Thanks, It is not clear the problem you are trying to explain. Are you trying to say it works with laptop audio output but not with mobile output ?

venuscreats

4 years ago

Hello, thanks for this project and I was searching it. How to build this using WS2811 LEDs ? Can you please give me some idea to how to change the code according to it? Thanks,

shajeeb

2 years ago

Thanks. Some one recently has posted a modified version of this project with WS2812 , please take a look at that.

Anonymous user

5 years ago

BTW, I tried implementing the same thing, but using 128x64 OLED display (through SPI) to output the histogram. It works quite adequately, but it is noticeable that FFT, as a blocking operation, consumes a lot of processing cycles, which is visible as low refresh rate of the display and missed beats in the input signal. But once I switched from `arduinoFFT` library used here to OpenMusicLabs implementation (I tried both their FFT and FHT), it just skyrocketed on me! It is faster than `arduinoFFT` by an order of magnitude (if not two). OpenMusicLabs implementation is a bit crude and hackish (interface-wise), but it is incredibly faster. If you just want to play with this a little bit, `arduinoFFT` used here will do the job. But if you want to see a properly operating spectrum analyzer, then it is just doesn't cut it. There are probably other well-optimized FFT/FHT implementations out there, but OpenMusicLabs's one is very very good.

shajeeb

2 years ago

Please publish your result which will be useful for some enthusiasts . (Btw, I stopped experimenting on this project a while back )

Anonymous user

5 years ago

Not sure what the point of "set ADC to free running mode" comment is in 'setup'. You are not using free running mode anyway. In your code you are using ADC in a single measurement mode. "ArduinoFFT library can do FFT of samples between 16 to 128...". Um... ArduinoFFT library has no limit on the number of samples it can process. Also, it is worth noting that you are using the ArduinoFFT library through a deprecated interface. Also, an absolutely critical detail in your code is how it chooses the ADC sampling frequency to make sure that the post-FFT data properly references the actual absolute frequencies. For some reason this detail is not even mentioned in the description.

shajeeb

2 years ago

Thanks for your interest in this project and comments. Some AVR documentation might provide more details on ADC. Sample one is at http://www.avrbeginners.net.

shajeeb

2 years ago

ATmega needs few external components like crystal , resistors and capacitors for its operation. All these are part of the standard Arduino board. Please refer to the board circuit diagram and suggest. But if some one wants to experiment it should be OK to do.

zonalimitatore

2 years ago

Dude, can you please tell me where put the filtering cap and relative value? Thanks

zonalimitatore

2 years ago

Thank you. I'll try with a cap. Polarized or not?

Anonymous user

2 years ago

For such a small capacitance as 100nf one'd typically use a non-polarized capacitor.

Anonymous user

2 years ago

True, but UNO, Mini and Mega do not have a capacitor on AREF. AFAIK, only Pro Mini has it. And adding a filtering cap on AREF does significantly reduce noise.

Anonymous user

2 years ago

Precisely. And, again, in your code you are piling up multiple unrelated and completely unnecessary ADC modes on top of each other. It "works", but it is incorrect (as in "nonsensically excessive"). You are not using Free Running ADC mode in your code at all. So, there's no need to set it up. The comment about this mode that you wrote in your code will only confuse people, since they will think that this somehow matters. Also, your schematic is missing another ultra-important component prescribed by ATmega datasheet - a filtering capacitor at the AREF pin. If you are using external voltage reference through AREF, this capacitor is needed. This will significantly drop the noise floor at lower frequenices range. Just try it.

Anonymous user

2 years ago

As I stated above, the capacitor should be connected between AREF pin of the Arduino and ground. The value is not exact science: 100nf is usually considered a "standard" value.

jackespare

5 years ago

Hello, Friend! I want to ask about your conections. You say that with R1 & R2 we divide 3.3v for our AREF pin. What is the purpose of conecting signal between R1 and R2? Does this mean that we divide our signal also?

shajeeb

2 years ago

R1,R2 voltage divider is for providing a DC bias to audio input. This makes audio to fluctuate above a fixed DC voltage instead of zero voltage. With this ADC can sense both positive and negative cycles of the input audio.

Anonymous user

5 years ago

can someone help me with construction of this project?

Anonymous user

5 years ago

Hello, I wanted to ask if I can also use RGB's in the dimensions 14x20 instead of the LED matrix display?

shajeeb

2 years ago

It is possible to use any type of led/display in place of dot matrix display. With reference to the flowchart given above , you will have to change everything below 'compute FFT' block to make it working with other type of displays.

Anonymous user

5 years ago

I am new to Arduino and coding but i have a question. If I will be using led strips to make this. Will i have to change the code at all in order to use led strips. I plan on making it 32 band like you did so 32 leds across but will i have to change anything if i decide to make it more than 8 less vertically. Maybe like 20 or so. Thanks for any advice!

Anonymous user

2 years ago

Hi, yes you will need to change the code. If you are new to Arduino and coding then I would start off by parking this sketch and just working on reading audio from an input so you can then view it using the basic example ReadAnalogSerial script. You will need to build a Passive RC HPF filter and bias the input so it reads at 512 on the Analog pin. If this means nothing to you like it meant nothing to me a week ago, then start off with baby steps! It will mean more to you at the end and have you grinning when you get it working and also understand it. Then once you can read the analog pin and see test frequencies in the Serial plotter it is time to move on to learning FFT and then add on the lights as an output. Otherwise this script will mean nothing to you and you won't learn anything or be able to fix/tweak it.

Itsmemp

5 years ago

Hallo sir.. Can I use led instead of dot display. For that which changes I need to make in this project? Thank u

shajeeb

2 years ago

It is possible to use any type of led/display in place of dot matrix display. With reference to the flowchart given above , you will have to change everything below 'compute FFT' block to make it working with other type of displays.

alien666dj

5 years ago

Hello Friend! First of all I want to thank you for your project, it’s very awsome! Is it possible to combine two led matrix max7219 to make an 8x64 spectrum analyzer? What needs to be fixed in the firmware? If you can describe in more detail, i am new in arduino(...

shajeeb

2 years ago

It is possible to use any type of display in place of dot matrix display. With reference to the flowchart given above , you will have to change everything below 'compute FFT' block to make it working with other type off displays.

Anonymous user

5 years ago

Hi. Great job on the coding! I am making my own matrix with a pcb kit. It is pre programmed and has CS CLK Data In/Out 5v and GND on each of 4 pcbs to create an 8x32 display. Can I use this code as is, or do I have to modify it? Also, can I just hook up data out from it’s control board, and data out from an Arduino to a switch to select which code I want to use, or do I have to hook up CS and CLK from the Arduino too? I know I have a lot of questions, but I’m almost done. Could I use a microphone and still get these results? Lastly, how could I make this with rgb color values for each of the 8 leds in the 32 sections? Sorry for all the questions, but I’m a big newb. Thanks!

novax1

5 years ago

Hi There is way to lower the brightness of max7219. thanks

shajeeb

2 years ago

You can use mx.control(MD_MAX72XX::INTENSITY, 8) to change the brightness. You can find more details inside the example "MD_MAX72xx_Test/MD_MAX72xx_Test.ino"

Attilator

5 years ago

Hi Shajeeb, thanks a lot for this amazing project! I love this solution very much, because it utilizes only the Arduino Nano and the LED DOT Matrix Display, i.e. no extra hardware is needed. I assembled it as per your instructions, and it works! I also tested it by a SINE signal generator (0,2V peak-peak) have noticed, that the frequencies from 20Hz till 900Hz are indicated only in the first Column. Here is the link to the video file: http://youtu.be/hQKLOAs5_ug Is there any chance to “stretch” these frequencies either in the FFT or in the script?

shajeeb

2 years ago

1. It is fine , please try and see if it makes any difference. 2. May be true, please experiment and share result here.

shajeeb

2 years ago

Thanks. What I have done is linear division of entire audio spectrum into 32 slots . Hence each column represents ~600 Hz range. Looks like what you are looking for is more expansion on the lower frequencies. Some one had commented here with "log scale" splitting of audio range, please take a look at that.

Anonymous user

2 years ago

In order to better resolve lower frequencies you'd need more samples. Say, 128 instead of 64. However, If lower frequencies is all you care about, you can actually _decrease_ _the_ _sampling_ _frequency_ and keep the number of samples unchanged. That will give you greater resolution in the lower part of the spectrum at the expense of lower resolution in upper part of the spectrum. But if you need the full range, then more samples is the only way to go.

Attilator

2 years ago

Thanks a lot. Yes, this is exactly what I am looking for. I will check his modifications. I have 2 more questions: 1. The code aubtracts the "ZERO" \\value from the digitized signal in this line: int value = ADC - 512. This way some of the values result in negative numbers. Is this OK? I was thyinking of a software "rectifier", like: if (value<0) value = -value 2. Now the code utilizes FFT library. I heard that the FHT is faster and more effetive. Is this true and applicable in this solution? Thanks for your advises.

Attilator

2 years ago

Thanks Shajeeb. I am not good enough with coding, so I am not capable to test the FHT. However, I love this project so much, that I can publish it in the national Practical Electronics Magazine to get more popularity - if you agree, please let me know.

Anonymous user

5 years ago

Is there any place with step by step instructions on this?

shajeeb

2 years ago

Sorry, I don't have any other document than what is given here.

Anonymous user

5 years ago

Great project, thanks for the idea of using FFT transform for spectrum analysis. One note: you code does it in 2 steps: collects samples and then analyses them. While collecting it technically sits waiting, then when running FFT it is not collecting. You can do both if you set ADC to use interrupt on completion (ADCSRA.ADIE) calling subprogram . Meanwhile FFT can run. Hope that will let you to increase sample size to 128 without performance loss.

shajeeb

2 years ago

Thanks for the suggestion. Samples are collected in ADC non-blocking mode hence reading 64 samples take less than 2 ms. Most majority of the time is being taken for FFT calculation which is in order of magnitude compared to sampling . So, having another samples ready while FFT is being calculated may not be useful and will have to be discarded multiple times. Also doing FFT on 128 samples (with the library I am using & ATmega328P) make the entire system laggy which spoils the fun. If interested someone can pick up on this suggestion and try out.

Anonymous user

5 years ago

would someone be kind enough to help me under stand the following code? void setup() { ADCSRA = 0b11100101; // set ADC to free running mode and set pre-scalar to 32 (0xe5) ADMUX = 0b00000000; // use pin A0 and external voltage reference pinMode(buttonPin, INPUT); mx.begin(); // initialize display delay(50); // wait to get reference voltage stabilized } void loop() { // ++ Sampling for(int i=0; i<SAMPLES; i++) { while(!(ADCSRA & 0x10)); // wait for ADC to complete current conversion ie ADIF bit set ADCSRA = 0b11110101 ; // clear ADIF bit so that ADC can do next operation (0xf5) int value = ADC - 512 ; // Read from ADC and subtract DC offset caused value vReal[i]= value/8; // Copy to bins after compressing vImag[i] = 0; }

shajeeb

2 years ago

AVR documentation might help you get details of these. Sample one is http://www.avrbeginners.net.

Anonymous user

5 years ago

I am having a problem. I did the same project with ESP32, with a splitter cable of which one end is going into spectrum analyser, and the other powers my headphones so that I can listen to the song. For some reason there is a lot of noise in my headphones the moment I power up this spectrum analyzer system. Can you please help me? P.S I am using only the left output of audio. Also, I am powering the whole thing using my laptop's USB. Putting a 220uF between VCC and GND of esp32 reduces the noise by a tiny bit. But not much.

Anonymous user

5 years ago

Hi, I like this project a lot. I was wondering how would you make this project in a smaller scale. Such as a 3x4 LED matrix.

shajeeb

2 years ago

3x4 display is too small for audio spectrum display. Probably what you need is a VU meter to show overall amplitude of the input signal.

Anonymous user

5 years ago

Hi Shajeeb Thanks for sharing your project with us all. It is very well documented and just by following it I, for one, have learnt a lot about audio, the hardware as well as FFT. There’s just a couple of minor things I’m not too sure about - - why do you have to divide the sample value by 8 before doing the FFT ? - is it really necessary to subtract the 512 due to the DC bias ? Thanks

shajeeb

2 years ago

Thank you. 1. Division by 8 is to reduce the amplitude of the measured input so that it can be uniformly (vertical) fit in the display used 2. Yes 512 need to be subtracted otherwise it will appear in the output as a DC level.

Anonymous user

2 years ago

Do you divide because you assume, that audio input comes in at max volume? In this case you may not be able to bypass your audio signal to speaker because you might want to change the volume down. I would suggest a 'learning algorithm' searching for the peak audio amplitude. Maybe with a circular buffer in addition, so you can mean the amplitude peak over a longer time and check for the amplitude history. With the peak you can adjust your divider You may use the amplitude (history) for a pi-control algorithm with saturation aswell. Saturation would be necessary to avoid infinite integration when volume is to low. (E.g. no audio input available) In this case it also could be a way to skip the controller algorithm. In order to that you can lower the volume just with an minor impact because of the low freqent step response from the algorithm (Depends on the time slot you select for the amplitude update and whether you choose a moving average by the circular buffer).

Anonymous user

5 years ago

Everything worked just fine but the modules weren´t in the correct order. So 280hz, for example, is on Modul 4 on the left side. 18600hz is on Module 1 on the right side. The direction is left to right, but the order of the Modules is 4 3 2 1. Anyone else with that problem? Maybe it´s a newer version of the Library

novax1

2 years ago

Hello If you have not been able to solve. I had the same problem and I could solve it by modifying the MD_MAX72XX file. I give an example. directory // documents / Arduino / libraries / MD_MAX7219, the document to be modified is MD_MAXX7219.h #define USE_ICSTATION_HW 1 /** •\\file •\\brief Main header file for the MD_MAX72xx library */ /** \\def USE_PAROLA_HW Set to 1 (default) to use the Parola hardware modules. The software was originally designed to operate with this hardware type. */ #define USE_PAROLA_HW 0 /** \\def USE_GENERIC_HW Set to 1 to use 'generic' hardware modules commonly available, with connectors at the top and bottom of the PCB, available from many sources. */ #define USE_GENERIC_HW 0 /** \\def USE_ICSTATION_HW Set to 1 to use ICStation DIY hardware module kits available from http://www.icstation.com/product_info.php?products_id=2609#.UxqVJyxWGHs This hardware must be set up with the input on the RHS. */ #define USE_ICSTATION_HW 1 /** \\def USE_FC16_HW Set to 1 to use FC16 hardware module kits. FC16 modules are similar in format to the ICStation modules but are wired differently. Modules are identified by a FC-16 designation on the PCB */ #define USE_FC16_HW 0 /** \\def USE_OTHER_HW Set to 1 to use other hardware not defined above. Module 0 (Data In) must be set up on the RHS and the CUSTOM hardware defines must be set up in the MD_MAD72xx_lib.h file under for this section, using the HW_Mapper utility to work out what the correct values to use are. */ #define USE_OTHER_HW 0 sorry for English but I have to translate it. I hope you find it useful. regards

shajeeb

2 years ago

Your display hardware module could be different. Try with changing the line #define HARDWARE_TYPE MD_MAX72XX::FC16_HW to #define HARDWARE_TYPE MD_MAX72XX::GENERIC_HW or #define HARDWARE_TYPE MD_MAX72XX::PAROLA_HW

ThomAce

5 years ago

Dear Friend, Your project is very good! I just used your code and built a similar stuff but with a two lines of LCD display. I have some doubts about the accuracy and representation of the frequencies, but your code is far better than the others I tried.

shajeeb

2 years ago

Thanks for your interest in my project. I just went through your modified stereo LCD version. You can check frequency response by feeding known frequency input signals (use signal generators or online tone generator) . Another point is that stereo processing causes additional latency hence you might see slow response from the system and higher frequencies are ignored.

Anonymous user

5 years ago

I'm trying to send the values through the serial port to processing to visualize the values on screen. The problem I'm having is that the output is really laggy and doesn't respond well to the music. Could this problem be caused because I'm sending it through serial instead of using the display? I'm not sure how the display works and if it is faster than serial. Thanks in advance :)

shajeeb

2 years ago

You can try with maximum serial speed. Still sending data via serial port makes the entire system to work slow as it blocks entire code till internal buffers get freed up for accepting new data pushed.

Anonymous user

5 years ago

do you have any tips on getting the code to work with an RGB matrix and having different colors for different intensity levels on each frequency?

shajeeb

2 years ago

Sorry, I never experimented with RGB matrix and libraries.

Anonymous user

5 years ago

hi i am new to this and wanted to build it but i was wondering where the arrows pointing down connect to in the project when looking at the diagram

shajeeb

2 years ago

Arrows pointing down means ground of power supply (standard representation of ground in electrical/electronic diagrams), in our case it is negative terminal of 5v supply.

Anonymous user

5 years ago

Hello everyone,I've made a board for this project With Frizting. You can use the frizting file and PCB file , using the link below: http://www.mediafire.com/file/7mnq7dspoogdna2/AudioSpectrum_With_Arduino.zip/file

shajeeb

2 years ago

Thanx.

novax1

5 years ago

Hi all. I'm new in this. Good hour, good job, it works perfectly. It is always good to find for those who know less. Thank you. Sorry for the English but I have to translate Spanish.

shajeeb

2 years ago

Thanks.

sbrennessel

5 years ago

Hello Shajeeb! Thank you for posting this, it has really jump started a personal project of mine! I am trying to adapt your code to use 32 one meter long LED strips instead of an LED matrix display. I am using the FastLED library to run the LED strips and hoping to use your code for the FFT data. I was wondering if you could explain what the peaks[] array is doing in the "send to display according measured value" section of the loop? Is this array only used when the program is in the "only peak pattern"? Also, in the "send to display according measured value" portion of the code, I wanted to make sure, after the line data_avgs[i] = map(data_avgs[i], 0, 80, 0, yres); if yres was set to be 60 (the number of LED's in the strip) instead of 8 would data_avgs[5] be equal to the number of LED's that should be lit up in the 6th strip? Thank you!

Anonymous user

2 years ago

I would like to create something similar. If you succeed please message me ;)

Anonymous user

6 years ago

hi shajeeb, thanks for sharing the amazing projects. currently i want to use 8x8 led matrix. can u guide me which part from the coding that i need to change? thanks

AlexD911

6 years ago

Hi there, this project looks great! I am looking to do a similar project myself (I am Arduino noob). Could this be implemented on a 256 x 64 OLED Display? https://www.aliexpress.com/item/NEW-OLED-Display-2-8-256-64-25664-Dots-Graphic-LCD-Module-Display-Screen-LCM-Screen/32988174566.html?spm=a2g0o.cart.99999999.259.38443c002yNZUR

lumek

2 years ago

of course, this can be displayed on many things. Your device is most likely have similar methods to display its content.

Anonymous user

6 years ago

I gave this a 120 BPM kickdrum sound and it sometimes gave a much smaller or even no pulse on the display. Can I ask why is that? I need my results to be consistent.

Alexandrelv

6 years ago

would it be complicated to change the display code of 16 x 32?

shajeeb

2 years ago

It depends on the type of change you are interested in .

shajeeb

2 years ago

Ok, your plan is to use 2 modules to form 32x16 display. A 32x8 display is formed by cascading four 8x8 displays. So you need to first get eight of 8x8 displays connected to form one 32x16 display . Once you get that working then you need to make some changes in the code like "#define yres" and "MY_MODE_x" values.

Alexandrelv

2 years ago

yes I made the following changes I left the "#define MAX DEVICES 8" but when I change the "#define yres 16" ai the display is already confused and I do not know how to modify the "MY_MODE_x" I am from Brazil thank you very much for your attention sorry for my English bad

Alexandrelv

2 years ago

I would like to use 2 modules of this increasing the lines leaving the analyzer with a matrix of 32x16 I think it would look really cool

yoghurtbox

6 years ago

I've not been able to find the MAX7219 LED display. Are you using a PCB to attach your lights or is the PCB part of the display?

yoghurtbox

2 years ago

Thank you very much!

Anonymous user

2 years ago

https://www.amazon.com/Wangdd22-MAX7219-Arduino-Microcontroller-Display/dp/B01EJ1AFW8

Anonymous user

6 years ago

Any way to adjust the scale to use more of the display? Seems that most of the #2 display sections are about as far as it lights. I can get activity along the whole display by touching the unconnected audio input. I checked all the components and hand picked for best accuracy and match. Unfortunately I don’t have access to a signal generator to fully check the out. Any thoughts? This is a great project.....thanks for sharing it!

Anonymous user

2 years ago

Thanks for your explanation of what you found. I’d love to pull this project out of the drawer it’s been hiding in. I think the code change you suggest would be awesome. Thanks!

Anonymous user

2 years ago

Hello! Have you modify/made changes to the code? Help me figure out how to make two LCD 8x64 matrices, what changes in the code are needed?

Anonymous user

2 years ago

I don’t know why I didn’t think of that..... I’ll grab one and see what happens. Thanks for the suggestion.

Anonymous user

2 years ago

So I procured a tone generator app. Although I can get the entire length of the display to light with frequency changes, the scale is too high. For example, 18khz is almost at the end of the display, 9.5khz is in the center and 4.2khz is almost at the beginning of 5he scale. It seems to me that the whole scale needs to shift down in frequency to be visually appealing and more useful in my situation. The current display output pretty much shows the first 3 or 4 columns to be the active ones. Any thoughts about shifting the whole thing down in frequency? Maybe widen the range? Thanks for the tone generator app suggestion!

Anonymous user

2 years ago

Thanks for responding. I’ve tried several audio sources. From preamp output to amplifier output and a lot in between. I adjusted bass and treble controls with no real change. Aside from the 3v3 voltage being slightly higher than your published values, I’m suspecting that 3 different Nano clones i’ve tried may not have the output speed the display needs to make this work. I’m ordering a “Genuine” Arduino Nano to compare them. I’ll post the outcome here. Ken

Anonymous user

2 years ago

Hello, Thanks for the project I have also the project to visualize frequencies from 60Hz to 16kHz. To achieve this, you say that we need to change the ADC seeting ? Is there an other solution to visualize low frequencies with the FFT ? Thomas

shajeeb

2 years ago

How are you feeding audio into the Spectrum analyzer ? If the signal has all frequencies and are reasonably strong enough then different will light up. You may try adjusting bass / treble settings (if your system has) to observe the response change.

shajeeb

2 years ago

There are online tone generators which can generate sine wave at audio frequencies. Try feeding those signals by connecting output of your computer / laptop .

shajeeb

2 years ago

It is designed to display entire audio range upto 19khz in 32 intervals. If you are looking for a system to display frequencies only up to 4khz then first thing you need to modify is the ADC sampling frequency. Please read documentation of ATmega328P and experiment.

shajeeb

2 years ago

Yes, this implementation uses linear scale to divide entire audio frequency range. Did you implement it in logarithmic scale ?

Anonymous user

2 years ago

I observe exactly same thing. I'm wondering if the FFT library has a setting to work in different frequency range or the RC combination could shift it. Any ideas much appreciated.

Anonymous user

2 years ago

It is a great project and I'll post up how I got on, however having the same "challenge" as the lads above to spread the display out of the left edge I made some slight adjustments to the ADCSRA setup which seems to have had the right effect. It might not be as pure as original but visually provides more width. Useful site: https://garretlab.web.fc2.com/en/arduino/inside/arduino/wiring_analog.c/analogRead.html Change: // ADCSRA = 0b11100101; // set ADC to free running mode and set pre-scalar to 32 (0xe5) ADCSRA = 0b11100100; // changed last bit to change division factor from 32 to 16 Great job sir

Anonymous user

2 years ago

From what I can tell from testing with a frequency response app (and some slightly modified code to run this on an LCD), the scale this uses is linear. 10kHz lines up in the center of the screen, theres equal distances between 5k-10k and 10k-15k, and all the lower frequencies are grouped up in one area. Since the lower frequencies are all getting compressed together (which is where a lot of music happens in),this would explain why all the lights group up in the spots closest to the left of the screen. It generally makes more sense, and is more traditional, to use a log scale from 20Hz-20kHz with audio. Ex, here is a graph of audio frequency ranges: https://www.google.com/url?sa=i&source=images&cd=&ved=2ahUKEwi_68eF69vlAhXPmq0KHbR2CtQQjRx6BAgBEAQ&url=https%3A%2F%2Fwww.audioreputation.com%2Faudio-frequency-spectrum-explained%2F&psig=AOvVaw0RKByNehCSf8qFBrw6kI1y&ust=1573344464507394 Ill be modifying this code sometime soon to try to have it use a log scale.

dougal

6 years ago

Nice clean uncomplicated example of sampling, FFT and display. Well done, excellent showcase !

Anonymous user

6 years ago

Hi, This project looks amazing. I have a question, can I use a liquid crystal display instead of a LED matrix display? Thanks

shajeeb

2 years ago

Yes , you can use liquid crystal display instead of a LED matrix display with required library (<LiquidCrystal.h>) and code changes. Please refer to online documents to get details of managing LCD.

Anonymous user

6 years ago

I was wondering, if I could use something else instead of the 100nF capacitors? I only have 22pF, 104pF, 10uF, 100uF capacitors at the moment and I dont want to wait weeks for new ones to arrive

Anonymous user

2 years ago

I'm quite new to electronics, does non polarized mean that the capcitor does not have a plus and a minus? If so then I think I only have the 22pF, 104pF capacitors which are non polarized.

shajeeb

2 years ago

You can connect + of the capcaitor sign towards resistor.

shajeeb

2 years ago

It is suggested to use non-polarized 100nf or 220nf or 470nf capacitor. You can try with 10uF, but response to signal may be slightly slow.

shajeeb

2 years ago

Your understanding is correct, you can use 10uF.

Anonymous user

2 years ago

My 10uF clearly has a big minus on the side of it. It also says ROHS which I dont know what it is. Can it still be used? (Ps.: these came in my arduino starter kit so I dont know much about them)

lumek

6 years ago

First I want to thank you for sharing such amazing project. Secondly should this code run on the original Arduino UNO as well? The sampling gives back only 63.00 values in vReal regardless what the Analog 0 pin may have. I'm wondering if UNO needs different setting of ADCSRA and/or ADMUX registers?

shajeeb

2 years ago

Stability of the voltage fed into AREF pin is very important to get accurate reading. In addition, increased reference voltage (5v instead 3.3v) will make ADC step response to be low for small changes in input signal. In that case you have to make sure input signal is strong enough. Please read some online document to get more details on how ATmega328P ADC behaves with external reference voltage.

shajeeb

2 years ago

Good to know that you could fix wiring error. Ideally none of the LEDs should glow when input is disconnected. Are you seeing static with input connected or disconnected ? Hope you are powering unit from a quality 5v source.

shajeeb

2 years ago

Yes, I had tested it with UNO & Nano with out any change in code.

shajeeb

2 years ago

1) This circuit works on 5v which you normally feed from USB port or a 5v charger . 2) 3.3v regulated supply is generated by UNO/Nano board , you don't have to feed it. 3) Make sure ground wire of audio cable is connected to the ground of this system. 4) Try to feed audio input from another source and compare.

lumek

2 years ago

Problem solved, I used wrong pin for AREF. Now it is working but I'm having quite a lot static comparing to your clean frequency test pictures. Besides grounded shield, can I help the circuitry to do better job with less static? Is there something I can make it better? Thank you in advance for any suggestions :)

lumek

2 years ago

Disconnected inputs are almost clean. There seem to be many other frequencies and noise when I fed single frequency from a generator app on my iPhone. It may get better when I move this from breadboard to PCB. But I have yet another question about the 3.3V. It seems as Pro Micros do not have 3.3V. Does this circuit need to supply 3.3V for correct operation or I could go away with 5V only? Thank you!

lumek

2 years ago

@2 Yes Pro Nano have both 5V and 3.3V but Pro Micro does not. Can I use the 5V instead 3.3V? Will it negatively affect the function? Thanks for helping!

Anonymous user

6 years ago

such a good project, I will do this project using stm32f407 and a microphone and map it into RGB ws2812b dot matrix

shajeeb

2 years ago

Thanks . Glad to know that you have a plan to try out with different hardware.

arduino112330

6 years ago

cool project! do you mind posting a photo of the arduino nano board and the connections to help visualize the schematic?

arduino112330

2 years ago

I am a little confused on how/where to connect the audio. Is there anyway you could post a diagram of this? How do I connect the left and right channels and also an external speaker? What kind of cord/cable do you use? Do you think I could use a microphone to pick up music instead? Thank you so much for answering my questions!

arduino112330

2 years ago

hey, just wanted to check in about a possible diagram with fritzing or a photograph of the wiring? I'm trying to build something similar and was wondering if I mount everything on a breadboard? it looks like you have two breadboards in the photo?

shajeeb

2 years ago

I may try to make a diagram with Fritzing which will have physical wiring details.

shajeeb

2 years ago

Please refer to the new images I added which shows two different ways of feeding audio input. I don't suggest to use another mic for audio pickup as the signal strength and frequency response will depend a lot on that mic.

shajeeb

2 years ago

You need to assemble only the items shown in the schematic diagram. Everything except display will easily fit on a breadboard. Second board what you see in the photo is an amplifier which connects to external speaker. That amplifier is not part of the Spectrum analyzer but it is to hear what is being played.

Anonymous user

6 years ago

How did you input audio? Just a splitter cable?

shajeeb

2 years ago

I do have one stereo 3.5mm female socket connected to the audio input wires of Spectrum analyzer. Then use a stereo 3.5mm splitter cable to connect headphone out of mobile phone to the Spectrum analyzer and to the amplifier. If you are taking audio output from line-out of the music system then you may not need splitter cable. I may try to make a diagram with Fritzing which I am not familiar with.

Anonymous user

6 years ago

The schematic is wrong - The 10k resistor should be between D5 and GND, not in series with the push button. As it is shown the link between D5 and gnd will hold D5 permanently low regdless of the pushbutton state. Otherwise a very nice project! ;)

shajeeb

2 years ago

Thanks Skywatch for catching it . I have updated the diagram.

Anonymous user

6 years ago

Your project looks very interesting. Is it possible to extend it to 2x 32x8 DOT matrix displays with 1x Arduino Nano and 1x button to display right and left stereo channel separated?

shajeeb

2 years ago

It is doable, but arduinoFFT library will be slow for computing FFT of 2 x 64 samples. One option could be to make 2 x 32 samples with caviet of less response on lower frequency band. Arduino Nano is cheaper than Dot Matrix LED display . Hence I would suggest to use 2 x Arduino Nano + 2 Displays + 1 button switch. If you power both system from same power supply you can use single switch to D5 pin of both Arduinos via 10k resistors.

Anonymous user

2 years ago

Another way you can do that, is to split the audio input into two different connections, and just make 2 circuits that do the same thing, but then you can visualize both in action.