Rahul Mohoto
Published © GPL3+

Music Spectrum Visualizer with Arduino Nano

Visualizes the peak of frequencies with different bars on 8*8 led dot matrix using Arduino Nano.

BeginnerFull instructions provided10 hours11,407

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Capacitor 10 µF
Capacitor 10 µF
×1
Resistor 1k ohm
Resistor 1k ohm
×2
Phone Audio Connector, 3.5mm
Phone Audio Connector, 3.5mm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

Circuit Diagram

Here the latch, data and clock pins are to be connected with the dot matrix, and we will be good to go.

Dot Matrix

This schematic shows how to connect 64 LEDs with shift registers and arduino to make a LED dot matrix display work

Code

Music Visualizer

Arduino
This is the main source code.
#include "fix_fft.h"

#define CLOCK 3
#define LATCH 4
#define DATA 5

#define SAMPLES 32 //define according to your need

#define AUDIO A0

char im[SAMPLES];
char data[SAMPLES];
int barht[SAMPLES];

int binary[] = {1, 2, 4, 8, 16, 32, 64, 128};
int columnBinary[] = {1, 2, 4, 8, 16, 32, 64, 128};

void setup()
{
  pinMode(CLOCK,OUTPUT);
  pinMode(LATCH,OUTPUT);
  pinMode(DATA,OUTPUT);
}

void loop()
{
  static int i, j;
  int val;
  
  // get audio data
  for(i = 0; i < SAMPLES; i++)
  {
    val = analogRead(AUDIO); // 0-1023
    data[i] = (char)(val/4 - SAMPLES); // store as char
    im[i] = 0; // init all as 0
  }

  // run FFT
  fix_fft(data, im, 5, 0); //2^5=32, as we are taking 32 samples

  // extract absolute value of data only, for 32 results
  for(i = 0; i < SAMPLES/2; i++)
  {
    barht[i] = (int)sqrt(data[i] * data[i] + im[i] * im[i]);
  }
  
  for(i = 0, j = 0; i < SAMPLES/2; i++, j += 2)
  {
    barht[i] = barht[j] + barht[j + 1];
  }

  // display barchart
  for(int k = 0; k < SAMPLES/4; k++){ //as we have 8rows and 8columns, so only 8 times we need to iterate. That's why 32/4=8 .
    digitalWrite(LATCH, LOW);
    int x = columnBinary[barht[k]%8]-1;
    shiftOut(DATA, CLOCK, LSBFIRST, ~x); // columns
    shiftOut(DATA, CLOCK, LSBFIRST, binary[k]); // rows
    digitalWrite(LATCH, HIGH);
    }
} 

LED matrix test code

Arduino
To test the custom built matrix
byte scroll[]={
  0B11111110,
  0B11111101,
  0B11111011,
  0B11110111,
  0B11101111,
  0B11011111,
  0B10111111,
  0B01111111
  };

  byte point[]={
    0B00000001,
    0B00000010,
    0B00000100,
    0B00001000,
    0B00010000,
    0B00100000,
    0B01000000,
    0B10000000
    };

    int latchPin=11;
    int clockPin=12;
    int dataPin=9;
  
void setup() {
  // put your setup code here, to run once:
  pinMode(latchPin,OUTPUT);
  pinMode(clockPin,OUTPUT);
  pinMode(dataPin,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  for(int i=0;i<8;i++){
    for(int j=0;j<8;j++){
      digitalWrite(latchPin,LOW);
      shiftOut(dataPin,clockPin,MSBFIRST,scroll[i]);
      shiftOut(dataPin,clockPin,MSBFIRST,point[j]);
      digitalWrite(latchPin,HIGH);
      delay(100);
      }
      }
}

All codes

Find all the code and circuit layouts here.

Credits

Rahul Mohoto

Rahul Mohoto

9 projects • 19 followers
Hello there. Welcome to the realm of hardware and interfacing. Have been a microcontroller enthusiast since 2011.

Comments