loading

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

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

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...

<p>how would I modify the code to make 6 rgb leds work instead of just 3 </p>
<p>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 </p>
<p>Hi !</p><p>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 ?</p>
<p>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</p>
<p>how do i change the transition time b/w colors???</p>
<p>why use 3 leds when u can use a full keyboard </p><p><a href="https://www.instagram.com/p/BA60_YquSjw/" rel="nofollow">https://www.instagram.com/p/BA60_YquSjw/</a></p>
<p>C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware &quot;C:\Program Files (x86)\Arduino\hardware&quot; -tools &quot;C:\Program Files (x86)\Arduino\tools-builder&quot; -tools &quot;C:\Program Files (x86)\Arduino\hardware\tools\avr&quot; -built-in-libraries &quot;C:\Program Files (x86)\Arduino\libraries&quot; -libraries &quot;C:\Users\HieuPhysics\Documents\Arduino\libraries&quot; -fqbn=arduino:avr:uno -ide-version=10607 -build-path &quot;C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp&quot; -warnings=none -prefs=build.warn_data_percentage=75 -verbose &quot;C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde&quot;</p><p>C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware &quot;C:\Program Files (x86)\Arduino\hardware&quot; -tools &quot;C:\Program Files (x86)\Arduino\tools-builder&quot; -tools &quot;C:\Program Files (x86)\Arduino\hardware\tools\avr&quot; -built-in-libraries &quot;C:\Program Files (x86)\Arduino\libraries&quot; -libraries &quot;C:\Users\HieuPhysics\Documents\Arduino\libraries&quot; -fqbn=arduino:avr:uno -ide-version=10607 -build-path &quot;C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp&quot; -warnings=none -prefs=build.warn_data_percentage=75 -verbose &quot;C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde&quot;</p><p>&quot;C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++&quot; -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 &quot;-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino&quot; &quot;-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard&quot; &quot;C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\sketch\RGBmusic.pde.cpp&quot; -o &quot;nul&quot;</p><p>&quot;C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++&quot; -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 &quot;-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino&quot; &quot;-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard&quot; &quot;C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\sketch\RGBmusic.pde.cpp&quot; -o &quot;nul&quot;</p><p>&quot;C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++&quot; -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 &quot;-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino&quot; &quot;-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard&quot; &quot;C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\sketch\RGBmusic.pde.cpp&quot; -o &quot;C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\preproc\ctags_target_for_gcc_minus_e.cpp&quot;</p><p>&quot;C:\Program Files (x86)\Arduino\tools-builder\ctags\5.8-arduino5/ctags&quot; -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives &quot;C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\preproc\ctags_target_for_gcc_minus_e.cpp&quot;</p><p>&quot;C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++&quot; -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 &quot;-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino&quot; &quot;-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard&quot; &quot;C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\sketch\RGBmusic.pde.cpp&quot; -o &quot;C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\sketch\RGBmusic.pde.cpp.o&quot;</p><p>RGBmusic:42: error: stray '#' in program</p><p> background(#151515);</p><p> ^</p><p>RGBmusic:47: error: stray '#' in program</p><p> stroke(#FFF700);</p><p> ^</p><p>RGBmusic:84: error: stray '#' in program</p><p> stroke(#FF0000);</p><p> ^</p><p>RGBmusic:94: error: stray '#' in program</p><p> fill(#111111);</p><p> ^</p><p>RGBmusic:98: error: stray '#' in program</p><p> fill(#046700);</p><p> ^</p><p>RGBmusic:1: error: 'import' does not name a type</p><p> import ddf.minim.*; </p><p> ^</p><p>RGBmusic:2: error: 'import' does not name a type</p><p> import ddf.minim.analysis.*;</p><p> ^</p><p>RGBmusic:3: error: 'import' does not name a type</p><p> import processing.serial.*;</p><p> ^</p><p>RGBmusic:4: error: 'import' does not name a type</p><p> import cc.arduino.*;</p><p> ^</p><p>RGBmusic:6: error: 'Arduino' does not name a type</p><p> Arduino arduino;</p><p> ^</p><p>RGBmusic:8: error: 'Minim' does not name a type</p><p> Minim minim; </p><p> ^</p><p>RGBmusic:9: error: 'AudioPlayer' does not name a type</p><p> AudioPlayer song;</p><p> ^</p><p>RGBmusic:10: error: 'FFT' does not name a type</p><p> FFT fft;</p><p> ^</p><p>C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde: In function 'void setup()':</p><p>RGBmusic:29: error: 'size' was not declared in this scope</p><p> size(800, 600);</p><p> ^</p><p>RGBmusic:31: error: 'arduino' was not declared in this scope</p><p> arduino = new Arduino(this, &quot;/dev/ttyUSB0&quot;, 57600);</p><p> ^</p><p>RGBmusic:31: error: expected type-specifier before 'Arduino'</p><p> arduino = new Arduino(this, &quot;/dev/ttyUSB0&quot;, 57600);</p><p> ^</p><p>RGBmusic:31: error: expected ';' before 'Arduino'</p><p>RGBmusic:32: error: 'Arduino' was not declared in this scope</p><p> for (int i = 0; i &lt;= 13; i++) arduino.pinMode(i, Arduino.OUTPUT);</p><p> ^</p><p>In file included from C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\sketch\RGBmusic.pde.cpp:1:0:</p><p>C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:44:16: error: expected unqualified-id before numeric constant</p><p> #define OUTPUT 0x1</p><p> ^</p><p>C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde:32:62: note: in expansion of macro 'OUTPUT'</p><p> for (int i = 0; i &lt;= 13; i++) arduino.pinMode(i, Arduino.OUTPUT);</p><p> ^</p><p>C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:40:14: error: expected unqualified-id before numeric constant</p><p> #define HIGH 0x1</p><p> ^</p><p>C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde:33:66: note: in expansion of macro 'HIGH'</p><p> for (int i = 0; i &lt;= 13; i++) arduino.digitalWrite(i,arduino.HIGH);</p><p> ^</p><p>RGBmusic:35: error: 'minim' was not declared in this scope</p><p> minim = new Minim(this); </p><p> ^</p><p>RGBmusic:35: error: expected type-specifier before 'Minim'</p><p> minim = new Minim(this); </p><p> ^</p><p>RGBmusic:35: error: expected ';' before 'Minim'</p><p>RGBmusic:36: error: 'song' was not declared in this scope</p><p> song = minim.loadFile(&quot;fugly.mp3&quot;);</p><p> ^</p><p>RGBmusic:38: error: 'fft' was not declared in this scope</p><p> fft = new FFT(song.bufferSize(), song.sampleRate()); </p><p> ^</p><p>RGBmusic:38: error: expected type-specifier before 'FFT'</p><p> fft = new FFT(song.bufferSize(), song.sampleRate()); </p><p> ^</p><p>RGBmusic:38: error: expected ';' before 'FFT'</p><p>C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde: In function 'void draw()':</p><p>RGBmusic:42: error: 'background' was not declared in this scope</p><p> background(#151515);</p><p> ^</p><p>RGBmusic:44: error: 'fft' was not declared in this scope</p><p> fft.forward(song.mix);</p><p> ^</p><p>RGBmusic:44: error: 'song' was not declared in this scope</p><p> fft.forward(song.mix);</p><p> ^</p><p>RGBmusic:46: error: 'strokeWeight' was not declared in this scope</p><p> strokeWeight(1.3);</p><p> ^</p><p>RGBmusic:47: error: 'FFF700' was not declared in this scope</p><p> stroke(#FFF700);</p><p> ^</p><p>RGBmusic:47: error: 'stroke' was not declared in this scope</p><p> stroke(#FFF700);</p><p> ^</p><p>RGBmusic:50: error: 'pushMatrix' was not declared in this scope</p><p> pushMatrix();</p><p> ^</p><p>RGBmusic:51: error: 'translate' was not declared in this scope</p><p> translate(250, 0); </p><p> ^</p><p>RGBmusic:53: error: 'height' was not declared in this scope</p><p> line(i, height*4/5, i, height*4/5 - fft.getBand(i)*4); </p><p> ^</p><p>RGBmusic:53: error: 'line' was not declared in this scope</p><p> line(i, height*4/5, i, height*4/5 - fft.getBand(i)*4); </p><p> ^</p><p>RGBmusic:54: error: 'text' was not declared in this scope</p><p> if(i%100==0) text(fft.getBand(i), i, height*4/5+20);</p><p> ^</p><p>RGBmusic:82: error: 'popMatrix' was not declared in this scope</p><p> popMatrix();</p><p> ^</p><p>RGBmusic:84: error: 'FF0000' was not declared in this scope</p><p> stroke(#FF0000);</p><p> ^</p><p>RGBmusic:88: error: 'line' was not declared in this scope</p><p> line(i, 50 + song.left.get(i)*50, i+1, 50 + song.left.get(i+1)*50);</p><p> ^</p><p>RGBmusic:93: error: 'noStroke' was not declared in this scope</p><p> noStroke();</p><p> ^</p><p>RGBmusic:94: error: 'fill' was not declared in this scope</p><p> fill(#111111);</p><p> ^</p><p>RGBmusic:95: error: 'height' was not declared in this scope</p><p> rect(0, 0, 250, height);</p><p> ^</p><p>RGBmusic:95: error: 'rect' was not declared in this scope</p><p> rect(0, 0, 250, height);</p><p> ^</p><p>RGBmusic:97: error: 'textSize' was not declared in this scope</p><p> textSize(24);</p><p> ^</p><p>RGBmusic:99: error: 'text' was not declared in this scope</p><p> text(&quot;left amplitude&quot;, 10, 50); </p><p> ^</p><p>C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde: In function 'void stop()':</p><p>RGBmusic:107: error: 'arduino' was not declared in this scope</p><p> for (int i = 0; i &lt;= 13; i++) arduino.digitalWrite(i,arduino.HIGH);</p><p> ^</p><p>In file included from C:\Users\HIEUPH~1\AppData\Local\Temp\buildbfe527539d40d23b2e85452625ad86ed.tmp\sketch\RGBmusic.pde.cpp:1:0:</p><p>C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:40:14: error: expected unqualified-id before numeric constant</p><p> #define HIGH 0x1</p><p> ^</p><p>C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde:107:66: note: in expansion of macro 'HIGH'</p><p> for (int i = 0; i &lt;= 13; i++) arduino.digitalWrite(i,arduino.HIGH);</p><p> ^</p><p>RGBmusic:108: error: 'song' was not declared in this scope</p><p> song.close(); </p><p> ^</p><p>RGBmusic:109: error: 'minim' was not declared in this scope</p><p> minim.stop();</p><p> ^</p><p>RGBmusic:110: error: 'super' was not declared in this scope</p><p> super.stop();</p><p> ^</p><p>C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde: In function 'void setColor1(int, int, int)':</p><p>RGBmusic:119: error: 'arduino' was not declared in this scope</p><p> arduino.digitalWrite(redPin1, red);</p><p> ^</p><p>C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde: In function 'void setColor2(int, int, int)':</p><p>RGBmusic:130: error: 'arduino' was not declared in this scope</p><p> arduino.digitalWrite(redPin2, red);</p><p> ^</p><p>C:\Users\HieuPhysics\Downloads\RGBmusic\RGBmusic.pde: In function 'void setColor3(int, int, int)':</p><p>RGBmusic:141: error: 'arduino' was not declared in this scope</p><p> arduino.digitalWrite(redPin3, red);</p><p> ^</p><p>exit status 1</p><p>stray '#' in program</p><p>I got that message and do not know how to fix it. Please help me!!!</p>
<p>Hey, nice project.</p><p>But i notice that 'redPin1' and 'redPin3' never get to turn on. Is that on purpose or is somthing wrong with the code?</p><p>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.</p><p>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.</p><p>Btw, thanks for sharing this.</p>
<p>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</p>
<p>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 .</p><p>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.</p><p>If anyone has any idea how to do it please share.</p>
<p>So I tried to run your code but on line 36, I get a NullPointerException with an error message that says</p><p> &quot;==== JavaSound Minim Error ====</p><p>==== Error invoking createInput on the file loader object: null&quot;</p><p>Do you have any ideas about how to fix this problem? Thanks</p>
<p>Hii @jschwartz1</p><p>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 </p><p>song = minim.loadFile(&quot;songname.mp3&quot;);</p><p>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.</p>
<p>Hello <a href="https://www.instructables.com/member/jschwartz1/" rel="nofollow">jschwartz1<br></a>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 .<br>song = minim.loadFile(&quot;xyz.mp3&quot;);<br>Best regards</p>

About This Instructable

20,271views

54favorites

License:

More by stauhidi:Arduino RGB LED Music Lights Solar System Simulator using Processing 
Add instructable to: