Best way to read in an analog trigger signal

I'm building a system that uses an arduino to operate 3 relays on a relay shield. Two are used for momentary dry contact closures to start and reset a countdown clock, and the other is used to turn a button light off for the duration of an external audio track played by a separate mp3 player. The trigger for the arduino is an analog (I'm assuming) output signal of 5V (100mA) generated by the mp3 player that lasts for the duration of the audio track.

The only thing I want to use this output signal for is to tell arduino when to trigger the relays. So I only care if the signal is high or low. I had been fussing with reading it into pin A0 using any values above 3V as high and 0 as low. But now I'm wondering if I can just read it into a digital pin to simply do a digitalRead to determine high or low. Thoughts? I'm especially interested in little fussy coding snipets I need to include to make sure I'm not accidentally causing explosions and mass hysteria all over my psyche.

I would test it directly, but my whole project has been installed and I can only test the code on site and infrequently. As such, I was hoping for a quick answer so I can save a bit of troubleshooting when I get there.

Thanks much for any insights.

Normally we don't discuss these kind of issues without more information. Not that we don't believe you but so far we have nothing. No Make or model for the mp3 player. No voltage measurements (you didn't say that you measured it, you simply said it it is such and such),
Let's break it down:
1

I'm building a system that uses an arduino to operate 3 relays on a relay shield.

(simple enough)
2

Two are used for momentary dry contact closures to start and reset a countdown clock

3

the other is used to turn a button light off for the duration of an external audio track played by a separate mp3 player

.
4

The trigger for the arduino is an analog (I'm assuming) output signal of 5V (100mA) generated by the mp3 player that lasts for the duration of the audio track.

5

The only thing I want to use this output signal for is to tell arduino when to trigger the relays.

6

So I only care if the signal is high or low.

7

I had been fussing with reading it into pin A0 using any values above 3V as high and 0 as low. But now I'm wondering if I can just read it into a digital pin to simply do a digitalRead to determine high or low.

8

I'm especially interested in little fussy coding snipets I need to include to make sure I'm not accidentally causing explosions and mass hysteria all over my psyche.

First things first.
We don't assume here (you know why)
We need to know exactly what kind of signal is coming from the mp3 player.
You have two options:
Option-1: Find the user manual and post the instructions describing the signal
Option-2: Put a meter on the end of the cable that is plugged into the mp3 player and measure the voltage and post that.

Second,
We're not going to write the code for you or give you snippets. You are perfectly capable of googling such things as
"arduino Analog read"
or "arduino digital read"
or "arduino digital write"

The ball's in your court. Do your homework. Get the info we need. Research the above syntax and then make an attempt to write the code and we'll go from there .

From the datasheet the atmega328 will only reliably register a low on the a digital pin when the voltage is below 0.3v in a 5v system. It has to be above 0.6V to register as high.
If your signal is reliably staying above 0.6V while fed from the MP3 player and is reliably dropping below 0.3v when the signal ends then you could convert to digital input.

Unfortunately a multi meter with a slow update rate may not be able to detect if those voltages are stable or not. If they're not stable then you could get excessive triggering on a digital pin. You would need some kind of latching circuit to workaround a unstable signal and seeing that your project is already installed that is probably out of the question.

You're probably better off staying with the Analog and using a software latch.

Because you're being proactive in trying to set up something prior to your site visit you really should set up something that logs the analog values to serial so you can get an understanding of what the signal looks like. If it's clean high/low then you can use pin interrupts to trigger your arduino to fire the relays. If the signal is messy then you can analyse the serial data to select an analog threshold value that you can include in your sketch.

The trigger for the arduino is an analog (I'm assuming) output signal of 5V (100mA) generated by the mp3 player that lasts for the duration of the audio track.

I don't see any information about the low state voltage , or even if the signal is TTL (or analog). Without knowing that , how can we answer the OP's question ?

raschemmel:

The trigger for the arduino is an analog (I’m assuming) output signal of 5V (100mA) generated by the mp3 player that lasts for the duration of the audio track.

I don’t see any information about the low state voltage , or even if the signal is TTL (or analog). Without knowing that , how can we answer the OP’s question ?

If you bothered to read the original post you would see that the OP asked for ideas.

Thoughts?

If you bothered to read the original post you would see that the OP has indicated that the status of the signal is in doubt.

Logically then the OP is looking for Ideas about how to confirm that his signal is suitable for digital triggering or if he will need to use analog triggering.

Clearly knowledge of the “low state voltage , or even if the signal is TTL (or analog)” is not required in order to respond to the OP.

If you only want to answer questions you should go to stack overflow where the strict question and answer format has rendered that site into one of the most useless sites on the internet.

would test it directly, but my whole project has been installed and I can only test the code on site and infrequently. As such, I was hoping for a quick answer so I can save a bit of troubleshooting when I get there.

@m12lrpv,
I didn’t see you answer the OP’s question.
If he does the homework I gave him he will be prepared for an analog or a digital solution.(Neither of which you offered, I might add)
You told him what voltage levels he might be dealing with, but you didn’t “bother” to tell him how to apply that information, like for example that the analog readings are 0 to 1023 which makes each count about 4.8mV so 0.6V =125 (+/-5) counts so if he is looking for a low he would do something like this :

                     int val= 0;
                     val = analogRead(analogPin);    // read the input pin
                            if (val<100)
                               {              
                                   STATE=0;
                                 }
                              else
                                {
                                   STATE=1;
                                 }

OR if it is digital;

            int val= 0;
                   val = digitalRead(inPin);
                    if (val==LOW)
                               {              
                                   STATE=0;
                                 }
                              else
                                {
                                   STATE=1;
                                 }

raschemmel:

would test it directly, but my whole project has been installed and I can only test the code on site and infrequently. As such, I was hoping for a quick answer so I can save a bit of troubleshooting when I get there.

@m12lrpv,
I didn't see you answer the OP's question.

Presumably a continued inability to read on your part.

The trigger for the arduino is an analog (I'm assuming) output signal of 5V (100mA) generated by the mp3 player that lasts for the duration of the audio track.

What MP3 player are you using and do you have links to data sheets for it. If your MP3 player is offering a GPI output as it seems from your description then reading on a digital pin should work. Remember you may also need to connect grounds.

If the output is an audio signal then you may be dealing with negative voltages that Arduino pins don't like so be careful.

If the signal is truly analogue (and is positive only) then maybe a RC Circuit will smooth out the fluctuations so you get a more stable analogue reading.

The trigger for the arduino is an analog (I'm assuming) output signal of 5V (100mA) generated by the mp3 player that lasts for the duration of the audio track.

Let's try to help the OP solve his problem with a minimum of fuss.

It's not clear from this quote whether the MP3 player has a special signal output to indicate when a track is playing or whether the OP is hoping to detect the existence of music as a means to trigger his relays.

If there is a special output signal (which is something I haven't heard of) it is likely to be a simple 0v or 5v digital signal so it should be easy to detect on an Arduino digital pin.

If the OP is trying to detect the music signal I think he will need to rectify it with a diode and then use the analogRead() to find out what sort of stuff is detectable. It will be difficult to get useful measurements with a voltmeter. HOWEVER ... I have no idea what voltage the audio signal might have. If there are peak voltages in excess of 5v they are likely to damage the Arduino so it may be a good idea to use a 5v Zener diode to protect it, until the OP knows what he is dealing with. I have no idea whether the Zener diode can also be the rectifier.

If the OP can get values from analogRead() when the music is playing it would probably be sufficient to assume there is no music if there are no values for (say) 5 seconds.

...R

m12lrpv:
From the datasheet the atmega328 will only reliably register a low on the a digital pin when the voltage is below 0.3v in a 5v system. It has to be above 0.6V to register as high.

Wrong on both counts.
Read it again.

m12lrpv:
Presumably a continued inability to read on your part.

Pot..kettle...kettle..pot.

Please keep it civil.

The only thing I want to use this output signal for is to tell arduino when to trigger the relays.

Based on the above he just wants to use it as a trigger (or Pre-trigger)

Your analog signal is going to transition between high and low, something in the ballpark of 1000 times a second. And it is going to be negative about half the time, which won't do the analog-digital input much good.

You need a circuit which detects the peak level of the analog signal on some basis.

Even then, if there are beats in the music, that signal will often be zero.

@michinyon,
Actually, the signal the OP wants to use is of UNKNOWN nature and moreover, it is not at home because it is on a job site. The audio signal which fits the signal parameters you mentioned is not going to the arduino, but the mp3 player supposedly has a separate (it seems) connector that outputs a signal while the music is playing and changes state when the music stops. We have not been given a name or any info on this signal or even any info on the mp3 player so we're basically just trying to cover all the bases. This is all we have:

The trigger for the arduino is an analog (I'm assuming) output signal of 5V (100mA) generated by the mp3 player that lasts for the duration of the audio track.

Riva suggested it is GPI (no idea what that is) There is no suggestion at this point that it is negative or has negative transistions, but the positive signal type is also unknown except for the level is 0 to 5V , which sounds like TTL digital (an not analog) to me.

AWOL:

m12lrpv:
From the datasheet the atmega328 will only reliably register a low on the a digital pin when the voltage is below 0.3v in a 5v system. It has to be above 0.6V to register as high.

Wrong on both counts.
Read it again.

Table

ok 0.3 x Vcc so a little bit higher. Op still should do what I advised and log the serial to see what the signal looks like then proceed from there.

From the datasheet the atmega328 will only reliably register a low on the a digital pin when the voltage is below 0.3v in a 5v system. It has to be above 0.6V to register as high.
.

Wrong on both counts.
Read it again

ok 0.3 x Vcc so a little bit higher. Op still should do what I advised and log the serial to see what the signal looks like then proceed from there.

Input High Voltage Min:(0.7Vcc) - Max:(Vcc+0.5)

I had been fussing with reading it into pin A0 using any values above 3V as high and 0 as low

.
Read the previous post for criteria to test your analog against

But now I'm wondering if I can just read it into a digital pin to simply do a digitalRead to determine high or low.

You could do that. Since we don't know what the signal looks like you have a 50/50 chance of success with that approach

Thoughts?

try both

I'm especially interested in little fussy coding snipets I need to include to make sure I'm not accidentally causing explosions and mass hysteria all over my psyche.

?

raschemmel:
Input High Voltage Min:(0.7Vcc) - Max:(Vcc+0.5)

That’s for data pins when VCC <= 2.4V or for XTAL pin at >= 2.4V
I think for the UNO @5V pin low is 1.5V and pin high is 3V any voltage between these is grey area.

I'm looking at Chapter 29.2 DC CHARACTERISTICS
It looks like Input Low is about 0.9Volts
Input High is above 2.4V