Difference between revisions of "Buzzer with AVR"
Line 76: | Line 76: | ||
=Code= | =Code= | ||
<syntaxhighlight> | <syntaxhighlight> | ||
+ | /*----------------------------------------------------------------------------- | ||
+ | Program to demonstrate Buzzer | ||
+ | ----------------------------------------------------------------------------- | ||
+ | |||
+ | note: Connect Buzzer on PORTB.0 | ||
+ | ------------------------------------------------------------------------------*/ | ||
+ | |||
+ | |||
+ | /* htc.h contains the definition of all ports and SFRs */ | ||
+ | #include <avr\io.h> | ||
+ | #include "stdutils.h" | ||
+ | #include "delay.h" //User defined library which contains the delay routine | ||
+ | |||
+ | /* start the main program */ | ||
+ | void main() | ||
+ | { | ||
+ | /*Configure PORTB.0 port as output */ | ||
+ | |||
+ | DDRB= 0x01; | ||
+ | |||
+ | |||
+ | while(1) | ||
+ | { | ||
+ | |||
+ | /* Turn On buzzer and wait for 3 second */ | ||
+ | |||
+ | PORTB = 0x01; | ||
+ | |||
+ | DELAY_sec(3); | ||
+ | |||
+ | /* Turn Off buzzer and wait for 3 second */ | ||
+ | |||
+ | PORTB = 0x00; | ||
+ | |||
+ | DELAY_sec(3); | ||
+ | |||
+ | |||
+ | } | ||
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=Video Tutorial= | =Video Tutorial= | ||
− | |||
− | |||
− |
Revision as of 14:11, 18 November 2015
Guru (talk) 20:00, 17 November 2015 (IST)
Contents
Hookup
You may look this up with the simple breadboard as shown in section below or you could use the Ultra AVR dev kit if do not wish to jumble with wires and resistors.
Type 1:Breadboard with Explore AVR 40 Pin Breakout Board with Atmega32
Components Used
1 |
|
AVR 40 pin breakout board with Atmega32 |
2 |
|
Breadboard |
3 |
|
Male to Male Jumper Wires |
4 |
|
Transistor - BC547 [ Click here to buy from our store] |
5 |
|
Buzzer [ Click here to buy from our store] |
6 |
|
Resistor |
Wiring diagram
Type 2:Using Explore Ultra AVR Dev Kit
Components Used
The Explore Ultra AVR Kit comes with all the things required, not just for this experiment but for the entire series. And even if you think of migrating to PIC or Arduino, you'll have breakout boards that fit on to this, hence we believe it is a great investment for learning hands on Embedded Systems. The kit is fully open source, you may use the schematics, the design files and all of the source code and build something cool on your own. And when you do that do not forget to share with us what you've done. We would be happy to see you building something cool.
- Explore Ultra AVR Dev Kit: Buy from EE Store
Code
/*----------------------------------------------------------------------------- Program to demonstrate Buzzer ----------------------------------------------------------------------------- note: Connect Buzzer on PORTB.0 ------------------------------------------------------------------------------*/ /* htc.h contains the definition of all ports and SFRs */ #include <avr\io.h> #include "stdutils.h" #include "delay.h" //User defined library which contains the delay routine /* start the main program */ void main() { /*Configure PORTB.0 port as output */ DDRB= 0x01; while(1) { /* Turn On buzzer and wait for 3 second */ PORTB = 0x01; DELAY_sec(3); /* Turn Off buzzer and wait for 3 second */ PORTB = 0x00; DELAY_sec(3); } }