Introduction: Arduino RGB LED Music Lights

In this ultra-simple project, we're gonna connect 3 (three) RGB LEDs with an Arduino, and use Processing in our PC to analyze and control the LEDs.

The video basically shows what our project is all about. The LEDs displays colors than was captured in the camera. My camcoder doesn't take good videos in the dark, and the LEDs are not distinct when there is too much light. Bummer.

Step 1: Connect the Components

Picture of Connect the Components

You'll need -

  • 3 x RGB LEDs
  • 9 x 220 ohm resistors
  • Arduino
  • Wires

Connect all components as shown in the schematic.

Check the type of your RGB LEDs. I'm using the Common Anode type. Hence, the anodes are all connected to +5v pin of the Arduino. If your LEDs are of the Common Cathode type, you need to connect them all to GND.

Open the Arduino IDE, go to File > Examples > Firmata > StandardFirmata, and upload the example sketch to your Arduino.

Step 2: Time to Party

Picture of Time to Party

Open the Processing IDE if you already have Processing installed, else install it. Then go to Sketch > Import Libraries and check if Arduino (Firmata) is on the list. If it's not there, install it from Sketch > Import Libraries... > Add Library...

Download the source code (musicLED.pde) from the bottom of this page and open it using Processing. Processing will copy it into a folder with the same name. Copy a mp3 song into the folder (/path/to/musicLED) where you saved the Processing sketch. Change the song.mp3 string in line 36 to the name of your mp3 file, or rename your mp3 file to song.mp3.

As I said before, I'm using the Common Anode type of RGB LEDs. If you have the Common Cathode type, you have to change int common_cathode = 0 to int common_cathode = 1 on line 26 in the above source code.

Also, you should probably use some basic program to check whether the variables like redPin1, bluePin2, etc. are all correct. Different RGB LEDs may have different pin patterns.

Also you have to change the /dev/ttyUSB0 in line 31 to point to your Arduino's port (something like /dev/name on Linux or com5 on Windows).

Put on your party hats, hit run (the triangular thing on the top of the Processing IDE). Sit back and enjoy...

You can also find this tutorial here .

Comments

davonbrown3 (author)2017-05-21

how would I modify the code to make 6 rgb leds work instead of just 3

Malleckie (author)2016-12-10

I was ale to correct my issue. My baud rate was at 9600. I put it to 57600 and it works perfect now. hopes this helps

YatendraB (author)2015-09-18

Hi !

I have done all the steps as brief in tutorial and able to run the music too. But my LED's are only glowing initially and not changing with music. Kindly help me out ?

Malleckie (author)YatendraB2016-12-10

I am having the same issue. Did you figure it out? please if so let me know i really want to finish this amazing project thank you

aakhtar1 (author)2016-02-06

how do i change the transition time b/w colors???

dicamarques made it! (author)2016-01-24

why use 3 leds when u can use a full keyboard

https://www.instagram.com/p/BA60_YquSjw/

MaiH3 (author)2016-01-19

C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware "C:\Program Files (x86)\Arduino\hardware" -tools "C:\Program Files (x86)\Arduino\tools-builder" -tools "C:\Program Files (x86)\Arduino\hardware\tools\avr" -built-in-libraries "C:\Program Files (x86)\Arduino\libraries" -libraries "C:\Users\HieuPhysics\Documents\Arduino\libraries" -fqbn=arduino:avr:uno -ide-version=10607 -build-path "C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp" -warnings=none -prefs=build.warn_data_percentage=75 -verbose "C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde"

C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware "C:\Program Files (x86)\Arduino\hardware" -tools "C:\Program Files (x86)\Arduino\tools-builder" -tools "C:\Program Files (x86)\Arduino\hardware\tools\avr" -built-in-libraries "C:\Program Files (x86)\Arduino\libraries" -libraries "C:\Users\HieuPhysics\Documents\Arduino\libraries" -fqbn=arduino:avr:uno -ide-version=10607 -build-path "C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp" -warnings=none -prefs=build.warn_data_percentage=75 -verbose "C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde"

"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\sketch\RGBmusic.pde.cpp" -o "nul"

"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\sketch\RGBmusic.pde.cpp" -o "nul"

"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\sketch\RGBmusic.pde.cpp" -o "C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\preproc\ctags_target_for_gcc_minus_e.cpp"

"C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino5/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\preproc\ctags_target_for_gcc_minus_e.cpp"

"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10607 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard" "C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\sketch\RGBmusic.pde.cpp" -o "C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\sketch\RGBmusic.pde.cpp.o"

