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.

Designing a buzzer circuit with PIC

Status
Not open for further replies.

grkmr

New Member
I am trying to build a buzzer circuit with PIC. There will be an ADC as an input to PIC that will provide a voltage interval between (let's say) 0-5V.There will be a treshold voltage e.g. 3V. I want to sound the buzzer when input is more than 3V. Any suggestions for code and circuit?
 
That's a pretty basic program, with example code on the net you should easily be able to work that out yourself. You obviously need to initialize the ADC so look at all the example code for your pic that does that and then monitor that for your threshold voltage. Also depending on your PIC you may have an analog comparator which is much easier to use than an ADC and will allow you to trigger at a specific voltage without a lot of code overhead. The buzzer generating itself is pretty easy as well and is most easily done using a timer setup to generate a PWM signal. Given that information you should be able to find plenty of example code and between than and the datasheet for your specific PIC will get you started. If you have trouble with your code once you start then post what you've tried to do and people can help troubleshoot.
 
Take a PIC and put a 10k pot on an input line. Turn the pot and find out when the input detects a HIGH.
Now put a voltage divider on the input and take the centre to the input of the PIC.
Now put a resistor from the midddle of the voltage divider to your 3v line and adjust the resistance values until the PIC detects 3v.
 
The pic I'm using has AN1, AN2 ports and datasheet says those are analog comparator pins. I think I don't need an external ADC do I?
 
I am trying to build a buzzer circuit with PIC. There will be an ADC as an input to PIC that will provide a voltage interval between (let's say) 0-5V.There will be a treshold voltage e.g. 3V. I want to sound the buzzer when input is more than 3V. Any suggestions for code and circuit?

What exactly are you trying to do and what exactly is the PIC you plan to use?

Ron
 
I use 16F628A and I want to compare two voltages and sound the buzzer if referance voltage is higher than the other. However, when I change the voltage values on corresponding pins, nothing changes at the buzzer pin (it always sounds or nothing happens). As I investigate some example codes on the internet I saw that I should use some commands like ADRESH or ADRESL to compare the converted values by the internal ADC of the PIC I'm using. However I dunno how to modify my code. I think there's a problem with "IF PORTA.3 > PORTA.0 THEN..." part of my code. I think I can not compare the pins directly but I should compare the converted binary values. I dunno how to do it exactly. Another problem might be activating the corresponding pins AN0 and AN1. Could you please help me? Here is my code:



************************************************** **************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 18.05.2011 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************
@ DEVICE pic16F628a
@ DEVICE pic16F628a, WDT_on
@ DEVICE pic16F628a, PWRT_ON
@ DEVICE pic16F628a, PROTECT_OFF
@ DEVICE pic16F628a, MCLR_OFF
@ DEVICE pic16F628a, INTRC_OSC_NOCLKOUT
CMCON=7 ; Turn OFF the comparators, and use these pins as normal
; digital I/O-pins
VRCON.7=0 ; Disable voltage reference module
TRISA = %01111111
CMCON = %00000010
T1CON = %00000001 ; Enable Timer1 with a prescaler of 1:1(1microsec.)
PIE1.0=1 ; Enable Timer1 as peripheral interrupt source
PIR1.0=0 ; Clear Timer1 interrupt flag
INTCON =0 ; All interrupt are disable
BUZZER VAR PORTA.7
MAIN:
while 1=1
IF PORTA.3 > PORTA.0 THEN
HIGH BUZZER
else
low buzzer
endIF
wend
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top