Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Speaker

Status
Not open for further replies.

AtomSoft

Well-Known Member
Hello all i want to make a alarm which is pretty simple for me but i would love to be able to drive a small speaker for the alarm sound instead of a buzzer...

Can anyone point me to how to control a speaker. How to get different tones and stuff from a MCU pin...

Can be AVR, PIC, ARM i dont care really. Its all the same to me heh...
 
You simply set the pin high, wait a time, set it low again, wait a time, repeat.

The time you wait determines the frequency.

You can use timers to do it as well, and there's a website that shows how to play phone ring tones on a PIC using timers, written in C.
 
Do not just connect a speaker voice coil from a PIC pin to ground. The DC resistance of the speaker is so low that it will overload the port pin. Put a 100uF or so electrolytic capacitor (6V, properly polarized) in series with the speaker. This breaks the DC path so no DC current is drawn from the PIC port pin.

I would also try to find a 2" speaker with a 30 to 45 Ohm voice coil (they exist), rather than using one with a 4Ohm coil. It will make more sound and load the pin less.
 
I think i get it...Ill give it a try... so a 100uf in series like:

speaker-jpg.50107


Then pwm a tone in and if i want... like...

BEEP----BEEP----BEEP----BEEP----BEEP


I have to pwm a tone in then delay then tone then delay.. etc.. correct?
 

Attachments

  • speaker.jpg
    speaker.jpg
    6.2 KB · Views: 422
Last edited:
ahh yeah heh.. thanks... actually if they figured out that electricity goes from NEG to POS it would have been correct heh...

New Schem...
speaker-jpg.50109


Thanks a bunch guys ... im about to go collect some old parts... like old cordless phones and rip some speakers out to test with heh
 

Attachments

  • speaker.jpg
    speaker.jpg
    6.5 KB · Views: 391
Last edited:
No, electrons go from negative to positive; electricity goes from positive to negative. :p
 
i have those but wouldnt get the loudness i want or if i want to add MP3 capabilities in the future...

I am sure i can build or buy a prebuilt tiny amp if needed. if anything i could always test a mini amp (LM386)

Thanks tho.
 
Last edited:
Is it b00001010?
 
Last edited:
thanks futz but that kind of confused me heh... i never understood asm like:

movlw 256 - (250-4)

what the heck would be in w ?
Heh :D You got a calculator between your ears that will do that one easily.

Lucio Di Jasio has some good audio info in the last chapter of his "Programming 16-bit Microcontrollers in C" and the 32-bit book as well. I know you have a copy of the 16-bit book at least.
 
Last edited:
I have both heh... didnt even notice these books ... i forgot i bought the "Programming 32-bit Microcontrollers in C Exploring the PIC32" when i first wanted to get into PIC32 but went to arm heh...
 
I have a question about the inductive spike from the speaker coil. Given the high dv/dt of the PIC PWM signal, can anyone explain how the inductive spike from the coil is handled without a flywheel diode? Or is it assumed that the built in diode in the PIC handles the spike?
 
A capacitor there DC blocking You don't want a diode across a speaker
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top