I have recently purchased an arduino for the Adalight project. Everything was successful and for my first project I was happy with the results. I have an idea for another project but I don't really have too much experience with the Arduino so I am posting here for some advice on where to start/how to begin.
The Idea:
What I would like to accomplish is to have RGB LED's light up depending on the sound level of the music or whatever is playing. I have done a lot of research over the past few days on different approaches and I found many solutions but all of the projects use a single colored LED, and don't display a certain color based on the dB of the audio output. I have found a library called minim but that seems to take an file as input rather than somehow listening for whatever sound is output. Or to start maybe I could just change the brightness of randomly changing colors so during a pitch the brightness would be lowered and during an audio wave peak the LED's would be full brightness.
This question might seem like a lot, I have the CS background so I can learn/follow code examples. I just don't have much experience with actual hardware. Also, I have never actually written code for an Arduino myself, but I have a general understanding of Arduino code by looking through code in other projects.
You could start with a microphone - check e.g. sparkfun.com for a breakout board - connected to the analog input.
The volume of the sound can be used to trigger the intensity of some LED by means of analog out (PWM=Pulse Width Modulation).
a minimal starter
const int ledPin = 9; // the PWM pin of the LED
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop()
{
byte brightness = analogRead(A0)/4; // analogRead goes from 0..1023 so /4 => 0..255
// adjust the LED
analogWrite(ledPin, brightness);
}
A step further:
Search the forum for FFT (Fast Fourier Transform) to determine the frequencies in the sound signal.
Thank you very much robtillart for the start. I have read that RGB LED's are controlled a little bit differently that a single color LED. Would it be that much more difficult to modify the code to work with a RGB LED?
Magician that is a good project, the only thing is that the LED's are single color. I was hoping to find a solution that supported a multi-color LED. Other than that, it seems to do pretty much what I was aiming at doing. Great reference and thank you.
As a second thought would it be easier to use in a base example: 1 red, 1 blue, 1 green LED and make other colors instead of using a RGB LED?
I have read that RGB LED's are controlled a little bit differently that a single color LED
It's not true, as RGB led is just 3 single color leds in one case.
As a second thought would it be easier to use in a base example: 1 red, 1 blue, 1 green LED and make other colors instead of using a RGB LED?
Technically, no difference. You would need diffusing screen to mix up a light, produced by single colored (SCL) leds to make it looks similar.
Installing RGB leds instead of SCL could bring new dimension in the visual show, as would allow to change "temperature" of red or say "coldness" of blue color. The same time complexity goes 3x.
Would it be that much more difficult to modify the code to work with a RGB LED?
No and yes, you could use 3 microphones and 3 SCL's or one RGB LED
problem will be that the mike's get probably the same volume, that's why you have to search for FFT, that analyses the signal and find basic frequencies in it.
Then you can assigne the strength of low frequencies to red , the mid to green and high to blue .