If you do use an average you probably want probably something faster than 20-seconds.Īlso with my code you can un-comment the serial.Print() statements to see your readings. And in your application you don't need the average unless you want to use the average instead of the peaks. Maybe you want to update your LEDs once per second or so. In my project the peak is updated every 50ms which MIGHT be too fast with 5 LEDs. Whenever the peaks are above average the built-in LED turns-on, and it's off when the signal is below average. It finds the peaks and calculates a 20-second moving-average. It's simpler that what you're doing but it should work with your microphone board and it MIGHT get you on the right track. I posted a little example project a couple of years ago - World's Simplest Lighting Effect Then when satisfied, you need to look into ways of extracting the volume level from the sound, either using software in the Arduino or some simple external electronics. The first thing you must do is check your code using a potentiometer. All you are doing is taking a snapshot of the waveform at that instant. You certainly can't just take one sample from the microphone input port and use that to determine the volume level. Only the peak levels give any kind of indication of the volume level, and that is non-linear, as already said. It will oscillate wildly all over the place, because that's what a sound waveform looks like. The output from the microphone does not represent the volume of the sound, it represents the waveform of the sound. If (volume>=1 & volume=600 & volume=800 & volume=900)įirst, I would test your code by removing the microphone and connecting a potentiometer to the input of the Arduino, so you can sweep the input between 0V and 5V and observe what happens with the LED. If someone could help and tell my noob ass what I am doing wrong it would be appreciated #define REDLED 13 I don't want to have many colors on at the same time, but rather only 1 color per range. Whenever I make a loud noise and the red LED lights up, they do but the blue LED stays on while I would want it to turn off. Unfortunately it does not seem to work right. Is the analog scale of 0 to 1023 for sound linear? It doesn't seem so to me. Yellow LED from 800 to 900 and then red LED blinking over 900. Then the green LED would light up from 600 to 800. I tried to do a code where I split the analog readout and that would open the blue LED from a range of 0 to 600. My LED all light up and work fine but I can not get to pair the sound level with the colors in a good way.
0 Comments
Leave a Reply. |