Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top