Flashing LEDs based on pitch of sound - How to

Need help with a project? Trying to find a component? Post any general technical questions here.
Post Reply
WibbleRex
Posts: 5
Joined: Thu Aug 21, 2008 9:20 am

Flashing LEDs based on pitch of sound - How to

Post by WibbleRex » Thu Aug 21, 2008 10:33 am

I am new to electronics and have built a “minimum theremin” (http://home.att.net/~theremin1/101/101.html) from Art Harrison’s clear instructions. And I have added a small LM386 amplifier kit, it is all powered from 9v dc and to my surprise it is working satisfactorily.

I would now like to add a set of LED’s that will flash depending on the pitch of the noise eg the higher the pitch the faster the flash, the lower the pitch the slower the flash.
I thought of using a 4017 IC (as its one of the few I know and I have some) to trigger the LEDs so that they would flash up from 1 to 10 faster as the pitch increased, but I am at a loss to figure how to use the signal going to the speaker as a timer pulse for the 4017.

Any help would be very much appreciated, but please be patient with me as I am still finding the electronics terminology confusing.

mattbo
Posts: 5
Joined: Tue Aug 19, 2008 1:18 am

Re: Flashing LEDs based on pitch of sound - How to

Post by mattbo » Thu Aug 21, 2008 9:48 pm

OK m8, I can think of two methods to perhaps do what you want in terms of Pitch affecting your LEDs
(It pretty much comes down to a number of filters, the amount depends on how much you want the speed of LEDs to vary & this is only as far as I can think)

1st - Analogue type Filter
Probably the cheapest option, involves some different resistors/capacitors & op-amps, oh and some maths to work out the values (Try googling for Butterworth, Chebyshev, and Bessel filters, these are pretty good for picking out the frequency/pitch of your signal).
Then take a 555 Timer in one-shot or monostable mode (or maybe another mode, like continuos when your pitch/frequency becomes active) & fire that into your 4017 IC (with different timings on each 555 timer coupled to your filters)

2nd - Digital Filter Processing
Have to get a processor.. Read an A/D converter at given sample rate, and process the frequency (ahhh sorry got to log off.. if you want more info post again, I'll get back to you when I can)

WibbleRex
Posts: 5
Joined: Thu Aug 21, 2008 9:20 am

Re: Flashing LEDs based on pitch of sound - How to

Post by WibbleRex » Thu Aug 21, 2008 10:43 pm

Thanks for replaying so quickly.
I have googled Butterworth, Chebyshev, and Bessel filters, and am having to lookup the words used in to describe them (decibel, attenuatinon, high ban/low band, radian/second !) etc and the maths seems overwhelming.

I will google it again in the morning and post again, I hope that after a good nights sleep I might understand it a bit better.

mattbo
Posts: 5
Joined: Tue Aug 19, 2008 1:18 am

Re: Flashing LEDs based on pitch of sound - How to

Post by mattbo » Fri Aug 22, 2008 11:42 am

Basic Idea
Basic Idea
Filters.jpg (19.17 KiB) Viewed 16964 times
No Problem man,
That's the basic idea above & it's probably not going to be a walk in the park. Seems like some trial & error and tinkering will be involved - as long as you like a challenge ;)

When you've got the filters right you can make a "Band-pass" filter, which takes a particular frequency region (say - 24.2kHz to 24.9kHz), and when this pitch becomes active (and constant) will produce an output on the end of your Op-Amp (you can make +5V if you read up on it, it's not that hard, just involves making the power supply to the Op-Amp 5V, but all the revelant information is out on the web i'm sure).

Then once the +5V output comes out, connect that to the 555 Timer enable type line (might be called something else other than enable).. Again you need a couple of resistors + capacitor to get the timing of your 555 Timer right, but you could make it give you a +5V logic output every 100ms for example.

That should then fire your 4017 IC CLK, which as you probably know starts the count & LEDs flashing ;)

The only thing I missed I think was if you wanted to use just one 4017 IC & have multiple 555 Timers connected to it. Well I think there it would just be a case of wiring all the 555 Timers to the CLK & after you've tested the seperate filters & circuits should (hopefully) control the 4017 IC independantly.. (I say hopefully because there might be an issue surrounding the logic level being wired to all the 555 Timers aswell.. but I think long as you share a common ground among all your components it "should" be OK)

;)

WibbleRex
Posts: 5
Joined: Thu Aug 21, 2008 9:20 am

Re: Flashing LEDs based on pitch of sound - How to

Post by WibbleRex » Fri Aug 22, 2008 1:26 pm

Thanks for the diagram. But I am struggling to get my head round it all, I think my next question will reveal my low level of understanding, but here goes.

I think that the output to the speaker must vary around 1,000 to 30,000 hertz ?
and the clock/pulse to the 4017 so the LED's looked good would need to vary from about 1 to 30 hertz.

So I would need to divide the speaker frequency by 1000 and convert if from an analogue sine wave to a digital square ?

