157Views8Replies

# How can i make a servo move to the amount of bass produced by a song...? Answered

I am planning for the wire coming from an ipod to go directly to a micro controller (arduino nano) which would control a servo. The only thing is that i am having trouble determining how to write an if then else statement for only the bass part of the song... thank you

Tags:

## Discussions

I don't know much about the arduino, but I assume that it has A/D capability. If so, you could low pass filter the input audio to the point where you have removed all but the bass portion, and then read that value with the A/D.

To couple audio into the A/D, bias the A/D
input at 1/2 the Vcc supply using a voltage divider. The audio is then input to the A/D pin via a capacitor, using a value of about 2uF or larger. All this is necessary to read an audio wave form, which has both positve and negative parts, using an A/D input that only reads from 0V to VCC.

Compute the magnitude of the input waveform by determining how much above or below the 1/2 Vcc value it is. This gives you the absolute value of the input voltage above or below 1/2 Vcc. Average several magnitude readings to get a value that represents the amout of bass.

Command the servo to the desired position based on the average computed. i assume your servo is the type that uses PWM signals at ~50Hz, with pulse widths from 1ms to 2ms.

Why worry ? The waveform can be considered symmetrical, let it clip on the A/D input.

I was thinking that both halves of the waveform must be intact, otherwise only the positive portion would be present, and the negative portion would be clamped to a diode drop below ground by the diodes internal to the A/D input. The waveform at the input pin would like it was half wave rectified.

If the waveform was sampled during the missing portion, the result would look like there was no input at all.

That's when your sampling frequency is too low then. Shannon sampling theorem and all that, you have to sample at at least twice the frequency of your highest component.

Steve

I see your point. The approach I was thinking of was along the lines of a simple envelope detector like that used in an AM radio, only done in software. But, come to think of it, those detectors do just use a single diode , effectively producing a half wave rectified signal, followed by the filtering to recover the amplitude.

+1. Thinking about It, one should clamp the -ve half cycle before the A/D, rather than risk latching up the device.

The traditional approach, to move mirrors for lighting effects, was just to modify a large speaker and use its voice coil as a solenoid.

If you really want to isolate the bass part: That's a low-pass filter. Simply doing a moving-window average of the signal would be the easiest way to implement that in software.

The advice above is good.

However there are so many variables that we don't know about It may not help:

How accurate does the movement need to be

Driven by amplitude or frequency

Where does base start in your frequency spectrum?

Do you have the skills to build a suitable active filter system and interface to the Micro & programme it?

Will the Micro react fast enough for your project

(505 Crystal ball failure.)