3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

How to Make LEDs Flash to Music with an Arduino

How to Make LEDs Flash to Music with an Arduino
This is a guide to make an LED flashing circuit that "beats" to an mp3 file on your computer, which can add an awesome effect to any sound-related device, or even your room (if you extend the concept with LED drivers or plenty of resistors/transistors).

The LED flashing circuit makes use of the Minim audio library and the Arduino program Processing to analyze sound, producing a response based on a snare drum hit, a bass drum hit, and a hi-hat hit from the percussion of the audio file.

 
Remove these adsRemove these ads by Signing Up
 

Step 1Parts/Tools Needed

Parts/Tools Needed
Here is what you'll need to make the LED beat flashing circuit:

Hardware:
1. An Arduino microcontroller board. There are many versions of the Arduino, but I would recommend the Arduino Duemilanove. You can buy one online for around $20.
2. Three LEDs (different colors preferred, so you can see the difference in beats easier - I used a red, yellow, and green LED)
3. Three resistors (depending on your LEDs, the resistor value will be different - check the ratings on the LEDs to see what resistance corresponds to their maximum brightness, without burning them out)
4. A solderless breadboard
5. Some wire, to use as leads from the Arduino to the LEDs/resistors on the breadboard
6. A computer
7. A USB cable (A to B)

Software:
1. Arduino Software Environment
2. Processing Software Environment
3. The "arduino" library for Processing
4. The BeatWrite / BeatListener code from the minim JavaSound library examples

Download links for the software will follow in Step 3.

« Previous StepDownload PDFView All StepsNext Step »
81 comments
1-40 of 81next »
Apr 23, 2012. 8:27 PMDannyboy1891 says:
Hey I am making this project for my class and I am wondering if anyone knows how i could do this same thing but with 5 led's tied in series......please comment back thanks :)
Apr 30, 2012. 2:10 PMrobinsunny says:
same here, i'm gonna follow this thread in case anything comes up
May 1, 2012. 8:12 AMDannyboy1891 says:
I found out an easy way to do it without using any extra components.......just tie the led's in parallel instead of series......the arduino powered all 5 of my led's just fine make sure you have a resistor though.
May 2, 2012. 11:38 AMrobinsunny says:
do u know a way to split the bands even more so the kick has its own lows, mids, and highs and the snare would have its own lows, mids, highs and so on? what do i need to edit to recognize more frequency ranges?
May 14, 2012. 5:27 PMDannyboy1891 says:
No I havent figured that out yet either. If you find out please let me know. It would better my project.
May 1, 2012. 10:41 AMagian says:
Is it possible to save the data from processing so it doesnt need to be tethered to the computer?
Apr 30, 2012. 2:13 PMrobinsunny says:
how can i edit beatwriter to recognize just more than kick, snare, and hat? i want to split the lows, mids, and highs into 2 or more signals each and use 6 to 9 LEDs altogether
Nov 22, 2010. 6:18 AMSentinel07 says:
OK here is a new problem my friend is trying to get the processing to work but he keeps getting NullPointerException and the instruction "song.play();" keeps get highlighted any suggestions Hyrulian.
Apr 30, 2012. 1:37 PMrobinsunny says:
i have the same problem, but i can't get mine to work at all. the file is in the right place, and the code is edited accordingly. Every time i "run" it, it keeps giving me the same error and goes back to this line. any thoughts?
Feb 26, 2012. 7:56 PMjin_yeugh says:
I just tried moving the folder around and didn't realize that it had to be in the same folder as the BeatWrite file. I had it in the same zipped folder, but separate from the file. It works great now! Thanks for the pointer.
Jan 26, 2011. 5:04 PMringofrizz says:
Help me please, I'm a noob! :(

In processing, in line 35,

arduino = new Arduino(this, Arduino.list()[1], 57600);

I get an error saying, ArrayIndexOutOfBoundsException: 1

What do I do? I've had my Arduino Duemilaneve for about 4 days now, so I'm really a noob, Haha :p

Please help,
much appreciated.
Apr 26, 2012. 7:35 PMoldsmarracin says:
arduino = new Arduino(this, Arduino.list()[0], 57600);
try that
Jan 26, 2011. 10:31 PMringofrizz says:
My code looks like this now if it helps :)


