Step 1: Prepare
Step 2: Something You Need to Know
I put all code on github
You should look at grove speaker wiki first
Here I connected speaker to D3. But Arduino code D3's pin number is 0.
You can type 12 musical notes by changing code.
I hope the code example can help you a lot!