(I am sure I have just embarrassed myself)

mattbo
Posts: 5
Joined: Tue Aug 19, 2008 1:18 am

Re: Flashing LEDs based on pitch of sound - How to

Post by mattbo » Fri Aug 22, 2008 3:37 pm

Hmmm, ye, my idea might of been a bit overkill -- not sure

If you can convert the signal to a square wave (is that what output you get -- a sine wave -- i'm too familiar with that device, if that's the case it must have a signal generator in it)

Infact looking now at that link you gave in the first post -> if you look at the Circuit Description part, it uses two local square wave oscillators
(Sorry, I didn't really look into this device first of all)

Yeah you are right and you could probably expect the output to vary around to 1,000 to 30,000 Hz

And there doesn't appear to be a sine wave at all (my low level of understanding :P).

So ye, but don't divide by 1,000 for your LEDs.. Frequency (Hz) = 1 / t (where t = time), so for example if you want your LEDs to flash up at one second intervals
that would be - t = 1 / f (f = frequency).. So if you want 1 second --> 1 = 1 / f... Sorry yeah I'm trying to sound clever here...
You're right again....

Take an oscilloscope to your speaker output, if it looks square, connect your 4017 IC to it & bob's your uncle (making sure the signal level is at +5V or whatever your 4017 IC accepts)

WibbleRex
Posts: 5
Joined: Thu Aug 21, 2008 9:20 am

Re: Flashing LEDs based on pitch of sound - How to

Post by WibbleRex » Fri Aug 22, 2008 10:19 pm

Thanks for your reply.

I think I have mislead you in my last post. I only believe that the audio speaker is receiving an analog wave (so I assume it is a sine type wave) to make its high pitch noise.
And I assume that the 4017 would need a square wave (is a square wave digital ? my lack of understanding here is really showing me up).
But I feel I might be correct that the frequency of the speaker signal is about 1000hrtz to 30,000hertz when it makes its high pitch sound.
and I think that the 4017 should count up (receive a clock/pulse) at a rate of 1 to 30 hertz.
But I have know idea how to get from one to the other.

I do not have accesses to an ociliscope and I don't have enough understanding/experience to make sense of what it could show me. I am just starting out on this kind of thing and thought that making the LED flash as described would be a simple exercise.

I am grateful for your patience.

mattbo
Posts: 5
Joined: Tue Aug 19, 2008 1:18 am

Re: Flashing LEDs based on pitch of sound - How to

Post by mattbo » Sun Aug 24, 2008 6:59 pm

Square & Sine waves
Square & Sine waves
Square_and_Sine.jpg (16.73 KiB) Viewed 16914 times
On the square wave shown V is the voltage level that the square wave rises and falls at:
If this is the same as what your 4017 expects (not sure, but possibly +5V, most logic systems expect that, except low-power systems which are coming out now & have +3.3V)
Yes a Square wave is exactly what digital logic looks like. And also this is what you would see on an oscilloscope (provided you adjust it correctly)

Looking at the quick picture I drew, you see "t" this is the time interval between clock pulses (digital logic). You want this equal to - t = 1 / f , where f is the frequency you expect to go into the device. To divide a 30,000 Hz signal to a 30 Hz signal, just connect two of your 4017 ICs together via the (divide by) 10 line. Take that and wire it to the next one. Then you can connect your LEDs to the outputs of the second 4017 IC

The standard way for a CLK input to work (and the same on your device) is that when the square wave/digital logic level rises up to say +5V, it trigger a clock pulse inside the device which counts one. Then the logic falls back to 0V and it waits for another rise to +5V, then another count occurs.

I believe a square wave can also make a high pitched noise (although don't quote me on that).

The best thing is to use an oscilloscope on the output of your device to see what you're dealing with and this is possible using the soundcard on your PC. Do a google for "Zelscope" & you will find some software that can do just that with a 14-day free trial period. It's also quite cheap to buy
To get that to work though you might need to chop up an old microphone.. or maybe you could find a lead from maplins or rs components :P
Seriously though that could do damage to your soundcard, so make sure you read the FAQ on the site & also use an old sound card first so you don't blow up your top of the range creative X-fi 7.1 system :P

Not sure if reasonably simple learning are the right words, but learning is never simple i find.. If you do carry on, you are pretty much getting a good idea for what goes on in a circuit (Oh yes, what you would look for on the oscilloscope is the square waveform on the pic, and hopefully pick up on the timing of pulses), if not well, the way electronics is going, you'll be able to start buying relatively advanced kits in tesco's soon i reckon ;)

WibbleRex
Posts: 5
Joined: Thu Aug 21, 2008 9:20 am

Re: Flashing LEDs based on pitch of sound - How to

Post by WibbleRex » Tue Aug 26, 2008 4:23 pm

Thanks for the diagram and explanation it has helped my understanding quit a bit.
I shall do some testing and post the results.

Post Reply