Playing music helps me concentrate, so this was a great opportunity for a quick Christmas project with my Red Pitaya, syncing my little Christmas tree lights using a sound sensor. Since I’m using a relay to switch the lights, this would work equally well on a full size tree, or even outside decorations.
The Hardware part is really simple. I have my Sensor Extension Module mounted on my Red Pitaya. I’m using the Grove Sound Module plugged into an analog port to detect the sound, and the Grove Relay Module in a digital port to switch the lights.
I have two little Christmas trees with LED lights, so I wired both the grounds to a battery pack. One tree has Red LED’s, and one tree has Blue. Since those LED’s have different voltage drops, when they were connected in parallel only the red would light up, since the red had a lower voltage drop. I solved this by wiring 50 Ohm current limiting resistors into both strings of LED’s, and then using a single relay to operate both. It would be even easier using two separate relays.
Here is the code, it is very simple:
It’s basically a loop, that checks the volume level, then turns the relay on or off depending on the result returned. It also puts in a small delay after turning on the relay, to try to stop rapid flickering.
Playing around with the volume level and the delays can make a big difference, but here is a couple of samples showing it working:
With multiple relays you have a lot of fun triggering them at different volume levels, and since this relay is rated up to 250V/7A, you could easily use the above to drive a full sized Christmas Tree or even an outdoor light display.