Project in progress

Music Adaptive RGB LED with Arduino and Processing

Make a RGB LED shine adaptively to a music played on a computer with processing.

  • 998 views
  • 6 comments
  • 10 respects

Components and supplies

About this project

I was playing around with processing and FFT (Fast Fourier Transform) and had the idea to use the 3 components of a FFT as a RGB colour and communicate it to my Arduino card using the processing serial library to make a RGB led shine with this colour.

The result is a led that shines adaptively to music and it’s nice looking and very easy to do.

For those who don't know what Processing is. It is a programming tool built on top of java, for coding visual arts. You can download it here:

https://processing.org/

and for this project you will need to install the Processing Sound library.

https://processing.org/reference/libraries/

How to change the audio file path:

After creating a new sketch and writing the code below, go to your sketch folder and create a folder and name it "data".

Copy-past the audio file you want, to the "data" folder.

Then change the file name in your code.

sample = new SoundFile(this, "music.mp3");  // select your music here

Please note that Processing works very well with mono-channel sound files. You could find some issues with stereo files.

Code

music_led.inoArduino
int red_pin = 9;
int green_pin = 10;
int blue_pin = 11;


int r = 0;
int g = 0;
int b = 0;

void setup()
{
  Serial.begin(9600);
  
  pinMode(red_pin, OUTPUT);
  pinMode(green_pin, OUTPUT);
  pinMode(blue_pin, OUTPUT);  
}
 
void loop()
{
  if (Serial.available() > 0) {
                r = Serial.read();
                g = Serial.read();
                b = Serial.read();
                
                analogWrite(red_pin, r);
                analogWrite(green_pin, g);
                analogWrite(blue_pin, b); 
       }
  delay(100);

}
music_led.pdeProcessing
import processing.sound.*;  
import processing.serial.*;  

SoundFile sample;   
FFT fft;    
AudioDevice device;  

Serial myPort;   

float[] spectrum =new float[3];
float r, g, b;

float smoothing = 0.2;

public void setup() {
  size(640, 360);  
  
  device = new AudioDevice(this, 44000, 3);
  
  sample = new SoundFile(this, "music.mp3");  // select your music here
  sample.loop();

  fft = new FFT(this, 3);
  fft.input(sample);
  
  String portName = Serial.list()[2]; // for me it's 2 but could be at a different port
  myPort = new Serial(this, portName, 9600);
}      

public void draw() {
  background(0, 0, 0);
  
  fft.analyze();

   spectrum[0] += (fft.spectrum[0] - spectrum[0]) * smoothing;
   spectrum[1] += (fft.spectrum[1] - spectrum[1]) * smoothing;
   spectrum[2] += (fft.spectrum[2] - spectrum[2]) * smoothing;
   
   r = spectrum[0]*height*4;
   g = spectrum[1]*height*4;
   b = spectrum[2]*height*4;
   
   stroke(255,0,0); 
   line( width/3 - 50, height, width/3 - 50, height - r );
   stroke(0,255,0);
   line( 2*width/3 - 50, height, 2*width/3 - 50, height - g);
   stroke(0,0,255);
   line( width - 50, height, width - 50, height - b );
   
    myPort.write((int)r % 255);
    myPort.write((int)g % 255);
    myPort.write((int)b % 255);
}

Schematics

Circuit
Music led bb muqupvalj9

Comments

Similar projects you might like

A Microwave Interface for the IKEA Duktig Kids Kitchen

Project showcase by Myles Eftos

  • 1,253 views
  • 8 comments
  • 7 respects

Servo Signals and Characterization

by 3 developers

  • 1,030 views
  • 4 comments
  • 13 respects

Cellular IoT with Blynk & Hologram

by Moheeb Zara

  • 4,987 views
  • 9 comments
  • 18 respects

Monitoring Temperature Remotely with Blynk for Dummies

Project in progress by Cmtelesann

  • 1,214 views
  • 2 comments
  • 4 respects

How to Make a Customizable Punchable Keyboard Button

Project tutorial by Amal Mathew

  • 1,520 views
  • 4 comments
  • 3 respects

Add Remote Control to Your Lamp

Project tutorial by littlelab

  • 724 views
  • 2 comments
  • 4 respects
Add projectSign up / Login