RGBmusic:42: error: stray '#' in program

background(#151515);

^

RGBmusic:47: error: stray '#' in program

stroke(#FFF700);

^

RGBmusic:84: error: stray '#' in program

stroke(#FF0000);

^

RGBmusic:94: error: stray '#' in program

fill(#111111);

^

RGBmusic:98: error: stray '#' in program

fill(#046700);

^

RGBmusic:1: error: 'import' does not name a type

import ddf.minim.*;

^

RGBmusic:2: error: 'import' does not name a type

import ddf.minim.analysis.*;

^

RGBmusic:3: error: 'import' does not name a type

import processing.serial.*;

^

RGBmusic:4: error: 'import' does not name a type

import cc.arduino.*;

^

RGBmusic:6: error: 'Arduino' does not name a type

Arduino arduino;

^

RGBmusic:8: error: 'Minim' does not name a type

Minim minim;

^

RGBmusic:9: error: 'AudioPlayer' does not name a type

AudioPlayer song;

^

RGBmusic:10: error: 'FFT' does not name a type

FFT fft;

^

C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde: In function 'void setup()':

RGBmusic:29: error: 'size' was not declared in this scope

size(800, 600);

^

RGBmusic:31: error: 'arduino' was not declared in this scope

arduino = new Arduino(this, "/dev/ttyUSB0", 57600);

^

RGBmusic:31: error: expected type-specifier before 'Arduino'

arduino = new Arduino(this, "/dev/ttyUSB0", 57600);

^

RGBmusic:31: error: expected ';' before 'Arduino'

RGBmusic:32: error: 'Arduino' was not declared in this scope

for (int i = 0; i <= 13; i++) arduino.pinMode(i, Arduino.OUTPUT);

^

In file included from C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\sketch\RGBmusic.pde.cpp:1:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:44:16: error: expected unqualified-id before numeric constant

#define OUTPUT 0x1

^

C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde:32:62: note: in expansion of macro 'OUTPUT'

for (int i = 0; i <= 13; i++) arduino.pinMode(i, Arduino.OUTPUT);

^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:40:14: error: expected unqualified-id before numeric constant

#define HIGH 0x1

^

C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde:33:66: note: in expansion of macro 'HIGH'

for (int i = 0; i <= 13; i++) arduino.digitalWrite(i,arduino.HIGH);

^

RGBmusic:35: error: 'minim' was not declared in this scope

minim = new Minim(this);

^

RGBmusic:35: error: expected type-specifier before 'Minim'

minim = new Minim(this);

^

RGBmusic:35: error: expected ';' before 'Minim'

RGBmusic:36: error: 'song' was not declared in this scope

song = minim.loadFile("fugly.mp3");

^

RGBmusic:38: error: 'fft' was not declared in this scope

fft = new FFT(song.bufferSize(), song.sampleRate());

^

RGBmusic:38: error: expected type-specifier before 'FFT'

fft = new FFT(song.bufferSize(), song.sampleRate());

^

RGBmusic:38: error: expected ';' before 'FFT'

C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde: In function 'void draw()':

RGBmusic:42: error: 'background' was not declared in this scope

background(#151515);

^

RGBmusic:44: error: 'fft' was not declared in this scope

fft.forward(song.mix);

^

RGBmusic:44: error: 'song' was not declared in this scope

fft.forward(song.mix);

^

RGBmusic:46: error: 'strokeWeight' was not declared in this scope

strokeWeight(1.3);

^

RGBmusic:47: error: 'FFF700' was not declared in this scope

stroke(#FFF700);

^

RGBmusic:47: error: 'stroke' was not declared in this scope

stroke(#FFF700);

^

RGBmusic:50: error: 'pushMatrix' was not declared in this scope

pushMatrix();

^

RGBmusic:51: error: 'translate' was not declared in this scope

translate(250, 0);

^

RGBmusic:53: error: 'height' was not declared in this scope

line(i, height*4/5, i, height*4/5 - fft.getBand(i)*4);

^

RGBmusic:53: error: 'line' was not declared in this scope

line(i, height*4/5, i, height*4/5 - fft.getBand(i)*4);

^

RGBmusic:54: error: 'text' was not declared in this scope

if(i%100==0) text(fft.getBand(i), i, height*4/5+20);

^

RGBmusic:82: error: 'popMatrix' was not declared in this scope

popMatrix();

^

RGBmusic:84: error: 'FF0000' was not declared in this scope

stroke(#FF0000);

^

RGBmusic:88: error: 'line' was not declared in this scope

line(i, 50 + song.left.get(i)*50, i+1, 50 + song.left.get(i+1)*50);

^

RGBmusic:93: error: 'noStroke' was not declared in this scope

noStroke();

^

RGBmusic:94: error: 'fill' was not declared in this scope

fill(#111111);

^

RGBmusic:95: error: 'height' was not declared in this scope

rect(0, 0, 250, height);

^

RGBmusic:95: error: 'rect' was not declared in this scope

rect(0, 0, 250, height);

^

RGBmusic:97: error: 'textSize' was not declared in this scope

textSize(24);

^

RGBmusic:99: error: 'text' was not declared in this scope

text("left amplitude", 10, 50);

^

C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde: In function 'void stop()':

RGBmusic:107: error: 'arduino' was not declared in this scope

for (int i = 0; i <= 13; i++) arduino.digitalWrite(i,arduino.HIGH);

^

In file included from C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\sketch\RGBmusic.pde.cpp:1:0:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:40:14: error: expected unqualified-id before numeric constant

#define HIGH 0x1

^

C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde:107:66: note: in expansion of macro 'HIGH'

for (int i = 0; i <= 13; i++) arduino.digitalWrite(i,arduino.HIGH);

^

RGBmusic:108: error: 'song' was not declared in this scope

song.close();

^

RGBmusic:109: error: 'minim' was not declared in this scope

minim.stop();

^

RGBmusic:110: error: 'super' was not declared in this scope

super.stop();

^

C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde: In function 'void setColor1(int, int, int)':

RGBmusic:119: error: 'arduino' was not declared in this scope

arduino.digitalWrite(redPin1, red);

^

C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde: In function 'void setColor2(int, int, int)':

RGBmusic:130: error: 'arduino' was not declared in this scope

arduino.digitalWrite(redPin2, red);

^

C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde: In function 'void setColor3(int, int, int)':

RGBmusic:141: error: 'arduino' was not declared in this scope

arduino.digitalWrite(redPin3, red);

^

exit status 1

stray '#' in program

I got that message and do not know how to fix it. Please help me!!!

SrBla (author)2015-11-09

Hey, nice project.

But i notice that 'redPin1' and 'redPin3' never get to turn on. Is that on purpose or is somthing wrong with the code?

I also notice that with some songs the LEDs seems to not react, i suspect that it has something to do with the frequency/rythm of the music. This happens, for instance, wit the music Afterglow from Wilkison.

If you could give some more information about what the code does it would be nice, since i don't hnow what some of the instructions are doing.

Btw, thanks for sharing this.

KyleL1 (author)2015-05-14

Is there a way to process music being played over speakers. So can i open Pandora and have this analyze the output audio? I know this specific code you need to load one .mp3 at a time, but i was looking for someone who may have modified it to just listen to music internally

SahibaA1 (author)KyleL12015-05-22

Hii i have also used minim's beatWrite library and this code restricts to the use of one mp3 that is mentioned in code itself.We just can't play any random music file and let arduino do the work.This can only be achieved if we extend the sensory capabilities of our board by using a sound sensor so for that we have to write a new code to analyse the input coming from sound sensor and define the range for drum beats or other musical frequencies.There is another approach too .

We can make the code access our entire music folder on our hard disk (PC/Computer) but i am also tinkering how can this be done.

If anyone has any idea how to do it please share.

jschwartz1 (author)2014-06-08

So I tried to run your code but on line 36, I get a NullPointerException with an error message that says

"==== JavaSound Minim Error ====

==== Error invoking createInput on the file loader object: null"

Do you have any ideas about how to fix this problem? Thanks

SahibaA1 (author)jschwartz12015-05-22

Hii @jschwartz1

I got this issue resolved by saving the entire sketch it will create a folder with the name of sketch you will be saving in processing folder there all you need to do it keep the mp3 file of the song you mentioned in

song = minim.loadFile("songname.mp3");

in this way it will load file from for the sketch u have saved and you won't get nullPointerException happens when the minim object u created is pointing to a file you have asked for coz of the loadFile() function but the file is not there.So all you need to do is save the sketch with new name in access this new folder created in processing folder there in that folder just copy the mp3 file.

marslan2 (author)jschwartz12014-06-25

Hello jschwartz1
I had this problem but I solve this problem first you will add a mp3 in the processing however this mp3 may be short and for example your mp3 is name xyz I have to write this .
song = minim.loadFile("xyz.mp3");
Best regards