Reader small image

You're reading from  Arduino BLINK Blueprints

Product typeBook
Published inMay 2016
PublisherPackt
ISBN-139781785284182
Edition1st Edition
Tools
Right arrow
Author (1)
Utsav Shah
Utsav Shah
author image
Utsav Shah

Utsav Shah is an instrumentation engineer who loves to work on the latest hardware as well as software technologies. He has been featured on India's leading website http://yourstory.in and Ahmedabad Mirror (Times Group) for his research work on "Converting sign language into speech" using a Leap Motion controller. Apart from his regular work at Infosys Limited, he manages activities of Infosys Robotics Club. In his leisure time, he loves to read books and work on cutting-edge technologies.
Read more about Utsav Shah

Right arrow

Chapter 5. Sound Visualization and LED Christmas Tree

Things get pretty easy once you have understood the basics of Arduino and how to control the "stuff" with Arduino. In the previous chapters, we have developed some useful projects using LEDs and light sensors. We also learned soldering in the previous chapter. In this chapter, we will understand how to visualize sound using Arduino and then we will develop an LED Christmas tree.

  • Introduction to sound visualization

  • Sound visualization using Arduino

  • Developing a sound controlled Christmas tree

Introduction to sound visualization


Sound visualization, or music visualization, has been an integral part of the music industry since the evolution of media players. For example, on your computer, when you play any music, you can see the visualization in the default media player or VLC media player, as shown in the following image:

You have noticed that, as the loudness of the music, or the frequency of the sound changes, the visualization changes. We will use the same principle to visualize sound using Arduino.

How to visualize the sound

In simple terms, sound/music is nothing but a series of signals with a certain frequency and a certain amplitude. We can get the value at each point by using analogRead(). But, this function would be much too slow for sampling audio. So, we will use the microcontroller's analog-to-digital converter, which automatically takes repeated analog intervals at precise intervals. We will learn both ways of sampling audio. There are a number of algorithms available...

Sound visualization using Arduino


After understanding the basics of sound visualization, we will move on to implement sound visualization using Arduino. Before we develop our LED Christmas tree, we will develop sound visualization on an LED matrix.

An LED matrix is a combination of 64 LEDs connected together as shown in the following circuit. As Arduino doesn't have 64 pins, we can't connect individual pins to control each LED. Instead, we will use the concept of multiplexing:

With the use of multiplexing, we can control any number of LEDs with Arduino. For controlling an 8 x 8 LED matrix, we need one multiplexer circuit. We can use the backpack from adafruit for the multiplexer, or a MAX7219 Dot Matrix MCU Control for the multiplexer part:

So, now we do not need to use a lot of pins to control this LED matrix. Instead, we require only four pins to control this LED matrix.

You will need the following components for a music-controlled LED matrix:

  • Analog Mic Sensor

  • 8 x 8 LED matrix with backpack...

Developing an LED Christmas tree


We are now familiar with the concept of sound visualization. We have also learnt about controlling an LED matrix with music. Now, we will develop an LED Christmas tree, which will blink the LEDs as per the music beats.

To develop the basic circuit which responds to the beats, connect the circuit as shown in the following image:

We will connect the audio input/mic to the analog pin 3 of the Arduino. We have connected LEDs to pins 5 to 12.

Once you have connected the circuit as mentioned, upload the following code on the Arduino:

#include <fix_fft.h>

int LEDPins[] = {5, 6, 7, 8, 9, 10, 11, 12};
int x = 0;
char imaginary[128], inputSignal[128];
char outputAverage[14];
int i = 0, inputValue;
#define AUDIOPIN 1

void setup()
{
  for (int i = 0; i < 8; i++)
  {
    pinMode(LEDPins[i], OUTPUT);
  }
  Serial.begin(9600);
}

void loop()
{
  for (i = 0; i < 128; i++) {
    inputValue = analogRead(AUDIOPIN);
    inputSignal[i] = inputValue;
    imaginary[i...

Summary


In this chapter, we started with the basics of sound visualization. After understanding the FFT algorithm, we move on to visualize the sound with Arduino using the same on an 8 x 8 dot matrix LED display. At the end of this chapter, we developed an LED Christmas tree, which syncs its light as per the beats in the music. In the next chapter, we will move on to develop "persistence of vision".

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Arduino BLINK Blueprints
Published in: May 2016Publisher: PacktISBN-13: 9781785284182
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Utsav Shah

Utsav Shah is an instrumentation engineer who loves to work on the latest hardware as well as software technologies. He has been featured on India's leading website&nbsp;http://yourstory.in and Ahmedabad Mirror (Times Group) for his research work on "Converting sign language into speech" using a Leap Motion controller. Apart from his regular work at Infosys Limited, he manages activities of Infosys Robotics Club. In his leisure time, he loves to read books and work on cutting-edge technologies.
Read more about Utsav Shah