Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Today I learned that if you are sloppy with your parts bin
- // organization, and mean to grab a piezo speaker and instead grab a
- // piezo buzzer with a built-in oscillator, you get an interesting
- // spectrum from a frequency sweep. The sum-and-difference signals
- // and their harmonics make neat patterns in a spectrogram!
- //
- // This originally was supposed to use a piezo speaker, so the
- // amplifier below is based around that. However, I grabbed the wrong
- // part; I grabbed a buzzer with an internal 2 kHz oscillator, similar
- // to Adafruit's part 1536. (1536 is 5v tolerant, but I meant to grab
- // a 3.3v part, so I'm sourcing from 3.3v in the amplifier.)
- //
- // FWIW, my buzzer uses about 20mA at 3.3v and 25mA at 5v. So you
- // could hook it up straight to an Arduino pin, but it's a bit hot for
- // my taste.
- //
- // Here's the amplifier I used:
- //
- // +3.3v (from Arduino)
- // ^
- // |
- // *------+
- // + | ---
- // [Piezo ] ^ Diode (1N4148 or whatever)
- // [buzzer] /_\
- // | |
- // *------+
- // |
- // |
- // >
- // 220 or so | /
- // pin 11 ----/\/\/\-----|< NPN transistor (2N2222 or whatever)
- // | \
- // \
- // |
- // -----
- // ---
- // -
- // Hook up a buzzer to digital pin 11.
- const int buzzer_pin = 11;
- // You can hook a button between digital pin 5 and ground to replay
- // the sound, or touch a wire briefly between pin 5 and ground, or
- // just hit the Reset button on the Arduino.
- const int button_pin = 5;
- void beep()
- {
- digitalWrite(buzzer_pin, HIGH);
- delay(100);
- digitalWrite(buzzer_pin, LOW);
- delay(100);
- }
- void setup() {
- pinMode(button_pin, INPUT);
- digitalWrite(button_pin, HIGH);
- pinMode(buzzer_pin, OUTPUT);
- }
- void loop()
- {
- beep();
- beep();
- digitalWrite(buzzer_pin, HIGH);
- delay(1000);
- digitalWrite(buzzer_pin, LOW);
- delay(1500);
- for (float freq = 60; freq < 20000; freq *= 1.008) {
- tone(buzzer_pin, (long)freq);
- delay(10);
- }
- noTone(buzzer_pin);
- delay(1500);
- beep();
- beep();
- while (digitalRead(button_pin))
- ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement