Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Peguino Buzzer Brick
#1
Peguino Buzzer Brick

This unit houses and delivers a piezo speaker to deliver acoustic signals eg. door bell alarm or a ringtone.

[Image: Brick_Buzzer_01b.png]


Examples for Peguino Uno Nano and ESP32 V1:

Connect the Buzzer Brick to the Peguino Uno Brick Port C2. Copy and paste the code below into the Arduino IDE and upload it to the Peguino Uno Brick board: Peguino Uno Nano or Peguino Uno ESP32 V1.


1. Code example for the Peguino Uno Nano version:
Code:
/*
  Buzzer Brick
  (C) 2018 by Peguino LTD
  Connect the Buzzer Brick to port C2
  Version 1
 
  Note: Use the Serial Plotter to see the values

  Peguino Uno Nano Board Pinout
             ┌─╥─┐
     D_13  1 │     │ 30  D_12
    3.3 V  2 │     │ 29  D_11
     AREF  3 │     │ 28  D_10
 D_14 A_0  4 │     │ 27  D_9
 D_15 A_1  5 │     │ 26  D_8
 D_16 A_2  6 │     │ 25  D_7
 D_17 A_3  7 │     │ 24  D_6
 D_18 A_4  8 │     │ 23  D_5
 D_19 A_5  9 │     │ 22  D_4
      A_6 10 │     │ 21  D_3
      A_7 11 │     │ 20  D_2
       5V 12 │     │ 19  GND
    Reset 13 │     │ 18  Reset
      GND 14 │     │ 17  D_0 RX
 Power In 15 │     │ 16  D_1 TX
             └───┘
  Visit https://www.peguino.com         
*/

int freq = 150;
int auf = 0;
int ab = 0;

void setup() {
#define PIN 23;
int speakerPin = 2;        // Digital 2 or Port
pinMode(speakerPin, OUTPUT);
}

void loop ()

{int speakerPin = 2;
  // Whoop up
  for(int hz = 440; hz < 1000; hz=hz+12){
    tone(speakerPin, hz, 50);
    delay(5);
  }
  noTone(speakerPin);

  // Whoop down
  for(int hz = 1000; hz > 440; hz=hz-9){
    tone(speakerPin, hz, 50);
    delay(5);
  }
  noTone(speakerPin);
}




2. Code example for the Peguino Uno ESP 32 version:
Code:
/*
  Buzzer Brick
  (C) 2019 by Peguino LTD
  Connect the Buzzer Brick to port C2
  Version 1
 
  Note: The ESP32 generates sound by PWM (Pulse Width Modulation) which has to be assigned to the associated pin

  Peguino Uno ESP 32 Development Board Pinout
            ┌─╥─┐
  3.3     1 │     │ 30  5V
  GND     2 │     │ 29  GND
  GPIO15  3 │     │ 28  GPIO13
  GPIO2   4 │     │ 27  GPIO12
  GPIO4   5 │     │ 26  GPIO14
  GPIO16  6 │     │ 25  GPIO27
  GPIO17  7 │     │ 24  GPIO26
  GPIO5   8 │     │ 23  GPIO25
  GPIO18  9 │     │ 22  GPIO33
  GPIO19 10 │     │ 21  GPIO32
  GPIO21 11 │     │ 20  GPIO35
  GPIO3  12 │     │ 19  GPIO34
  GPIO1  13 │     │ 18  GPIO39
  GPIO22 14 │     │ 17  GPIO36
  GPIO23 15 │     │ 16  Chip enable
            └───┘
  Visit https://www.peguino.com          
*/

int freq = 440;     // its the initial frequency in Hz
int channel = 0;    // ESP32 speciality
int resolution = 8; // ESP32 speciality - it means 8 Bits resolution to count from 0 - 255
int whizzer = 0;    // the counter of whizz sound cycles
int whizz = 0;      // the sound frequency we use
void setup() {
 
 // Serial.begin(115200);
  ledcSetup(channel, freq, resolution);   //ESP32 speciality - PWM function to control a buzzer
  ledcAttachPin(23, channel);             //ESP32 speciality - attach it at Pin23
 
}
 
void loop() {
while (whizz <= 3){
      whizz +=1;
      for(int freq = 440; freq <= 2000; freq = freq + 30){
          ledcWriteTone(channel, freq);
         delay(5);
      }
      whizzer +=1;
   }
if (whizzer = 4){
  ledcWriteTone(channel, -1);         //ESP32 speciality - turn off sound
  }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)