Piezo Tunes

3,875

50

5

About: Circuito.io is an automatic web tool that will help you build almost any innovation you have ever dreamed of, by breaking technical barriers and giving you the best package to kickstart your project. Our In...

In this Instructable,you're going to learn how you can play your own melody with a Piezo speaker, using code generated by Circuito.io

Step 1: Plan It!

First, fill in a query with Piezo speaker as an output on Circuito.io.

Once you do this, you’ll receive code & scheme for you project within minutes!

Step 2: Connect It!

Follow the scheme in the Email from Circuito.io, and connect your breadboard.

Step 3: Code It!

1. Open the firmware file you received from Circuito.io.

2. In order to play your tune, you need to change 3 parameters:

a - Length: add the number of notes in the melody.

b - Melody array: add a list of notes you want to play by their order in the melody.

The number of notes in the array must match the Length int.

c - Note Duration Array: add a list of note durations:

4 = quarter note,

8 = eighth note, etc.

The number of note durations in the array must match the number of notes in the Melody Array and the Length int.

* We've highlighted the relevant parameters that you need to edit in the GIFS and images attached.

Step 4: Play It!

1. To play the melody use the piezoSpeaker.playMelody function in the loop code section using the parameters and arrays above.

Make sure to update the names of the parameters if you changed them in the setup, for example, if you named your tune "Mario", you'll need to change the names of the parameters to MarioLength, MarioMelody and MarioNoteDuration.

Also make sure that the parameters are in the same order as they appeared above.

2. Upload the modified code to your Arduino.

** The code was created based on the Arduino Tone function.

Step 5: Share Your Projects With Us!

We would really love to see (and hear) your projects!

You can share them with us on Instructables,

or on our Facebook page>> facebook.com/circuito.io

If you have any questions, we're at >> hello@circuito.io

Share

    Recommendations

    • Big and Small Contest

      Big and Small Contest
    • PCB Contest

      PCB Contest
    • Toys Contest

      Toys Contest

    5 Discussions

    0
    None
    Sunbutt_Shimmer

    1 year ago

    This is great! I'm doing an Arduino mood lamp, and I'm also going to use the piezo speaker with it. This will help, glad I found this!

    1 reply
    0
    None
    Circuito ioSunbutt_Shimmer

    Reply 1 year ago

    Glad we could help. You can make lots of different hardware combinations with circuito.io. I'm sure you'll find it useful

    0
    None
    miguelbarroso

    2 years ago

    I followed the link you provided for the Arduino Tone function, and the schematics they have there are much simpler than the one you suggest

    2 replies
    0
    None
    eyakmiguelbarroso

    Reply 2 years ago

    Hi!
    That's true, but Circuito shows an amplified speaker (that's what the transistor does) which will create louder sounds than the example Arduino uses.
    Here a link to Arduino's reference you mentioned:
    https://www.arduino.cc/en/Tutorial/PlayMelody

    0
    None
    miguelbarrosoeyak

    Reply 2 years ago

    Thank you... noob here, so I was simply confused why the two circuits were different ;)