/**
* This sketch demonstrates how to use the BeatDetect object in FREQ_ENERGY mode.

* You can use isKick, isSnare, isHat, isRange,
* and isOnset(int) to track whatever kind of beats you are looking to track, they will report
* true or false based on the state of the analysis. To "tick" the analysis you must call detect
* with successive buffers of audio. You can do this inside of draw, but you are likely to miss some
* audio buffers if you do this. The sketch implements an AudioListener called BeatListener
* so that it can call detect on every buffer of audio processed by the system without repeating a buffer
* or missing one.
*


* This sketch plays an entire song so it may be a little slow to load.
*/

import processing.serial.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import cc.arduino.*;

Minim minim;
AudioPlayer song;
BeatDetect beat;
BeatListener bl;
Arduino arduino;

int ledPin = 12; // LED connected to digital pin 12
int ledPin2 = 8; // LED connected to digital pin 1
int ledPin3 = 2; // LED connected to digital pin 0

float kickSize, snareSize, hatSize;

void setup() {println.Arduino.list();}
size(512, 200, P3D);

minim = new Minim(this);
arduino = new Arduino(this, Arduino.list()[1], 57600);

song = minim.loadFile("Soy Bomb", 2048);
song.play();
// a beat detection object that is FREQ_ENERGY mode that
// expects buffers the length of song's buffer size
// and samples captured at songs's sample rate
beat = new BeatDetect(song.bufferSize(), song.sampleRate());
// set the sensitivity to 300 milliseconds
// After a beat has been detected, the algorithm will wait for 300 milliseconds
// before allowing another beat to be reported. You can use this to dampen the
// algorithm if it is giving too many false-positives. The default value is 10,
// which is essentially no damping. If you try to set the sensitivity to a negative value,
// an error will be reported and it will be set to 10 instead.
beat.setSensitivity(100);
kickSize = snareSize = hatSize = 16;
// make a new beat listener, so that we won't miss any buffers for the analysis
bl = new BeatListener(beat, song);
textFont(createFont("Helvetica", 16));
textAlign(CENTER);

arduino.pinMode(ledPin, Arduino.OUTPUT);
arduino.pinMode(ledPin2, Arduino.OUTPUT);
arduino.pinMode(ledPin3, Arduino.OUTPUT);
}

void draw() {
background(0);
fill(255);
if(beat.isKick()) {
arduino.digitalWrite(ledPin, Arduino.HIGH); // set the LED on
kickSize = 32;
}
if(beat.isSnare()) {
arduino.digitalWrite(ledPin2, Arduino.HIGH); // set the LED on
snareSize = 32;
}
if(beat.isHat()) {
arduino.digitalWrite(ledPin3, Arduino.HIGH); // set the LED on
hatSize = 32;
}
arduino.digitalWrite(ledPin, Arduino.LOW); // set the LED off
arduino.digitalWrite(ledPin2, Arduino.LOW); // set the LED off
arduino.digitalWrite(ledPin3, Arduino.LOW); // set the LED off
textSize(kickSize);
text("KICK", width/4, height/2);
textSize(snareSize);
text("SNARE", width/2, height/2);
textSize(hatSize);
text("HAT", 3*width/4, height/2);
kickSize = constrain(kickSize * 0.95, 16, 32);
snareSize = constrain(snareSize * 0.95, 16, 32);
hatSize = constrain(hatSize * 0.95, 16, 32);
}

void stop() {
// always close Minim audio classes when you are finished with them
song.close();
// always stop Minim before exiting
minim.stop();
// this closes the sketch
super.stop();
}

Jan 26, 2011. 10:29 PMringofrizz says:
Thank U soooooooo much for the help Hyrulian, thank U for your fast response also!

Ok, println fixed that error, but now I get an error with the next line, line 36

size(512, 200, P3D); gest a "It looks like you're mixing "active" and "static" modes." error.

What should I do about this 1?

Thanks again for all your help!

I hope I'm not to much much of a bother, haha :P
Jan 27, 2011. 3:33 PMringofrizz says:
Well YAY! :D haha :p

That kinda fixed it, but I get a different error this time

void setup() {println.Arduino.list(); says " Cannot find anything named "println" "

Grrrr! This is getting a bit flustering ):

