# Tiny Arduino Music Visualizer

## Overview

**UPDATE: this is an older guide designed for boards like the Arduino Uno and Adafruit METRO 328. It relies on _assembly language_ code that’s specific to 8-bit AVR microcontrollers and will not work with boards based on other chips (ESP32, RP2040, SAMD, etc.).**

http://youtu.be/Tmpl5KA02S4

(Music: _The Owl Named Orion_ by Dan-O at DanoSongs.com)  
  
Here’s an easy-to-build project that really packs a lot of _blinkenlight_ for the effort: a little pocket-size music visualizer we call “Piccolo.”  
  
Set Piccolo next to the telly or some speakers and you’ll see the lights respond to music and sound — lowest notes toward the left end of the graph, highest notes toward the right.  
  
Technically this would be called a “spectrum analyzer,” but as this is not a precision scientific instrument, we’re more comfortable labeling it a “visualizer.” It’s strictly for show.  
  
This intermediate Arduino project shows a clear progression from input to processing and then output in a package that’s appealing and easy for minds to grasp: music and lights. It’s not abstract or “science-y” unless you choose to peel back the layers…

# Tiny Arduino Music Visualizer

## Wiring

Begin by assembling the LED matrix and “backpack” board&nbsp;as described in the [Adafruit LED Backpacks tutorial](http://learn.adafruit.com/adafruit-led-backpack/bi-color-8x8-matrix).  
  
If using the LED matrix for the first time, we <u>very strongly</u> recommend working through that full tutorial first. This will let you test and confirm that the Matrix is properly assembled before moving on to this more advanced project.

![](https://cdn-learn.adafruit.com/assets/assets/000/002/700/medium800/led_matrix_backpack.jpg?1396785913)

If working with a breadboard as shown below, solder row headers on to the microphone breakout and LED matrix backpack boards (three pins on the former, four on the latter). You can optionally use 90 degree headers if you’d like either component to be positioned standing up.

Thanks to the “smarts” of the LED matrix backpack, this whole project requires fewer than a dozen connections total:

- Connect the Arduino’s **3.3V** &nbsp;pin both to the mic amp **VCC** pin and the Arduino’s **AREF** pin.&nbsp;We use one of the power rails on the breadboard to route 3.3 Volts to both locations.&nbsp;The AREF connection is very important — don’t overlook this!
- Connect the Arduino&nbsp; **5V** pin to the LED matrix **+** pin.
- Connect Arduino&nbsp; **GND** pin to both the mic amp **GND** pin and the LED matrix **–** pin. You can use a breadboard power rail, or the Arduino has multiple GND pins available.
- Connect Arduino **analog pin 0** to the mic amp **OUT** pin.
- Connect Arduino pins **SDA** and **SCL** to the matrix backpack **D** (data) and **C** (clock) pins, respectively. **Earlier Arduino boards don’t include SDA and SCL pins — instead, use analog pins 4** (for SDA) **and 5** (SCL) **.**

For a current “R3” Arduino board (such as the Arduino Leonardo or more recent Arduino Uno and Mega&nbsp;boards), the wiring should resemble this:

![](https://cdn-learn.adafruit.com/assets/assets/000/002/696/medium800/led_matrix_layout-r3.png?1396785885)

If using a “classic” Arduino board — an Arduino Uno version R1 or R2, Arduino Duemilanove or&nbsp;Diecimila (with 328P chip), the matrix data and clock lines should be connected to analog pins 4 and 5:

![](https://cdn-learn.adafruit.com/assets/assets/000/002/695/medium800/led_matrix_layout-classic.png?1396785867)

_ **Note: the project only works with 8-bit AVR boards.** It relies on a library that’s written in assembly language, and won’t compile on newer 32-bit boards like Arduino Zero or Adafruit Metro Express._

Piece of cake!

You can power the Arduino from the USB connection or using a battery or power supply connected to the DC jack. The LED matrix draws a couple hundred milliamps at most, so we can safely power it through the Arduino.

# Tiny Arduino Music Visualizer

## Code

This button will download a folder containing all the code needed for this project:

[Download “Piccolo” Arduino source code](https://github.com/adafruit/Adafruit_Learning_System_Guides/tree/main/Tiny_Music_Visualizer)
The code can [also be found on Github](https://github.com/adafruit/Adafruit_Learning_System_Guides/tree/main/Tiny_Music_Visualizer).

After uncompressing the ZIP file, inside you’ll find a folder called _Piccolo._ This can be moved to your Arduino documents folder if you like. The **Piccolo.ino** file in there is the main project source code — open this in the Arduino IDE.

Two libraries are required for this: **Adafruit\_LEDBackpack** and **Adafruit\_GFX**. If you worked through the basic LED matrix backpack guide first, these should already be present. Otherwise, both can be found in the Arduino Library Manager (Sketch→Include Library→Manage Libraries…)

With the Piccolo sketch open, select your Arduino board type and serial port from the Tools menu. Then click the Upload button. After a moment, if all goes well, you’ll see the message “Done uploading.” The project should now be responsive to sound…try clapping your hands!

## Troubleshooting
If there’s no response from the device, try the following:

- Test the matrix using the example code from the Adafruit\_LEDBackpack Library. If there’s no response, the clock and data pins might be swapped, or the matrix may have been soldered to the board backwards.
- Double-check all wiring against the diagrams. Did you include the 3.3V-to-AREF connection?&nbsp;D and C pins from the matrix backpack should connect to SDA and SCL on newer Arduinos, or analog pins 4 and 5 on older boards.
- The gain on the mic amplifier may be set low. There’s a dial on the back of the board that can be adjusted with a small screwdriver.
- Try increasing the music volume.

## Principle of Operation
Using the normal Arduino analogRead() function would be <u>much</u> too slow for sampling audio.&nbsp;Instead, a feature&nbsp;of the microcontroller’s analog-to-digital converter called _free-run mode_ is utilized. This automatically takes repeated analog samples at precise intervals…about 9.6 KHz for this project, the maximum a 16 MHz Arduino can handle with 10-bit samples.

This is strictly mono. There isn’t enough RAM or processor _oomph_ for stereo.  
  
The raw audio samples are converted into a _frequency spectrum_ using a _[fast Fourier transform](http://en.wikipedia.org/wiki/Fast_Fourier_transform)_&nbsp;or FFT.&nbsp;There are a number of Arduino FFT libraries out there, but we keep finding ourselves returning to the venerable&nbsp;[ELM-ChaN ffft library](http://elm-chan.org/works/akilcd/report_e.html)&nbsp;for its speed and good looks.  
  
The FFT output still needs a bit of massaging to make for a good presentation on the limited 8x8 matrix. Several tables of scales and weights de-emphasize certain frequency ranges as they’re reduced to just eight columns. The software works at keeping the graph interesting, but some columns will always be less lively than others, especially comparing live speech against music of varying genres. If everything seems to stick toward one end of the graph, try another musician, musical genre, or different speakers.

# Tiny Arduino Music Visualizer

## Ideas

Our wiring diagrams illustrated this project with a half-size breadboard, but for a smaller package the parts can also&nbsp;fit on an Arduino breakout shield:

![](https://cdn-learn.adafruit.com/assets/assets/000/002/697/medium800/led_matrix_proto.jpg?1396785894)

Depending how you choose to orient the LED matrix, the matrix.setRotation() function can be used to keep the graph upright.

Just a concept — this is not functional — but it’s interesting&nbsp;to note that an Arduino Micro, the LED matrix and the microphone amplifier are almost perfectly matched to the dimensions of a 9 Volt battery:

![](https://cdn-learn.adafruit.com/assets/assets/000/002/698/medium800/led_matrix_idea.jpg?1396785897)

If you do attempt an extra-compact build like this, please keep in mind that the Arduino Micro includes a 5 Volt regulator, allowing it to be powered from a 9 Volt battery. Most small form-factor Arduino-compatible boards **do not include a regulator** ,&nbsp;and **will be damaged if you attempt to power them directly from 9 Volts!** For such boards, either add your own regulator to the circuit, or use an appropriate battery pack: three alkaline AA or AAA cells in series, or four rechargeable NiMH cells.  
  
Additionally, the code may need adjustments for some “alternative” Arduino boards…most likely the analog channel number, which may be mapped to different pin numbers on different boards.

Finally, because ADC registers are accessed directly, specific interrupts are used, and the FFT code is in AVR assembly language, this software **will not run** on upscale boards like the ESP32, Pico RP2040 or Teensy 3.0. It is strictly for “classic” Arduinos.


## Featured Products

### Adafruit Bicolor LED Square Pixel Matrix with I2C Backpack

[Adafruit Bicolor LED Square Pixel Matrix with I2C Backpack](https://www.adafruit.com/product/902)
What's better than a single LED? Lots of LEDs! A fun way to make a small colorful display is to use a [1.2" Bi-color 8x8 LED Matrix](http://www.adafruit.com/products/458). Matrices like these are 'multiplexed' - so to control all the 128 LEDs you need 24 pins....

Out of Stock
[Buy Now](https://www.adafruit.com/product/902)
[Related Guides to the Product](https://learn.adafruit.com/products/902/guides)
### Electret Microphone Amplifier - MAX4466 with Adjustable Gain

[Electret Microphone Amplifier - MAX4466 with Adjustable Gain](https://www.adafruit.com/product/1063)
Add an ear to your project with this well-designed electret microphone amplifier. This fully assembled and tested board comes with a 20-20KHz electret microphone soldered on. For the amplification, we use the Maxim MAX4466, an op-amp specifically designed for this delicate task! The amplifier...

In Stock
[Buy Now](https://www.adafruit.com/product/1063)
[Related Guides to the Product](https://learn.adafruit.com/products/1063/guides)
### Adafruit METRO 328 Fully Assembled - Arduino IDE compatible

[Adafruit METRO 328 Fully Assembled - Arduino IDE compatible](https://www.adafruit.com/product/50)
We sure love the ATmega328 here at Adafruit, and we use them&nbsp;_a lot_&nbsp;for our own projects. The processor has plenty of GPIO, Analog inputs, hardware UART SPI and I2C, timers and PWM galore - just enough for most simple projects. When we need to go small, we use a <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/50)
[Related Guides to the Product](https://learn.adafruit.com/products/50/guides)
### Breadboarding wire bundle

[Breadboarding wire bundle](https://www.adafruit.com/product/153)
75 flexible stranded core wires with stiff ends molded on in red, orange, yellow, green, blue, brown, black and white. These are a major improvement over the "box of bent wires" that are sometimes sold with breadboards, and faster than stripping your own solid core wires. Makes...

In Stock
[Buy Now](https://www.adafruit.com/product/153)
[Related Guides to the Product](https://learn.adafruit.com/products/153/guides)
### Half Sized Premium Breadboard - 400 Tie Points

[Half Sized Premium Breadboard - 400 Tie Points](https://www.adafruit.com/product/64)
This is a cute, half-size breadboard with&nbsp;400 tie points, good for small projects. It's 3.25" x 2.2" / 8.3cm&nbsp;x 5.5cm&nbsp;with a standard double-strip in the middle and two power rails on both sides.&nbsp;You can pull the power rails off easily to make the breadboard as...

Out of Stock
[Buy Now](https://www.adafruit.com/product/64)
[Related Guides to the Product](https://learn.adafruit.com/products/64/guides)

## Related Guides

- [Adafruit LED Backpacks](https://learn.adafruit.com/adafruit-led-backpack.md)
- [Program an AVR or Arduino Using Raspberry Pi GPIO](https://learn.adafruit.com/program-an-avr-or-arduino-using-raspberry-pi-gpio-pins.md)
- [Line Following Zumo Robot Using Simulink](https://learn.adafruit.com/line-following-zumo-robot-programmed-with-simulink.md)
- [ TensorFlow Lite for EdgeBadge Quickstart](https://learn.adafruit.com/tensorflow-lite-for-edgebadge-kit-quickstart.md)
- [Ladyada's Learn Arduino - Lesson #2](https://learn.adafruit.com/ladyadas-learn-arduino-lesson-number-2.md)
- [Adafruit CC3000 WiFi and Xively](https://learn.adafruit.com/adafruit-cc3000-wifi-and-xively.md)
- [Let’s Put LEDs in Things!](https://learn.adafruit.com/lets-put-leds-in-things.md)
- [Wireless Power Switch with Arduino & the CC3000 WiFi Chip](https://learn.adafruit.com/wireless-power-switch-with-arduino-and-the-cc3000-wifi-chip.md)
- [Sous-vide controller powered by Arduino - The SousViduino!](https://learn.adafruit.com/sous-vide-powered-by-arduino-the-sous-viduino.md)
- [Arduino Lesson 7. Make an RGB LED Fader](https://learn.adafruit.com/adafruit-arduino-lesson-7-make-an-rgb-led-fader.md)
- [TTL Serial Camera](https://learn.adafruit.com/ttl-serial-camera.md)
- [Bluetooth Controlled Motorized Camera Slider](https://learn.adafruit.com/bluetooth-motorized-camera-slider.md)
- [Trinket Audio Player](https://learn.adafruit.com/trinket-audio-player.md)
- [Arduino Lesson 11. LCD Displays - Part 1](https://learn.adafruit.com/adafruit-arduino-lesson-11-lcd-displays-1.md)
- [LSM303 Accelerometer + Compass Breakout](https://learn.adafruit.com/lsm303-accelerometer-slash-compass-breakout.md)
- [Using NeoPixels and Servos Together](https://learn.adafruit.com/neopixels-and-servos.md)
