You are previewing Beginning Arduino.

Beginning Arduino

Cover of Beginning Arduino by Michael McRoberts Published by Apress
  1. Title Page
  2. Dedication
  3. Contents at a Glance
  4. Contents
  5. About the Author
  6. About the Technical Reviewer
  7. Acknowledgments
  8. Introduction
  9. CHAPTER 1: Introduction
    1. How to Use This Book
    2. What You Will Need
    3. What Exactly is an Arduino?
    4. Getting Started
    5. Upload Your First Sketch
    6. The Arduino IDE
  10. CHAPTER 2: Light 'Em Up
    1. Project 1 – LED Flasher
    2. Project 2 – S.O.S. Morse Code Signaler
    3. Project 3 – Traffic Lights
    4. Project 4 – Interactive Traffic Lights
    5. Summary
  11. CHAPTER 3: LED Effects
    1. Project 5 – LED Chase Effect
    2. Project 6 – Interactive LED Chase Effect
    3. Project 7 – Pulsating Lamp
    4. Project 8 – RGB Mood Lamp
    5. Project 9 – LED Fire Effect
    6. Project 10 – Serial Controlled Mood Lamp
    7. Summary
  12. CHAPTER 4: Simple Sounders and Sensors
    1. Project 11 – Piezo Sounder Alarm
    2. Project 12 – Piezo Sounder Melody Player
    3. Project 13 – Piezo Knock Sensor
    4. Project 14 – Light Sensor
    5. Summary
  13. CHAPTER 5: Driving a DC Motor
    1. Project 15 – Simple Motor Control
    2. Project 16 – Using an L293D Motor Driver IC
    3. Summary
  14. CHAPTER 6: Binary Counters
    1. Project 17 – Shift Register 8-Bit Binary Counter
    2. Project 18 – Dual 8-Bit Binary Counters
    3. Summary
  15. CHAPTER 7: LED Displays
    1. Project 19 – LED Dot Matrix Display – Basic Animation
    2. Project 20 – LED Dot Matrix Display – Scrolling Sprite
    3. Project 21 – LED Dot Matrix Display – Scrolling Message
    4. Project 22 – LED Dot Matrix Display – Pong Game
    5. Summary
  16. CHAPTER 8: Liquid Crystal Displays
    1. Project 23 – Basic LCD Control
    2. Project 24 – LCD Temperature Display
    3. Summary
  17. CHAPTER 9: Servos
    1. Project 25 – Servo Control
    2. Project 26 – Dual Servo Control
    3. Project 27 – Joystick Servo Control
    4. Summary
  18. CHAPTER 10: Steppers and Robots
    1. Project 28 – Basic Stepper Control
    2. Project 29 – Using a Motor Shield
    3. Project 30 – Line Following Robot
    4. Summary
  19. CHAPTER 11: Pressure Sensors
    1. Project 31 – Digital Pressure Sensor
    2. Project 32 – Digital Barograph
    3. Summary
  20. CHAPTER 12: Touch Screens
    1. Project 33 – Basic Touch Screen
    2. Project 34 – Touch Screen Keypad
    3. Project 35 – Touch Screen Light Controller
    4. Summary
  21. CHAPTER 13: Temperature Sensors
    1. Project 36 – Serial Temperature Sensor
    2. Project 37 – 1-Wire Digital Temperature Sensor
    3. Summary
  22. CHAPTER 14: Ultrasonic Rangefinders
    1. Project 38 – Simple Ultrasonic Rangefinder
    2. Project 39 – Ultrasonic Distance Display
    3. Project 40 – Ultrasonic Alarm
    4. Project 41 – Ultrasonic Theremin
    5. Summary
  23. CHAPTER 15: Reading and Writing to an SD Card
    1. Project 42 – Simple SD Card/Read Write
    2. Project 43 – Temperature SD Datalogger
    3. Summary
  24. CHAPTER 16: Making an RFID Reader
    1. Project 44 – Simple RFID Reader
    2. Project 45 – Access Control System
    3. Summary
  25. CHAPTER 17: Communicating over Ethernet
    1. Project 46 – Ethernet Shield
    2. Project 47 – Internet Weather Display
    3. Project 48 – Email Alert System
    4. Project 49 – Twitterbot
    5. Project 50 – RSS Weather Reader
    6. Summary
  26. Index
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 ...

The best content for your career. Discover unlimited learning on demand for around $1/day.