-ringofrizz
Jan 28, 2011. 2:38 PMringofrizz says:
Ok, I changed it to void setup() {println(Arduino.list());

But then I get a "ArrayIndexOutOfBoundsException: 1" error on

arduino = new Arduino(this, Arduino.list()[1], 57600); still.

I don't get whats wrong :(




/**
* This sketch demonstrates how to use the BeatDetect object in FREQ_ENERGY mode.

* You can use isKick, isSnare, isHat, isRange,
* and isOnset(int) to track whatever kind of beats you are looking to track, they will report
* true or false based on the state of the analysis. To "tick" the analysis you must call detect
* with successive buffers of audio. You can do this inside of draw, but you are likely to miss some
* audio buffers if you do this. The sketch implements an AudioListener called BeatListener
* so that it can call detect on every buffer of audio processed by the system without repeating a buffer
* or missing one.
*


* This sketch plays an entire song so it may be a little slow to load.
*/

import processing.serial.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import cc.arduino.*;

Minim minim;
AudioPlayer song;
BeatDetect beat;
BeatListener bl;
Arduino arduino;

int ledPin = 12; // LED connected to digital pin 12
int ledPin2 = 8; // LED connected to digital pin 1
int ledPin3 = 2; // LED connected to digital pin 0

float kickSize, snareSize, hatSize;

void setup() {println(Arduino.list());
size(512, 200, P3D);

minim = new Minim(this);
arduino = new Arduino(this, Arduino.list()[1], 57600);

song = minim.loadFile("Soy Bomb", 2048);
song.play();
// a beat detection object that is FREQ_ENERGY mode that
// expects buffers the length of song's buffer size
// and samples captured at songs's sample rate
beat = new BeatDetect(song.bufferSize(), song.sampleRate());
// set the sensitivity to 300 milliseconds
// After a beat has been detected, the algorithm will wait for 300 milliseconds
// before allowing another beat to be reported. You can use this to dampen the
// algorithm if it is giving too many false-positives. The default value is 10,
// which is essentially no damping. If you try to set the sensitivity to a negative value,
// an error will be reported and it will be set to 10 instead.
beat.setSensitivity(100);
kickSize = snareSize = hatSize = 16;
// make a new beat listener, so that we won't miss any buffers for the analysis
bl = new BeatListener(beat, song);
textFont(createFont("Helvetica", 16));
textAlign(CENTER);

arduino.pinMode(ledPin, Arduino.OUTPUT);
arduino.pinMode(ledPin2, Arduino.OUTPUT);
arduino.pinMode(ledPin3, Arduino.OUTPUT);
}

void draw() {
background(0);
fill(255);
if(beat.isKick()) {
arduino.digitalWrite(ledPin, Arduino.HIGH); // set the LED on
kickSize = 32;
}
if(beat.isSnare()) {
arduino.digitalWrite(ledPin2, Arduino.HIGH); // set the LED on
snareSize = 32;
}
if(beat.isHat()) {
arduino.digitalWrite(ledPin3, Arduino.HIGH); // set the LED on
hatSize = 32;
}
arduino.digitalWrite(ledPin, Arduino.LOW); // set the LED off
arduino.digitalWrite(ledPin2, Arduino.LOW); // set the LED off
arduino.digitalWrite(ledPin3, Arduino.LOW); // set the LED off
textSize(kickSize);
text("KICK", width/4, height/2);
textSize(snareSize);
text("SNARE", width/2, height/2);
textSize(hatSize);
text("HAT", 3*width/4, height/2);
kickSize = constrain(kickSize * 0.95, 16, 32);
snareSize = constrain(snareSize * 0.95, 16, 32);
hatSize = constrain(hatSize * 0.95, 16, 32);
}

void stop() {
// always close Minim audio classes when you are finished with them
song.close();
// always stop Minim before exiting
minim.stop();
// this closes the sketch
super.stop();
}


-ringofrizz (:

Jan 28, 2011. 3:54 PMringofrizz says:
Ok, thank U soooooooooooooooooooooooooooo much for writing i new code! :D

It seems everything works except I get

"Cannot find a class or type named "BeatListener" " on BeatListener bl; :(

-ringofrizz
Jan 28, 2011. 6:50 PMringofrizz says:
I do, yes :D

-ringofrizz
Jan 29, 2011. 1:51 PMringofrizz says:
I know I sound stupid, but how do U do that? Haha :p

-ringofrizz
Jan 20, 2012. 4:12 PMEthankell says:
Whenever I'm trying to run the script in processing I get the following error.


WARNING: RXTX Version mismatch
Jar version = RXTX-2.2pre1
native lib Version = RXTX-2.2pre2
Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 1
at BeatWrite.setup(BeatWrite.java:59)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)

It also highlights

arduino = new Arduino(this, Arduino.list()[1], 57600);


Within the script. Any ideas/help? It would be much appreciated.
Feb 21, 2012. 11:17 PMTunai says:
I did this arduino = new Arduino(this, Arduino.list()[0], 57600);

and it worked.


 I dont know about RXTX mismatch error
Apr 26, 2012. 7:32 PMoldsmarracin says:
the rxtx error is highly common and has no effect on how it works but for the rest of the error its just you didnt have the right com selected for the arduino
Apr 26, 2012. 7:29 PMoldsmarracin says:
your code worked a week ago now everytime i try and run it i get java crashes i click show more and it says faulty module rxtxserial.dll
Mar 12, 2012. 7:13 AMalexwu2211 says:
Hi, I am a 13 year old kid from taiwan, and I just failed miserably on the this Arduino- based project. This was my first Arduino project in mind, and I thought it would be a good lesson to start with. At the start everything worked out smoothly, but after I downloaded the Arduino library for Processing, things started going a little down hill. Soon my dad came over to help, but also failed. We just couldn't figure out where was Processing's library! Since I didn't succeed with this project, it would be very helpful for you guys to answer some of my questions/ suggestions, so here they are.

1) does this project only work with PC?

2) where is Processing's library?

