[SOLVED] How to connect a buzzer to a PIC MCU?

Status
Not open for further replies.

KhaledOsmani

Full Member level 6
Joined
May 4, 2014
Messages
384
Helped
1
Reputation
2
Reaction score
1
Trophy points
18
Activity points
3,933
How to connect a DC buzzer to a microcontroller (circuit diagram please).

From another part, is its tone is controller, by a delay function; i.e If i want to make it buzz for 10 seconds, so I connect it according to the correct diagram, BSF PORTX,PINX, call delay, then BCF PORTX,PINX or there is another logic to do that?
 

Hi,

No, there is nothing wrong with your code logic.

How to connect the buzzer really depends on what voltage and current it needs.

If its only 5v like the pic and uses less than 25ma then you could drive it direct, preferable via a resistor.

However thats unlikely so you need to use a transistor to act as the voltage /currrent handler.
See this link for practical examples.
http://www.winpicprog.co.uk/pic_tutorial_extras.htm
 
Dear KhaledOsmani,

See code looks like.
Code:
#include <htc.h>
#define _XTAL_FREQ 8000000
#define  PORT_ON(port,pin) port |= (1<<pin)
#define  PORT_OFF(port,pin)  port &=  ~(1<<pin)

void main()
{
  TRISB&=~(1<<PB0);
   while(1)
  { 
    PORT_ON(PORTB,0);
    _delay_ms(10000);       // FOR 10 SEC BUZZER ON
    PORT_OFF(PORTB,0);
   _delay_ms(10000);       // FOR 10 SEC BUZZER OFF
  }
}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…