Sound starting the code

Hello everyone,

Recently i started programming LEDs that is synchronised with music. I am beginner in electronics and arduino/coding so i have a issue with my recent idea. I thought that if the main code (loop) would be started by the first sound of the music track (i edited it so it has a clear beat in the beggining) it would mean easily calibrated music with LEDs. Problem is - i don't really know how i should do it. I googled and found several solutions but all of them are way too complex for my and for the function i need (most of the discussions not only takes the input music, but does something with it too and i don't need it).

So my main questions is:

  1. Should i use normal pins or analog pins for input from AUX?
  2. What circuit should i use to limit my signal to 0-5V? (lets say it is played from ipod or phone)
  3. this one is not the biggest issue, but - how should i process my code to only start the loop after receiving signal from AUX input? (to be more clear - i need that signal only to launch the code. after that, aux would be disconnected for leds/arduino mobility.)

thank you in advance for your response!

  1. Probably analog

  2. Use one of those circuits which you consider to be "too complex". A resistor and capacitor is the absolute minimum, usually 2 resistors is better. I would look at a circuit which will act as an analog filter with high sensitivity to the initial beat or click and low sensitivity to random noise.

  3. Don't attempt to stop the loop. loop() should repeat thousands of times per second, scanning all the inputs and making decisions. Once it has made the decision that the music has started, the loop can change what it does, but it still runs very often.

  1. Should i use normal pins or analog pins for input from AUX?

Analog

  1. What circuit should i use to limit my signal to 0-5V? (lets say it is played from ipod or phone)

It's unlikely that you'll get more than 5V but audio is AC so it's negative half the time. Usually you just need to [u]bias the input[/u] (two resistors and a capacitor*) so that it never goes negative. With the bias, the ADC will read about 512 with silence.

With higher-power speaker outputs, you can add a [u]protection circuit[/u], and if necessary a [u]voltage divider[/u] to knock-down the signal.

Neither of those should be necessary with a headphone/line/aux signal, bit it never hurts to have some protection when connecting to the "outside world".

After adding the bias circuit, run the [u]Analog Read Serial Example[/u] code to see what kind of readings you're getting. (If you get readings up to 1023 and down to zero, add a protection circuit. :wink: ).

Those readings should give you an idea of what to expect when the music starts.

how should i process my code to only start the loop after receiving signal from AUX input? (to be more clear - i need that signal only to launch the code. after that, aux would be disconnected for leds/arduino mobility.)

You can use an [u]if-statement[/u] that runs the code if your analog reading is > X. Or, you can make a "do nothing" [u]while-loop[/u] that just sits there looping while there is no signal, and then beaks-out and continues your code once a signal is detected.

  • You can leave out the 47nF capacitor.

P.S.

to be more clear - i need that signal only to launch the code. after that, aux would be disconnected for leds/arduino mobility.)

If this is for some kind of public performance... There are two kinds of errors to watch-out for. You can get a false-trigger or a missed-trigger and these are more likely with an "outside world" connection than for something self-contained.

The false-trigger can probably be avoided with an on-off switch (don't switch it on 'till the performance is about to start). To avoid missed-triggers you'll need to confirm that the trigger has been received, and if not start the music again. Maybe it's obvious when that "first beat" starts the sequence, but if not you may need to flash an LED (or something like that) to confirm that the sequence is starting.

The message with a circuit photo below explains everything in details.

Hi. Although the clocks of all your Arduinos are nominally 16MHz, they will naturally vary from each other and over time and with changes in temperature.

You need some hardware to keep them all in sync. One Arduino could be the master and send out a simple pulse which the other Arduino(s) could receive to keep themselves in sync. If you need something to keep them all synced to a more accurate clock, you could get an rtc module such as ds3231 and set it up to give out a regular (eg. 1s) pulse signal which all the Arduinos receive and use to to keep themselves in sync.

Alternatively, stop using multiple Arduinos. You don't give much detail on what these are doing, but could one Arduino do the work of 2 or 3? If there are not enough outputs on a single Arduino, there are many solutions to that problem.

Wise if you had continued your previous thread.
You already had some answers here.
Leo..

@Filosofas Time waster!

@Wawa if you are scolding someone for breaking forum rules it's best to make sure you are following them yourself, like posing links correctly!

Just warning posters that there is already a thread.
Link inserted.
Leo..

Load the song into a wav editor.
Combine the L and R channels into one channel.
Wipe one of the channels and add a click track like what musicians use to keep time.
Export as mp3 or whatever format your music player understands.
Use the click track to drive the Arduino time keeping.

Thanks Leo! For the warning, as well as the link.

Sorry for this mistake of mine. Going back to the old post. Could you please delete or lock this? I dont see this kind of option for myself.

There is a "report to moderator" line in every post.
I just have asked a moderator to merge the two.
Leo..

@Filosofas, please do not cross-post. Threads merged.

So i build the code using arduino uno, powered by cable to pc and leds ( 2strips with 12leds each) powered by phone charger. It had a perfect execution every time i ran it. What time was input, it was executed every time the same, and as coded. (no hint of delays or something similar). For the start of the code i used this kind of protection circuit:
(the nanos will be explaining my issue, that will come next)

Before issue, i would like to thank for everyone that helped me to gather required information and scatter the doubts about knowledge i already had.

Few days ago i tried to build a hardware: arduino nano, powered by 3.7V 2400mAh battery, and two led strips (12 leds ea), getting signals from different pins, but powered from the same battery. i built two exactly the same setups. And made protective circuit with a branch for two hardware (like the image above).
Problem is - one of them is making delays that has linear increase over time (indication code shows that they start the code totally the same but starts to differ by bit after ~20-30sec and that difference incease over time). And because my protective circuit only gives a signal that starts the code, i cant use music to drive arduino in place (as suggested above), because it is a performance and hardware should be small and mobile. Moreover - their sync together is not the main deal. They need to be sync together, as well as synced with the music. ( performance is 15mins , so arduino clock accuracy should not be causing problems)
By the way, delay happened only the second time i launched it. the first time, i checked only first minute of the code (it is wrote on 4min track), but it played all well synchronized.

Firstly I thought it might be just broken nano. But when i bought another nano and tested it - worked perfectly at the start, but when i soldered everything, launched them both - delay appeared again.

To be noted:

  1. I have leds indicating that code starts simultaneously on both nanos.
  2. Analog signal never goes more than 524 (i guess it shows effectiveness of protective schematics)
  3. I tried launching all arduinos at my disposal: 1 uno, 2nanos. uno with one nano was going all sync'ed up while one nano was messed up.

After lot of thoughts and investigetion overheat from soldering comes to mind, but why the first nano was working perfectly (even after soldering and more than 10 runs), but next day it started to be a problem too? I do not have that many of resources atm to buy lot of arduinos ant test it. So i am asking - does anybody have a suggestion why this might happen? Have anyone had similar situations, examples, researches? I dont want to change the way this all process is build unless it is totally necessary, because i had a working example when i was building the code.