Add an output device

This week, I wanted to play around with different speakers and hook them up to the microcontroller baord I had designed. I first sourced two speakers/piezoelectric buzzers: an active and a passive buzzer. The active buzzer is called active because it only needs a DC voltage to produce sound, whereas for a passive buzzer, you need an AC voltage to produce sound. Both buzzers are polarized. Active buzzers can only produce a single tone (tuned to ~2kHz by the manufacturer) whereas passive buzzers need to have a triggered wave, which means that they can produce a range of different tones based on the input frequency of the signal.

This is a useful diagram that demonstrates the differences among the makeup of the two buzzers:

This is a picture of the active buzzer, which was larger in size than the passive buzzer (and came with a white sticker on the top to distinguish the two speakers):

This is a picture of the passive buzzer:

By looking over the ATSAMD11C microcontroller, I found that I could use pin 5 (PA05) to digitalWrite to. For the code for the active buzzer, I began by instantiating the buzzerPin and the buttonPin. The idea was that when you pressed the button, the buzzer would sound, while when the button was unpressed, the buzzer would be silent. This was a simple way to incorporate both an input device (the button) and an output device (the active buzzer).

This is a picture of the code:

This is a picture of the operation after loading onto the microcontroller:

The operation was successful and the sound was surprisingly loud when the button was pressed! (It even woke up my roommate who was sleeping -- an unexpectedly successful alarm system)

For the passive buzzer, I could adjust the tones of the buzzer to play different notes. For example, 440 Hz translated to the note A4, 587 Hz translated to D4, and 784 Hz translated to G4. The code went through a simple scale (A through G), playing each note for 1000 ms, and then went silent for 1000 ms before looping through again. Although this code did not utilize an input device, the output device showed more range than the operation of the active piezoelectric buzzer.

This is a picture of the code:

This is a picture of the operation after loading onto the microcontroller:

The operation was successful, however, the sound was quite artificial (not replicating the full richness, for example, of a C4 played on a piano).

The code used for this project can be found on this wonderful online resource here:

Phone

(203) 507-0590 x12387