Using iPad audio signal?

I’m a novice Arduino user but an experienced electronics hobbyist.

With its volume control maximised, my iPad audio output displays about 2V pk-pk on the ‘scope. (I think the iPhone’s may be a little lower.) What is the recommended method to write a program to output a digital LOW from this analog input please?

My natural impulse would be to do it externally by soldering up a pre-amp and rectifier circuit, but I’m trying to get into a ‘software’ frame of mind!

Terry

Hi,
Can you read this again mate.

What is the recommended method to write a program to output a digital LOW from this analog input please?

What input condition do you want the digital output to go LOW and what to go HIGH?

Tom.... :slight_smile:

Tom,

Not sure I understand your first point?

I want the analog audio input (from the iPad’s output socket) to cause a digital LOW Arduino output, when an input signal of 2V pk-pk or more is maintained for say 10 ms.

My code actually only needs a single low going pulse at D6 to trigger the required process (sending a sequence of servo activations), as discussed in my earlier thread. But 10 ms should greatly reduce the possibility of spurious triggering by noise, yet it’s much shorter than the 200 ms expected iPad audio.

So essentially what you are proposing is to connect the audio output to a series capacitor with diodes to catch it from deviating beyond supply and ground, feed that into an analog input and in the loop, to repeatedly perform analog reads and look for a drop of more than a Volt (200 counts or so) which persists while millis() increments by 10.

Thanks, I’ll try that. I haven’t yet used millis() so this will be an additional learning exercise.

BTW, I think the iPad output would already include a cap.

My natural impulse would be to do it externally by soldering up a pre-amp and rectifier circuit, but I'm trying to get into a 'software' frame of mind!

The Arduino can't read negative voltages. It can actually be damaged by negative voltages and/or the signal can be damaged (distorted).

The "standard solution" it to bias the input at 2.5V. There is a schematic at the bottom of [u]this post[/u].

The associated code doesn't do exactly what you want but it uses a millis() timer to find the waveform peaks (and another millis() timer to find a moving average) so you can modify that code to do what you want.

Thanks, but I’m not trying to read negative voltages.

Simple VOX circuit Shirley?

Terrypin:
Thanks, but I’m not trying to read negative voltages.

You may not be trying, but you are succeeding. Audio is AC.

aarg:
You may not be trying, but you are succeeding. Audio is AC.

Obviously I would use a series diode as a precautionary measure, even for that max negative of a mere -1V. But from the specs of an ATM328, I understand that all input pins are protected by a pair of limiting diodes, to Vcc and Gnd respectively.

I guess you did not see “...experienced electronics hobbyist” in the opening sentence of my post? I do know that “Audio is AC”, thanks.

Really, how am I supposed to guess what you might do? You never posted any schematics or proposed any particular circuit.

The 328 intrinsic diodes offer very poor protection, they are really just a side effect of the manufacturing process. Any significant current through them creates a risk of damage or undefined operation of the part. You need external Schottky diodes to clamp the input if you plan to drive it that way.

To eliminate further confusion, I suggest that you post a diagram of your proposed circuit. Then people with software suggestions would at least know what input they are coding for.

This afternoon I achieved the result I wanted with a simple one-transistor amplifier, as impatience trumped my intention to do it with programming. I’ll post its schematic in the morning. And it avoids the need for using an analog pin, delivering its output via a series diode to digital pin 6.

But I still intend to try Paul’s suggestion, which includes basic input circuit recommendations.

00:06 UK BST.

Yes, it would be simple. Whether or not the iThing already has an output capacitor, you use a series capacitor. The diodes to each rail constrain the input voltage to the logic range.

Now while you could use a pair of resistors to set a bias voltage, you are going to be repeatedly reading the value with the ADC and looking for a specified step, so (given that the output has already been through the full excursions and the capacitor has charged to accommodate this) it really does not matter what the actual values are when you perform the arithmetic subtraction. :sunglasses:

@Paul__B, the diodes will automatically bias the series capacitor as you say. But the resulting DC bias level can drift, after the first time the cap charges through the diode (since the peak to peak amplitude might be less than 5V). I think this makes it complicated to use subtraction in software. Would you then use differentiation (i.e. the calculus kind) to distinguish between a large and small waveform amplitude? I can't think of any other way you could ignore an unknown and slowly changing DC offset. To perform a subtraction, you have to establish some reference value. Normally that is provided by a resistive divider or some fixed voltage source.

The OP did not mention a slowly changing DC offset, but a

Terrypin:
single low going pulse at D6 to trigger the required process

So a dynamic adaptive (moving average) reference level would seem entirely appropriate. :grinning:

Here's the simple h/w solution I mentioned, pending my attempt at the recommended programming approach.

The iPad generates sounds from a motion detecting app. Bursts are about 800 mS in duration, with ~ 2 Vpp max near their start. That's amplified/rectified as shown in my circuit schematic. The first LOW signal detected triggers the Arduino sketch to deliver a sequence of servo arm movements.

Not sure now whether the amplification was needed, as the iPad input may have sufficed.

I already have several other front-end circuits triggering the 328, each connected by a parallel set of reversed series diodes like this latest add-on, acting as ORs.

There are a few components there that you don't need - the 150 ohm resistor, the Zener, the 1N4148 diode. The transistor base resistor value is sized correctly for a 150 ohm load, but there is no reason to have that so low (or, as I'm suggesting, any reason to have it at all since you can use the internal pullup resistor as a load). If the transistor collector goes directly to the Arduino input, something like a 1k or 10k on the base will give it plenty of drive.

You should probably have some resistor to ground in the base circuit, in case there are small leakage current from the audio output that might bias the transistor on when idle.

If this circuit works well, it might actually be easier than the other idea with capacitor and diodes.

"Not sure now whether the amplification was needed, as the iPad input may have sufficed."

Well, theoretically OK from this simulation, but probably too close to the limits to be practical. But I will try it when I get back to the shed, if only out of curiosity.

@aarg: Crossed in the post! I'll now try simulating your suggestions too.

@aarg: Neat, sims fine, thanks!