3) could you make another picture of how to put the Arduino folder into Processing's library?

4) is the Arduino in the picture a UNO?

5) can the latest Arduino UNO work for this project


Thanks guys, this is really all I ask for!!!
Oct 10, 2011. 5:17 PMcalebpicou says:
My leds don't respond at all. I checked to make sure I had the correct pins and everything. Do I need to do something different to get it to work with the Arduino Uno?
Feb 28, 2012. 5:29 PMjin_yeugh says:
I'm still having this same problem getting the LEDs to light up. Did you ever get them working?
Feb 6, 2012. 2:24 PMtomtortoise says:
I downloaded the processing-arduino.zip, unzipped it, and copy/pasted that into the folder "libraries" that i made, (this folder is in the Processing main folder)
after this im still getting the error
the package "cc" does not exist. you might be missing a library.

no library found for cc.arduino
as of release 1.0, libraries most be installed in a folder named 'libraries' inside the 'sketchbook' folder.

i tried looking or the sketchbook folder but i cant find it, do i need to make it?
Feb 21, 2012. 11:16 PMTunai says:
In processing main window file > preferences you will see the default sketchbook location. Create a libraries folder there and copy the arduino folder to here.
Feb 22, 2011. 4:36 PMmatrixneowoman says:
I get a message stating that it cannot find a class for BeatListener. What am I missing?

Here's the exact message:
Cannot find a class or type named "BeatListener"
Jan 6, 2012. 1:28 AMgang601 says:
As you put "BeatWriter" into processing, Do it like same~
Jun 30, 2011. 7:30 PMjarvis7.1 says:
if i try to run the script in processing i get the following error.

the package "cc" does not exist. you might be missing a library.

no library found for cc.arduino
as of release 1.0, libraries most be installed in a folder named 'libraries' inside the 'sketchbook' folder.

can someone please help.
Jan 6, 2012. 1:09 AMgang601 says:
1)Go this wepsite : http://www.arduino.cc/playground/Interfacing/Processing
2)Download this -> Processing Library: processing-arduino.zip (Updated 11 Nov. 2011)
3) Unzip the file and you can find "arduino" folder
3) Copy "arduino" file into libraries(in processing folder)
4) and restart


Jul 23, 2011. 1:15 PMHandegaard says:
I get the same massage! :/ need help!
1-40 of 81next »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
3
Followers
1
Author:Hyrulian