ARDUINO Sensor Buzzer 5V Module User Manual
- June 12, 2024
- ARDUINO
Table of Contents
ARDUINO Sensor Buzzer 5V Module
Arduino Sensor Buzzer 5V User Manual
The Arduino Sensor Buzzer 5V is an electronic device used to play tones and melodies. It takes advantage of the processor’s capability to produce PWM signals to play music. The buzzer is plugged into pin number 9, which supports the functionality of writing a PWM signal to it.
It is important to note that buzzers have polarity. Commercial devices typically have a red and black wire, indicating how to plug it into the board.
Product Connection
Arduino | 5V | GND | Pin 9 |
---|---|---|---|
+ | S |
Example 1: Play Melody
// Play Melody
// ----------
// Program to play a simple melody
//
// Tones are created by quickly pulsing a speaker on and off
// using PWM, to create signature frequencies.
//
// Each note has a frequency, created by varying the period of
// vibration, measured in microseconds. We'll use pulse-width
// modulation (PWM) to create that vibration.
//
// We calculate the pulse-width to be half the period; we pulse
To use the Arduino Sensor Buzzer 5V, follow these steps:
- Connect the Arduino board’s 5V pin to the buzzer’s positive (+) terminal.
- Connect the Arduino board’s GND pin to the buzzer’s ground (GND) terminal.
- Connect the Arduino board’s pin 9 to the buzzer’s signal (S) terminal.
Once the connections are made, you can upload the provided example code to your Arduino board. This code will play a simple melody using pulse-width modulation (PWM) to create different tones.
Play Melody
- This example makes use of a buzzer in order to play melodies. We are taking advantage of the processors capability to produce PWM signals in order to play music.
- A buzzer is nothing but an electronic device that is used to play tones In our example we are plugging the buzzer on the pin number 9, that supports the functionality of writing a PWM signal to it, and not just a plain HIGH or LOW value.
- The first example of the code will just send a square wave to the buzzer, while the second one will make use of the PWM functionality to control the volume through changing the Pulse Width.
- The other thing to remember is that buzzers have polarity, commercial devices are usually having a red and a black wires indicating how to plug it to the board.
Connection
- Arduino 412 ARDUINO SENSOR BUZZER 5V
- 5V +
- GND –
- Pin 9 S
Example 1: Play Melody
- Play Melody
- ———–
- Program to play a simple melody
- Tones are created by quickly pulsing a speaker on and off
- using PWM, to create signature frequencies.
- Each note has a frequency, created by varying the period of
- vibration, measured in microseconds. We’ll use pulse-width
- modulation (PWM) to create that vibration.
- We calculate the pulse-width to be half the period; we pulse * the speaker HIGH for ‘pulse-width’ microseconds, then LOW
- for ‘pulse-width’ microseconds.
- This pulsing creates a vibration of the desired frequency.
- (cleft) 2005 D. Cuartielles for K3
- Refactoring and comments 2006 clay.shirky@nyu.edu
- See NOTES in comments at end for possible improvements
- The program purports to hold a tone for ‘duration’ microseconds.
- Lies lies lies! It holds for at least ‘duration’ microseconds, plus
- any overhead created by incremeting elapsed_time (could be in excess of
- 3K microseconds) plus overhead of looping and two digitalWrites()
- As a result, a tone of ‘duration’ plays much more slowly than a rest
- of ‘duration.’ rest_count creates a loop variable to bring ‘rest’ beats
- in line with ‘tone’ beats of the same length.
- rest_count will be affected by chip architecture and speed, as well as
-
- overhead from any program mods. Past behavior is no guarantee of future
- performance. Your mileage may vary. Light fuse and get away.
- overhead from any program mods. Past behavior is no guarantee of future
- This could use a number of enhancements:
- ADD code to let the programmer specify how many times the melody should
- loop before stopping
- ADD another octave
- MOVE tempo, pause, and rest_count to #define statements
- RE-WRITE to include volume, using analogWrite, as with the second program at
- http://www.arduino.cc/en/Tutorial/PlayMelody
- ADD code to make the tempo settable by pot or other input device
- ADD code to take tempo or volume settable by serial communication
- (Requires 0005 or higher.)
- ADD code to create a tone offset (higer or lower) through pot etc
- REPLACE random melody with opening bars to ‘Smoke on the Water’
- Second version, with volume control set using analogWrite()
Play Melody
Program to play melodies stored in an array, it requires to know * about timing issues and about how to play tones.
- The calculation of the tones is made following the mathematical * operation:
- timeHigh = 1/(2 * toneFrequency) = period / 2
- where the different tones are described as in the table:
- note frequency period PW (timeHigh)
- c 261 Hz 3830 1915
- d 294 Hz 3400 1700
- e 329 Hz 3038 1519
- f 349 Hz 2864 1432
- g 392 Hz 2550 1275
- a 440 Hz 2272 1136
- b 493 Hz 2028 1014
- C 523 Hz 1912 956
- (cleft) 2005 D. Cuartielles for K3 */
Read User Manual Online (PDF format)
Read User Manual Online (PDF format) >>