01 - TK37 Passive Buzzer

# Overview The Lonely Binary TinkerBlock TK37 Passive Buzzer is a versatile audio module designed for creating customizable sound effects in microcontroller projects.Imagine creating custom musical alerts for your smart home, designing unique sound effects for a homemade game, or even building a tiny instrument that plays your favorite tunes. This compact module lets you bring your audio ideas to life. Unlike TK36 Active Buzzer that only make one sound, the TK37 lets you control the **pitch and tone**, so you can craft exactly the sound you want. It's safe and easy to use, and even has a small light that glows when it's making noise, so you know it's working. Whether you're a hobbyist or just love to tinker, the TK37 opens up a world of customizable sound for all your creative projects. Get ready to make some noise! ![](https://cdn.shopify.com/s/files/1/0331/9994/7908/files/Pasted_image_20250730164454.png?v=1753857907) # Pinout | Pin | Function | | ------ | ------------- | | GND | Ground | | VCC | VCC | | NC | Not Connected | | Signal | Digital, PWM | # Dimensions ![](images/Pasted%20image%2020250718152201.png) # Components ## Passive Buzzer Unlike Active Buzzer which has built-in circuitry to generate a fixed tone when simply given power, passive buzzers are essentially small speakers or transducers. They need an external signal that changes rapidly to make them vibrate and produce sound. - **Controlling Pitch and Tone:** The magic of a passive buzzer is that you can control the sound it makes. To do this, you need to vary the frequency of the signal you send to it. - **Frequency = Pitch:** A higher frequency PWM signal will make the buzzer vibrate faster, resulting in a higher-pitched sound. A lower frequency will create a lower pitch. - **Duty Cycle = Volume (to some extent):** While the primary control for a passive buzzer is frequency, the "duty cycle" of the PWM signal (the percentage of time the signal is "on" within a cycle) can also influence the perceived volume and character of the sound. A 50% duty cycle (where the signal is on for half the time and off for half the time) typically produces the loudest and clearest tone for a square wave. - **Creating Melodies and Alerts:** By precisely controlling the PWM frequency, you can play different notes, create musical sequences, or generate various types of alerts and sound effects. ## Why Use an NPN Transistor? The NPN transistor (Q1) is used to amplify and switch the current required to drive the active buzzer. Direct connection of the buzzer to a digital pin might overload the microcontroller's limited output current (typically 20-40mA), risking damage or unreliable operation. The NPN transistor acts as a switch: when the SIGNAL pin goes high, it allows a larger current from VCC to flow through the buzzer, controlled by the microcontroller's smaller signal. This setup ensures the buzzer operates efficiently while protecting the microcontroller. ## Purpose of the Diode The diode (D2) serves as a flyback or freewheeling diode, protecting the circuit from voltage spikes. When the buzzer is turned off, the collapsing magnetic field in its internal coil can generate a reverse voltage spike. This spike could damage the NPN transistor or other components. The diode provides a path for this reverse current to dissipate safely, preventing potential damage and ensuring long-term reliability of the TK36 module. # PWM Digital Signal **PWM (Pulse Width Modulation) is a digital signal**, but it's used to achieve **analog-like control**. A digital signal fundamentally has two states: ON (high voltage) or OFF (low voltage). PWM works by rapidly switching a digital signal between these ON and OFF states. It's a square wave. The "trick" is that by varying the _duration_ of the ON time (the "pulse width") within a fixed period, you effectively control the _average_ power delivered to a device.If the signal is ON for a short time and OFF for a long time, the average power is low. If the signal is ON for a long time and OFF for a short time, the average power is high. For a passive buzzer, this rapid switching at different frequencies causes the diaphragm to vibrate, creating audible sound waves. Your ear perceives these rapid digital pulses as a continuous tone, and by changing the frequency of these pulses, you hear different pitches. In essence, PWM allows microcontrollers, which inherently produce digital ON/OFF signals, to effectively control things that typically need a varying "analog" input, like the pitch of a passive buzzer, the brightness of an LED, or the speed of a motor. # Sample Code ``` cpp // Define the digital pin where the passive buzzer is connected. const int buzzerPin = 5; // Define standard musical note frequencies in Hertz (Hz). // These values are approximate and commonly used for basic melodies. #define NOTE_C4 262 // Middle C #define NOTE_D4 294 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_G4 392 #define NOTE_A4 440 // Define a structure to hold both the note frequency and its duration type. struct Note { int frequency; int durationType; // '4' for quarter, '2' for half, etc. }; // Define the melody for "Twinkle, Twinkle, Little Star" using the Note structure. // Each entry now directly combines the note and its duration. Note song[] = { {NOTE_C4, 4}, {NOTE_C4, 4}, {NOTE_G4, 4}, {NOTE_G4, 4}, {NOTE_A4, 4}, {NOTE_A4, 4}, {NOTE_G4, 2}, // "Twinkle, twinkle, little star," {NOTE_F4, 4}, {NOTE_F4, 4}, {NOTE_E4, 4}, {NOTE_E4, 4}, {NOTE_D4, 4}, {NOTE_D4, 4}, {NOTE_C4, 2}, // "How I wonder what you are." {NOTE_G4, 4}, {NOTE_G4, 4}, {NOTE_F4, 4}, {NOTE_F4, 4}, {NOTE_E4, 4}, {NOTE_E4, 4}, {NOTE_D4, 2}, // "Up above the world so high," {NOTE_G4, 4}, {NOTE_G4, 4}, {NOTE_F4, 4}, {NOTE_F4, 4}, {NOTE_E4, 4}, {NOTE_E4, 4}, {NOTE_D4, 2}, // "Like a diamond in the sky." {NOTE_C4, 4}, {NOTE_C4, 4}, {NOTE_G4, 4}, {NOTE_G4, 4}, {NOTE_A4, 4}, {NOTE_A4, 4}, {NOTE_G4, 2}, // "Twinkle, twinkle, little star," (repeat) {NOTE_F4, 4}, {NOTE_F4, 4}, {NOTE_E4, 4}, {NOTE_E4, 4}, {NOTE_D4, 4}, {NOTE_D4, 4}, {NOTE_C4, 2} // "How I wonder what you are." (repeat) }; // Define the base duration of a quarter note in milliseconds. // This value controls the overall tempo of the song. // A smaller value will make the song play faster. const int quarterNoteTempo = 200; // 200 milliseconds per quarter note void setup() { // Initialize the buzzer pin as an output. // This prepares the pin to send electrical signals to the buzzer. pinMode(buzzerPin, OUTPUT); } void loop() { // Iterate through each note in the 'song' array to play the melody. // The loop runs for the total number of notes defined in the song. for (int thisNote = 0; thisNote < sizeof(song) / sizeof(song[0]); thisNote++) { // Calculate the actual duration (in milliseconds) for the current note. // For example: // If 'song[thisNote].durationType' is 4 (quarter note), 'noteLength' will be 'quarterNoteTempo' (200ms). // If 'song[thisNote].durationType' is 2 (half note), 'noteLength' will be 'quarterNoteTempo * 2' (400ms). int noteLength = quarterNoteTempo * (4.0 / song[thisNote].durationType); // Play the current note on the buzzer. // 'tone(pin, frequency, duration)' generates a square wave of the specified 'frequency' // on the 'buzzerPin' for the calculated 'noteLength' duration. tone(buzzerPin, song[thisNote].frequency, noteLength); // Create a short pause after each note to make the notes distinct. // This pause is slightly longer than the note's sound duration to ensure clear separation. int pauseBetweenNotes = noteLength * 1.30; // 30% longer than the note's sound delay(pauseBetweenNotes); // Stop the tone on the buzzer pin. // This is important to ensure that the sound stops before the next note plays, // preventing notes from blending into each other. noTone(buzzerPin); } // After the entire song has played, pause for a longer period (2 seconds) // before the 'loop()' function restarts the song. delay(2000); } ``` # Product Link For product support, manuals, tutorials, and sample code, please visit our product page to access comprehensive resources. [https://lonelybinary.com/products/tk37](https://lonelybinary.com/products/tk37) # Support If you encounter any issues, please go to [https://lonelybinary.com ](https://lonelybinary.com ) and click the Support button located in the bottom right corner. Our team is ready to assist you. [![Technical Support](https://cdn.shopify.com/s/files/1/0331/9994/7908/files/Pasted_image_20250527102623_4e41083f-a1d3-412d-a78f-9cb11ecf69e5.png?v=1754008493)](https://lonelybinary.com) # Thank You Thank you for choosing TinkerBlock to fuel your passion for STEM! Whether you’re a student diving into coding, an educator shaping future innovators, a hobbyist bringing your vision to life, or a business seeking cutting-edge solutions, TinkerBlock empowers you to create, learn, and innovate. **For school orders, wholesale inquiries, or custom business solutions, please contact us to discuss your specific needs.** [office@lonelybinar.com](office@lonelybinary.com) > **Unleash Your Creativity with TinkerBlock – Where Coding Meets the Real World!**