segunda-feira, 14 de dezembro de 2015

Dancing lights with Arduino - The idea

I have been having fun with Arduino these days! In this article I am going to show how did I use an electret mic with Arduino to create a Dancing Lights circuit.

Dancing Lights 


 I used to be an eletronician before starting the IT college. I had my own electronics maintenance office to fix television, radios, etc. In my free time I used to create electronic projects to sell and I made a few "reais" selling a version of Dancing lights, but it was too limited: it simply animated lamps using a relay in the output of a 4017 CMOS IC. The circuit was a decimal counter  controlled by a 555.
4017 decimal counter. Source in the image

When I met Arduino a few years ago, I was skeptical because I said: I can do this with IC, why should I use a microcontroller. I thought that Arduino was for kids. But now my pride is gone and I am having a lot of fun with Arduino :-)
The implementation of Dancing Lights with Arduino uses an electret mic to capture the sound and light leds according to the sound peeks(amplitude). The program also has the automatic way, that simply animate the lights without following the sound peeks.

Electret mic and preamp

I first tried a circuit with LM 741, but it was not working correctly (probably I did something wrong) and it used too many components, so I stick with a transistor preamp.
I connect the output of this circuit to an Arduino analog pin and read the input. Remember the analog input converts the signal into integer values between 0 and 1023. So we have to read this integer and using an IF to turn on the LED PINs according to the value:


Analog ValuePIN set to HIGH
0000 - 0150LED1
0150 - 0300LED1, LED2
0300 - 0450LED1, LED2, LED3....
An so on...

I am using 7 leds only, I need extra pins to control the automatic dancing lights. Notice also that I am not adjusting the gain of the circuit, but in future I plan to make a version with a potentiometer to allow it.

The single transistor circuit to amplify the input coming from an electret is the following::

Simple circuit to pre-amplify an electret input. Source http://www.instructables.com/id/Pre-amp-to-electret-mic/

Automatic Dancing lights


That might be the case when you don't want to follow the music, in this case, you can set Arduino to use automatic animations. A PIN will control if the circuit should whether follows the music or play automatic animations. If we select to play automatic animations, a String will be read from the serial port in order to load a new animation. Once we change the mode, it counts to ten seconds so you can write the code to configure the animation in the serial input. Think about the possibilities: you can use the same circuit to animate your Christmas tree or to rock a night house :-)


Conclusion

At this moment I haven't finished the circuit, I haven't even started it to be honest :) Once I finish it I will publish this post and make another one with the technical details and show how to expand it to turn on lights instead LEDs. In another post I plan to create a JavaFX application to monitor the LAMPs and allow to change the selected animation.

The circuit is working! See how it looks like:
I also made a video(explanation in Portuguese):



In the next post I will discuss the Arduino code as soon as I clean it :-)

Nenhum comentário:

Postar um comentário