by Michael McRoberts

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Project 12 – Piezo Sounder Melody Player

Rather than using the piezo to make annoying alarm sounds, why not use it to play a melody? You are going to get your Arduino to play the chorus of “Puff the Magic Dragon.” Leave the circuit exactly the same as in Project 11; you are just changing the code.

Enter the Code

Open up your Arduino IDE and type in the code from Listing 4-2.

Listing 4-2. Code for Project 12

// Project 12 - Piezo Sounder Melody Player #define NOTE_C3  131#define NOTE_CS3 139 #define NOTE_D3  147 #define NOTE_DS3 156 #define NOTE_E3  165 #define NOTE_F3  175 #define NOTE_FS3 185 #define NOTE_G3  196 #define NOTE_GS3 208 #define NOTE_A3  220 #define NOTE_AS3 233 #define NOTE_B3  247 #define NOTE_C4  262 #define NOTE_CS4 277 #define ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required