Categories
Price Range
Manufacturers
Themes
    Home > Products > 012- Module > Passive Piezo Buzzer - Sounder Speaker Alarm Piezoelectric Arduino PIC
    Passive Piezo Buzzer - Sounder Speaker Alarm Piezoelectric Arduino PIC
    enlarge

    Passive Piezo Buzzer - Sounder Speaker Alarm Piezoelectric Arduino PIC

    RM2.50  
    Item details
    SKU: 012-006
    Weight: 100 grams
    Stock: Out of stock

    Brand: Arduino
      Share This   Add To Facebook   Add To MySpace   

    Passive Piezo Buzzer, bagaimana untuk menggunakannya? Untuk menghasilkan bunyi, anda perlu memberi isyarat PWM kepada Pasif Piezo Buzzer ini. Frekuensi PWM yang berbeza akan menghasilkan bunyi yang berbeza.

    Video

    Sambungan Litar

    Kod Arduino

    /* Programmer : Muhammad Ilyasaa Bin Abdul Rahman
     * More info at https://www.nadieleczone.com.my
     */
    
    const int buzzerPin = 6;
    const int songLength = 18;
    
    char notes[] = "cdfda ag cdfdg gf "; // a space represents a rest
    int beats[] = {1,1,1,1,1,1,4,4,2,1,1,1,1,1,1,4,4,2};
    
    int tempo = 150;
    
    void setup() 
    {
      pinMode(buzzerPin, OUTPUT);
    }
    
    void loop() 
    {
      int i, duration;
    
      for (i = 0; i < songLength; i++) 
      {
        duration = beats[i] * tempo;  
    
        if (notes[i] == ' ')         
        {
          delay(duration);          
        }
        else                          
        {
          tone(buzzerPin, frequency(notes[i]), duration);
          delay(duration);            
        }
        delay(tempo/10);              
      }
    }
    
    int frequency(char note) 
    {
      int i;
      const int numNotes = 8;
    
      char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
      int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523};
    
      for (i = 0; i < numNotes; i++)  
      {
        if (names[i] == note)         
        {
          return(frequencies[i]);     
        }
      }
      return(0);  
    }